Skip to content

Commit

Permalink
Merge pull request #38 from depromeet/feature/#29
Browse files Browse the repository at this point in the history
Feature/#29 recruit crud api 개발
  • Loading branch information
sejoon00 authored Aug 12, 2024
2 parents 00c433b + 43d4cb9 commit fbaa787
Show file tree
Hide file tree
Showing 33 changed files with 2,708 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ HELP.md
docker-compose.yml
.env



build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
/src/main/generated/

/src/main/resources/static/

### STS ###
.apt_generated
Expand Down
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ tasks.withType(GenerateSwaggerUI) {
}
}

tasks.withType(Test).configureEach {
jvmArgs = jvmArgs + ['--add-opens=java.base/java.util=ALL-UNNAMED']
}

test {
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
}

build {
dependsOn(':openapi3')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.server.bbo_gak.domain.recruit.controller;

import com.server.bbo_gak.domain.recruit.dto.request.RecruitCreateRequest;
import com.server.bbo_gak.domain.recruit.dto.request.RecruitUpdateSeasonRequest;
import com.server.bbo_gak.domain.recruit.dto.request.RecruitUpdateSiteUrlRequest;
import com.server.bbo_gak.domain.recruit.dto.request.RecruitUpdateStatusRequest;
import com.server.bbo_gak.domain.recruit.dto.request.RecruitUpdateTitleRequest;
import com.server.bbo_gak.domain.recruit.dto.response.RecruitGetResponse;
import com.server.bbo_gak.domain.recruit.service.RecruitService;
import com.server.bbo_gak.domain.user.entity.User;
import com.server.bbo_gak.global.annotation.AuthUser;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/recruits")
@RequiredArgsConstructor
public class RecruitController {

private final RecruitService recruitService;

@GetMapping("")
public ResponseEntity<List<RecruitGetResponse>> getTotalRecruitList(
@AuthUser User user
) {
return ResponseEntity.ok(recruitService.getTotalRecruitList(user));
}


@GetMapping("/bySeason")
public ResponseEntity<List<RecruitGetResponse>> getRecruitListBySeason(
@AuthUser User user,
@RequestParam("season") String season
) {
return ResponseEntity.ok(recruitService.getRecruitListBySeason(user, season));
}

@GetMapping("/progressing")
public ResponseEntity<List<RecruitGetResponse>> getProgressingRecruitList(
@AuthUser User user
) {
return ResponseEntity.ok(recruitService.getProgressingRecruitList(user));
}

@PostMapping("")
public ResponseEntity<RecruitGetResponse> createRecruit(
@AuthUser User user,
@RequestBody RecruitCreateRequest request
) {
return ResponseEntity.ok(recruitService.createRecruit(user, request));
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteRecruit(
@AuthUser User user,
@PathVariable("id") Long id
) {
recruitService.deleteRecruit(user, id);
return ResponseEntity.ok().body(null);
}

@PatchMapping("/{id}/title")
public ResponseEntity<RecruitGetResponse> updateRecruitTitle(
@AuthUser User user,
@PathVariable("id") Long id,
@RequestBody RecruitUpdateTitleRequest request) {
RecruitGetResponse response = recruitService.updateRecruitTitle(user, id, request.title());
return ResponseEntity.ok(response);
}

@PatchMapping("/{id}/season")
public ResponseEntity<RecruitGetResponse> updateRecruitSeason(
@AuthUser User user,
@PathVariable("id") Long id,
@RequestBody RecruitUpdateSeasonRequest request) {
RecruitGetResponse response = recruitService.updateRecruitSeason(user, id, request.season());
return ResponseEntity.ok(response);
}

@PatchMapping("/{id}/status")
public ResponseEntity<RecruitGetResponse> updateRecruitStatus(
@AuthUser User user,
@PathVariable("id") Long id,
@RequestBody RecruitUpdateStatusRequest request) {
RecruitGetResponse response = recruitService.updateRecruitStatus(user, id, request.recruitStatus());
return ResponseEntity.ok(response);
}

@PatchMapping("/{id}/siteUrl")
public ResponseEntity<RecruitGetResponse> updateRecruitSiteUrl(
@AuthUser User user,
@PathVariable("id") Long id,
@RequestBody RecruitUpdateSiteUrlRequest request) {
RecruitGetResponse response = recruitService.updateRecruitSiteUrl(user, id, request.siteUrl());
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.server.bbo_gak.domain.recruit.controller;

import com.server.bbo_gak.domain.recruit.dto.response.SeasonGetResponse;
import com.server.bbo_gak.domain.recruit.service.SeasonService;
import com.server.bbo_gak.domain.user.entity.User;
import com.server.bbo_gak.global.annotation.AuthUser;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/seasons")
@RequiredArgsConstructor
public class SeasonController {

private final SeasonService seasonService;


@GetMapping("")
public ResponseEntity<List<SeasonGetResponse>> getRecruitSeasonList(
@AuthUser User user
) {
return ResponseEntity.ok(seasonService.getSeasonListByUser(user));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.server.bbo_gak.domain.recruit.dao;

import com.server.bbo_gak.domain.recruit.entity.Recruit;
import com.server.bbo_gak.domain.recruit.entity.Season;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RecruitRepository extends JpaRepository<Recruit, Long> {

Optional<Recruit> findByUserIdAndId(Long userId, Long id);

List<Recruit> findAllByUserId(Long userId);

List<Recruit> findAllByUserIdAndSeason(Long userId, Season season);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.server.bbo_gak.domain.recruit.dao;

import com.server.bbo_gak.domain.recruit.entity.Season;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SeasonRepository extends JpaRepository<Season, Long> {

List<Season> findAllByUserId(Long userId);

boolean existsByUserIdAndName(Long userId, String name);

Optional<Season> findByUserIdAndName(Long userId, String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.server.bbo_gak.domain.recruit.dto.request;

import com.server.bbo_gak.domain.recruit.entity.Recruit;
import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule;
import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage;
import com.server.bbo_gak.domain.recruit.entity.RecruitStatus;
import com.server.bbo_gak.domain.recruit.entity.Season;
import com.server.bbo_gak.domain.user.entity.User;

public record RecruitCreateRequest(
String season,
String title,
String siteUrl,
RecruitScheduleStage recruitScheduleStage,
String deadline
) {

public Recruit toEntity(User user, Season season, RecruitSchedule schedule) {
return Recruit.builder()
.season(season)
.title(title)
.siteUrl(siteUrl)
.recruitStatus(RecruitStatus.APPLICATION_COMPLETED)
.user(user)
.build()
.addSchedule(schedule);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.server.bbo_gak.domain.recruit.dto.request;

import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule;
import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage;
import java.time.LocalDate;

public record RecruitScheduleCreateRequest(
RecruitScheduleStage recruitScheduleStage,
String deadline
) {

public static RecruitSchedule of(RecruitScheduleStage recruitScheduleStage, String deadline) {
return RecruitSchedule.builder()
.recruitScheduleStage(recruitScheduleStage)
.deadLine(LocalDate.parse(deadline))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.server.bbo_gak.domain.recruit.dto.request;

public record RecruitUpdateSeasonRequest(String season) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.server.bbo_gak.domain.recruit.dto.request;

public record RecruitUpdateSiteUrlRequest(String siteUrl) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.server.bbo_gak.domain.recruit.dto.request;

import com.server.bbo_gak.domain.recruit.entity.RecruitStatus;

public record RecruitUpdateStatusRequest(RecruitStatus recruitStatus) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.server.bbo_gak.domain.recruit.dto.request;

public record RecruitUpdateTitleRequest(String title) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.server.bbo_gak.domain.recruit.dto.response;

import com.server.bbo_gak.domain.recruit.entity.Recruit;
import com.server.bbo_gak.global.utils.BaseDateTimeFormatter;
import lombok.Builder;

@Builder
public record RecruitGetResponse(
Long id,
String title,
String season,
String siteUrl,
String recruitStatus,
String createdDate
) {

public static RecruitGetResponse from(Recruit recruit) {

return RecruitGetResponse.builder()
.id(recruit.getId())
.title(recruit.getTitle())
.season(recruit.getSeason().getName())
.siteUrl(recruit.getSiteUrl())
.recruitStatus(recruit.getRecruitStatus().getValue())
.createdDate(recruit.getCreatedDate().format(BaseDateTimeFormatter.getLocalDateTimeFormatter()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.server.bbo_gak.domain.recruit.dto.response;

import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule;
import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage;
import com.server.bbo_gak.global.utils.BaseDateTimeFormatter;
import lombok.Builder;

@Builder
public record RecruitScheduleGetResponse(
Long id,
RecruitScheduleStage recruitScheduleStage,
String deadLine
) {

public static RecruitScheduleGetResponse from(RecruitSchedule schedule) {
return RecruitScheduleGetResponse.builder()
.id(schedule.getId())
.recruitScheduleStage(schedule.getRecruitScheduleStage())
.deadLine(schedule.getDeadLine().format(BaseDateTimeFormatter.getLocalDateFormatter()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.server.bbo_gak.domain.recruit.dto.response;

import com.server.bbo_gak.domain.recruit.entity.Season;

public record SeasonGetResponse(
String name
) {

public static SeasonGetResponse from(Season season) {
return new SeasonGetResponse(season.getName());
}
}
Loading

0 comments on commit fbaa787

Please sign in to comment.