From 5163655767f7c320f4483fe99b072df0cce66d16 Mon Sep 17 00:00:00 2001 From: Hyunkyu Lee <88573971+wken5577@users.noreply.github.com> Date: Sun, 7 Apr 2024 17:46:37 +0900 Subject: [PATCH] [FEAT] #811 admin recruit detail api (#812) --- .../recruit/RecruitmentAdminRepository.java | 6 ++++ .../RecruitmentAdminController.java | 8 +++++ .../response/CheckItemAdminResDto.java | 17 +++++++++++ .../response/FormDetailAdminResDto.java | 26 ++++++++++++++++ .../RecruitmentAdminDetailResDto.java | 30 +++++++++++++++++++ .../service/RecruitmentAdminService.java | 6 ++++ .../service/result/CheckItemAdminSvcDto.java | 15 ++++++++++ .../service/result/FormDetailAdminSvcDto.java | 24 +++++++++++++++ .../result/RecruitmentDetailAdminSvcDto.java | 28 +++++++++++++++++ .../RecruitmentAdminIntegrationTest.java | 30 +++++++++++++++++++ 10 files changed, 190 insertions(+) create mode 100644 gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/CheckItemAdminResDto.java create mode 100644 gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/FormDetailAdminResDto.java create mode 100644 gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/RecruitmentAdminDetailResDto.java create mode 100644 gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/CheckItemAdminSvcDto.java create mode 100644 gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/FormDetailAdminSvcDto.java create mode 100644 gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/RecruitmentDetailAdminSvcDto.java diff --git a/gg-admin-repo/src/main/java/gg/admin/repo/recruit/RecruitmentAdminRepository.java b/gg-admin-repo/src/main/java/gg/admin/repo/recruit/RecruitmentAdminRepository.java index 24504dd70..95a1bb2b2 100644 --- a/gg-admin-repo/src/main/java/gg/admin/repo/recruit/RecruitmentAdminRepository.java +++ b/gg-admin-repo/src/main/java/gg/admin/repo/recruit/RecruitmentAdminRepository.java @@ -1,11 +1,17 @@ package gg.admin.repo.recruit; +import java.util.Optional; + import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import gg.data.recruit.recruitment.Recruitment; public interface RecruitmentAdminRepository extends JpaRepository { Page findAllByOrderByEndTimeDesc(Pageable pageable); + + @Query("SELECT r FROM Recruitment r WHERE r.id = :recruitId AND r.isDeleted = false") + Optional findNotDeletedRecruit(Long recruitId); } diff --git a/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/RecruitmentAdminController.java b/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/RecruitmentAdminController.java index 12890dfcc..2cc711293 100644 --- a/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/RecruitmentAdminController.java +++ b/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/RecruitmentAdminController.java @@ -34,6 +34,7 @@ import gg.recruit.api.admin.controller.request.UpdateStatusRequestDto; import gg.recruit.api.admin.controller.response.CreatedRecruitmentResponse; import gg.recruit.api.admin.controller.response.GetRecruitmentApplicationResponseDto; +import gg.recruit.api.admin.controller.response.RecruitmentAdminDetailResDto; import gg.recruit.api.admin.controller.response.RecruitmentApplicantResultResponseDto; import gg.recruit.api.admin.controller.response.RecruitmentApplicantResultsResponseDto; import gg.recruit.api.admin.controller.response.RecruitmentsResponse; @@ -64,6 +65,13 @@ public ResponseEntity createRecruitment( return ResponseEntity.status(HttpStatus.CREATED).body(createdRecruitmentResponse); } + @GetMapping("/{recruitId}") + public RecruitmentAdminDetailResDto findRecruitmentDetail(@PathVariable Long recruitId) { + RecruitmentAdminDetailResDto res = new RecruitmentAdminDetailResDto( + recruitmentAdminService.findRecruitmentDetail(recruitId)); + return res; + } + @PatchMapping("/{recruitId}/status") public ResponseEntity updateRecruitStatus(@PathVariable @Positive Long recruitId, @RequestBody UpdateStatusRequestDto requestDto) { diff --git a/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/CheckItemAdminResDto.java b/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/CheckItemAdminResDto.java new file mode 100644 index 000000000..2b4a0d9b6 --- /dev/null +++ b/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/CheckItemAdminResDto.java @@ -0,0 +1,17 @@ +package gg.recruit.api.admin.controller.response; + +import gg.recruit.api.admin.service.result.CheckItemAdminSvcDto; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Getter +public class CheckItemAdminResDto { + private Long id; + private String contents; + + public CheckItemAdminResDto(CheckItemAdminSvcDto dto) { + this.id = dto.getId(); + this.contents = dto.getContents(); + } +} diff --git a/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/FormDetailAdminResDto.java b/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/FormDetailAdminResDto.java new file mode 100644 index 000000000..d05ed9fa7 --- /dev/null +++ b/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/FormDetailAdminResDto.java @@ -0,0 +1,26 @@ +package gg.recruit.api.admin.controller.response; + +import java.util.List; +import java.util.stream.Collectors; + +import gg.data.recruit.recruitment.enums.InputType; +import gg.recruit.api.admin.service.result.FormDetailAdminSvcDto; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Getter +public class FormDetailAdminResDto { + private Long questionId; + private String question; + private InputType inputType; + private List checkList; + + public FormDetailAdminResDto(FormDetailAdminSvcDto dto) { + this.questionId = dto.getQuestionId(); + this.question = dto.getQuestion(); + this.inputType = dto.getInputType(); + this.checkList = dto.getCheckList().stream() + .map(CheckItemAdminResDto::new).collect(Collectors.toList()); + } +} diff --git a/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/RecruitmentAdminDetailResDto.java b/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/RecruitmentAdminDetailResDto.java new file mode 100644 index 000000000..a7809205a --- /dev/null +++ b/gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/RecruitmentAdminDetailResDto.java @@ -0,0 +1,30 @@ +package gg.recruit.api.admin.controller.response; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +import gg.recruit.api.admin.service.result.RecruitmentDetailAdminSvcDto; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class RecruitmentAdminDetailResDto { + private LocalDateTime startDate; + private LocalDateTime endDate; + private String title; + private String contents; + private String generation; + private List forms; + + public RecruitmentAdminDetailResDto(RecruitmentDetailAdminSvcDto recruitmentDetail) { + this.startDate = recruitmentDetail.getStartDate(); + this.endDate = recruitmentDetail.getEndDate(); + this.title = recruitmentDetail.getTitle(); + this.contents = recruitmentDetail.getContents(); + this.generation = recruitmentDetail.getGeneration(); + this.forms = recruitmentDetail.getForms().stream() + .map(FormDetailAdminResDto::new).collect(Collectors.toList()); + } +} diff --git a/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/RecruitmentAdminService.java b/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/RecruitmentAdminService.java index 44cae27ab..7fce2d982 100644 --- a/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/RecruitmentAdminService.java +++ b/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/RecruitmentAdminService.java @@ -26,6 +26,7 @@ import gg.recruit.api.admin.service.param.UpdateApplicationStatusParam; import gg.recruit.api.admin.service.param.UpdateRecruitStatusParam; import gg.recruit.api.admin.service.result.AllRecruitmentsResult; +import gg.recruit.api.admin.service.result.RecruitmentDetailAdminSvcDto; import gg.utils.exception.ErrorCode; import gg.utils.exception.custom.BusinessException; import gg.utils.exception.custom.DuplicationException; @@ -224,4 +225,9 @@ public Page findApplicationsWithAnswersAndUserWithFilter(GetRecruit } } + public RecruitmentDetailAdminSvcDto findRecruitmentDetail(Long recruitId) { + Recruitment recruitment = recruitmentAdminRepository.findNotDeletedRecruit(recruitId) + .orElseThrow(() -> new NotExistException("Recruitment not found.")); + return new RecruitmentDetailAdminSvcDto(recruitment); + } } diff --git a/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/CheckItemAdminSvcDto.java b/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/CheckItemAdminSvcDto.java new file mode 100644 index 000000000..6446d75a4 --- /dev/null +++ b/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/CheckItemAdminSvcDto.java @@ -0,0 +1,15 @@ +package gg.recruit.api.admin.service.result; + +import gg.data.recruit.recruitment.CheckList; +import lombok.Getter; + +@Getter +public class CheckItemAdminSvcDto { + private Long id; + private String contents; + + public CheckItemAdminSvcDto(CheckList checkList) { + this.id = checkList.getId(); + this.contents = checkList.getContent(); + } +} diff --git a/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/FormDetailAdminSvcDto.java b/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/FormDetailAdminSvcDto.java new file mode 100644 index 000000000..4a06b6fa0 --- /dev/null +++ b/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/FormDetailAdminSvcDto.java @@ -0,0 +1,24 @@ +package gg.recruit.api.admin.service.result; + +import java.util.List; +import java.util.stream.Collectors; + +import gg.data.recruit.recruitment.Question; +import gg.data.recruit.recruitment.enums.InputType; +import lombok.Getter; + +@Getter +public class FormDetailAdminSvcDto { + private Long questionId; + private String question; + private InputType inputType; + private List checkList; + + public FormDetailAdminSvcDto(Question question) { + this.questionId = question.getId(); + this.question = question.getQuestion(); + this.inputType = question.getInputType(); + this.checkList = question.getCheckLists().stream() + .map(CheckItemAdminSvcDto::new).collect(Collectors.toList()); + } +} diff --git a/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/RecruitmentDetailAdminSvcDto.java b/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/RecruitmentDetailAdminSvcDto.java new file mode 100644 index 000000000..b3db2cf54 --- /dev/null +++ b/gg-recruit-api/src/main/java/gg/recruit/api/admin/service/result/RecruitmentDetailAdminSvcDto.java @@ -0,0 +1,28 @@ +package gg.recruit.api.admin.service.result; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +import gg.data.recruit.recruitment.Recruitment; +import lombok.Getter; + +@Getter +public class RecruitmentDetailAdminSvcDto { + private LocalDateTime startDate; + private LocalDateTime endDate; + private String title; + private String contents; + private String generation; + private List forms; + + public RecruitmentDetailAdminSvcDto(Recruitment recruit) { + this.startDate = recruit.getStartTime(); + this.endDate = recruit.getEndTime(); + this.title = recruit.getTitle(); + this.contents = recruit.getContents(); + this.generation = recruit.getGeneration(); + this.forms = recruit.getQuestions().stream() + .map(FormDetailAdminSvcDto::new).collect(Collectors.toList()); + } +} diff --git a/gg-recruit-api/src/test/java/gg/recruit/api/admin/integration/RecruitmentAdminIntegrationTest.java b/gg-recruit-api/src/test/java/gg/recruit/api/admin/integration/RecruitmentAdminIntegrationTest.java index 83065b400..b0ca4d5ed 100644 --- a/gg-recruit-api/src/test/java/gg/recruit/api/admin/integration/RecruitmentAdminIntegrationTest.java +++ b/gg-recruit-api/src/test/java/gg/recruit/api/admin/integration/RecruitmentAdminIntegrationTest.java @@ -37,6 +37,7 @@ import gg.recruit.api.RecruitMockData; import gg.recruit.api.admin.controller.request.InterviewRequestDto; import gg.recruit.api.admin.controller.request.RecruitmentRequestDto; +import gg.recruit.api.admin.controller.response.RecruitmentAdminDetailResDto; import gg.recruit.api.admin.service.param.FormParam; import gg.utils.TestDataUtils; import gg.utils.annotation.IntegrationTest; @@ -69,6 +70,35 @@ public class RecruitmentAdminIntegrationTest { @Autowired private ApplicationAdminRepository applicationAdminRepository; + @Nested + @DisplayName("공고 상세 조회 시 - GET /admin/recruitments/{recruitmentId}") + class GetRecruitment { + + @DisplayName("지워진 공고가 아니라면 공고 상세 조회 성공 - 200 OK") + @Test + void getRecruitment() throws Exception { + // given + Recruitment recruitment = recruitMockData.createRecruitment(); + recruitMockData.createQuestion(recruitment); + recruitMockData.createQuestion(recruitment, "question2", + InputType.MULTI_CHECK, "check1", "check2"); + long recruitmentId = recruitment.getId(); + String url = String.format("/admin/recruitments/%d", recruitmentId); + String accessToken = testDataUtils.getAdminLoginAccessToken(); + + // when + String response = mockMvc.perform(get(url) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + RecruitmentAdminDetailResDto resDto = objectMapper.readValue(response, + RecruitmentAdminDetailResDto.class); + + assertThat(resDto.getForms().size()).isEqualTo(2); + } + + } + @Nested @DisplayName("공고 전체 조회 시 - POST /admin/recruitments") @TestInstance(TestInstance.Lifecycle.PER_CLASS)