From e63cf309e5d4eb1dd09ae6243f79c313a009932f Mon Sep 17 00:00:00 2001 From: JeongHoon Lee Date: Fri, 19 Jul 2024 22:37:00 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A7=80=EC=9B=90=20=EA=B3=B5=EA=B3=A0?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=20=EC=88=98=EC=A0=95=20API=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruit/controller/RecruitController.java | 14 ++++++- .../controller/port/RecruitService.java | 5 +++ .../kkijuk/server/recruit/domain/Recruit.java | 13 ++++++ .../recruit/domain/RecruitStatusUpdate.java | 15 +++++++ .../recruit/service/RecruitServiceImpl.java | 9 ++++- .../recruit/service/RecruitServiceTest.java | 40 ++++++++++++++++--- 6 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 src/main/java/umc/kkijuk/server/recruit/domain/RecruitStatusUpdate.java diff --git a/src/main/java/umc/kkijuk/server/recruit/controller/RecruitController.java b/src/main/java/umc/kkijuk/server/recruit/controller/RecruitController.java index 29ee2c1e..9e9702e4 100644 --- a/src/main/java/umc/kkijuk/server/recruit/controller/RecruitController.java +++ b/src/main/java/umc/kkijuk/server/recruit/controller/RecruitController.java @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*; import umc.kkijuk.server.common.LoginUser; import umc.kkijuk.server.recruit.controller.port.RecruitService; +import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate; import umc.kkijuk.server.recruit.domain.RecruitUpdate; import umc.kkijuk.server.recruit.controller.response.RecruitResponse; import umc.kkijuk.server.recruit.domain.Recruit; @@ -30,11 +31,20 @@ public ResponseEntity create(@RequestBody @Valid RecruitCreateD } @PutMapping("/{recruitId}") - public ResponseEntity modify(@RequestBody @Valid RecruitUpdate recruitUpdate, - @PathVariable Long recruitId) { + public ResponseEntity update(@RequestBody @Valid RecruitUpdate recruitUpdate, + @PathVariable long recruitId) { LoginUser loginUser = LoginUser.get(); return ResponseEntity .status(HttpStatus.OK) .body(recruitService.update(recruitId, recruitUpdate).getId()); } + + @PatchMapping("/{recruitId}") + public ResponseEntity updateState(@RequestBody @Valid RecruitStatusUpdate recruitStatusUpdate, + @PathVariable long recruitId) { + LoginUser loginUser = LoginUser.get(); + return ResponseEntity + .ok() + .body(recruitService.updateStatus(recruitId, recruitStatusUpdate).getId()); + } } diff --git a/src/main/java/umc/kkijuk/server/recruit/controller/port/RecruitService.java b/src/main/java/umc/kkijuk/server/recruit/controller/port/RecruitService.java index 6f60c0b9..e15f96e8 100644 --- a/src/main/java/umc/kkijuk/server/recruit/controller/port/RecruitService.java +++ b/src/main/java/umc/kkijuk/server/recruit/controller/port/RecruitService.java @@ -2,12 +2,17 @@ import umc.kkijuk.server.recruit.domain.Recruit; import umc.kkijuk.server.recruit.domain.RecruitCreateDto; +import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate; import umc.kkijuk.server.recruit.domain.RecruitUpdate; +import javax.net.ssl.SSLSession; + public interface RecruitService { Recruit create(RecruitCreateDto recruitCreateDto); Recruit update(Long recruitId, RecruitUpdate recruitUpdate); Recruit getById(long id); + + Recruit updateStatus(long recruitId, RecruitStatusUpdate recruitStatusUpdate); } diff --git a/src/main/java/umc/kkijuk/server/recruit/domain/Recruit.java b/src/main/java/umc/kkijuk/server/recruit/domain/Recruit.java index 80759506..0336c80f 100644 --- a/src/main/java/umc/kkijuk/server/recruit/domain/Recruit.java +++ b/src/main/java/umc/kkijuk/server/recruit/domain/Recruit.java @@ -43,4 +43,17 @@ public Recruit update(RecruitUpdate recruitUpdate) { .link(recruitUpdate.getLink()) .build(); } + + public Recruit updateStatus(RecruitStatusUpdate recruitStatusUpdate) { + return Recruit.builder() + .id(this.id) + .title(this.getTitle()) + .status(recruitStatusUpdate.getStatus()) + .startTime(this.getStartTime()) + .endTime(this.getEndTime()) + .applyDate(this.getApplyDate()) + .tags(this.getTags()) + .link(this.getLink()) + .build(); + } } diff --git a/src/main/java/umc/kkijuk/server/recruit/domain/RecruitStatusUpdate.java b/src/main/java/umc/kkijuk/server/recruit/domain/RecruitStatusUpdate.java new file mode 100644 index 00000000..7918465f --- /dev/null +++ b/src/main/java/umc/kkijuk/server/recruit/domain/RecruitStatusUpdate.java @@ -0,0 +1,15 @@ +package umc.kkijuk.server.recruit.domain; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.*; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RecruitStatusUpdate { + @NotNull + @Schema(description = "변경될 공고 상태", example = "REJECTED", type = "string") + private RecruitStatus status; +} diff --git a/src/main/java/umc/kkijuk/server/recruit/service/RecruitServiceImpl.java b/src/main/java/umc/kkijuk/server/recruit/service/RecruitServiceImpl.java index 35858164..42a94f1f 100644 --- a/src/main/java/umc/kkijuk/server/recruit/service/RecruitServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/recruit/service/RecruitServiceImpl.java @@ -8,6 +8,7 @@ import umc.kkijuk.server.recruit.controller.port.RecruitService; import umc.kkijuk.server.recruit.domain.Recruit; import umc.kkijuk.server.recruit.domain.RecruitCreateDto; +import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate; import umc.kkijuk.server.recruit.domain.RecruitUpdate; import umc.kkijuk.server.recruit.service.port.RecruitRepository; @@ -40,5 +41,11 @@ public Recruit update(Long recruitId, RecruitUpdate recruitUpdate) { return recruitRepository.save(recruit); } - + @Override + @Transactional + public Recruit updateStatus(long recruitId, RecruitStatusUpdate recruitStatusUpdate) { + Recruit recruit = getById(recruitId); + recruit = recruit.updateStatus(recruitStatusUpdate); + return recruitRepository.save(recruit); + } } diff --git a/src/test/java/umc/kkijuk/server/recruit/service/RecruitServiceTest.java b/src/test/java/umc/kkijuk/server/recruit/service/RecruitServiceTest.java index 69380826..4612a6a8 100644 --- a/src/test/java/umc/kkijuk/server/recruit/service/RecruitServiceTest.java +++ b/src/test/java/umc/kkijuk/server/recruit/service/RecruitServiceTest.java @@ -5,10 +5,7 @@ import org.junit.jupiter.api.Test; import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException; import umc.kkijuk.server.recruit.controller.port.RecruitService; -import umc.kkijuk.server.recruit.domain.Recruit; -import umc.kkijuk.server.recruit.domain.RecruitCreateDto; -import umc.kkijuk.server.recruit.domain.RecruitStatus; -import umc.kkijuk.server.recruit.domain.RecruitUpdate; +import umc.kkijuk.server.recruit.domain.*; import umc.kkijuk.server.recruit.mock.FakeRecruitRepository; import umc.kkijuk.server.recruit.service.port.RecruitRepository; @@ -141,7 +138,40 @@ void init() { //when //then - Assertions.assertThatThrownBy( + assertThatThrownBy( () -> recruitService.update(2L, recruitUpdate)).isInstanceOf(ResourceNotFoundException.class); } + + @Test + void status만_수정시_없는_리소스로의_요청은_에러() { + //given + RecruitStatusUpdate recruitStatusUpdate = RecruitStatusUpdate.builder() + .status(RecruitStatus.ACCEPTED).build(); + + //when + //then + assertThatThrownBy( + () -> recruitService.updateStatus(2L, recruitStatusUpdate)).isInstanceOf(ResourceNotFoundException.class); + } + + @Test + void 기존_recruit_status_수정() { + //given + RecruitStatusUpdate recruitStatusUpdate = RecruitStatusUpdate.builder() + .status(RecruitStatus.ACCEPTED).build(); + + //when + Recruit result = recruitService.updateStatus(1L, recruitStatusUpdate); + assertAll( + () -> assertThat(result.getId()).isEqualTo(1L), + () -> assertThat(result.getTitle()).isEqualTo("test-title"), + () -> assertThat(result.getStatus()).isEqualTo(RecruitStatus.ACCEPTED), + () -> assertThat(result.getStartTime()).isEqualTo(LocalDateTime.of(2024, 7, 19, 2, 30)), + () -> assertThat(result.getEndTime().isEqual(LocalDateTime.of(2024, 7, 31, 17, 30))), + () -> assertThat(result.getApplyDate().isEqual(LocalDate.of(2024, 7, 19))), + () -> assertThat(result.getTags().size()).isEqualTo(3), + () -> assertEquals(result.getTags(), Arrays.asList("코딩 테스트", "인턴", "대외 활동")), + () -> assertThat(result.getLink()).isEqualTo("test-link") + ); + } } \ No newline at end of file