Skip to content

Commit

Permalink
[FEAT] #811 admin recruit detail api (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
wken5577 authored Apr 7, 2024
1 parent 49ea386 commit 5163655
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Recruitment, Long> {
Page<Recruitment> findAllByOrderByEndTimeDesc(Pageable pageable);

@Query("SELECT r FROM Recruitment r WHERE r.id = :recruitId AND r.isDeleted = false")
Optional<Recruitment> findNotDeletedRecruit(Long recruitId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,6 +65,13 @@ public ResponseEntity<CreatedRecruitmentResponse> 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<Void> updateRecruitStatus(@PathVariable @Positive Long recruitId,
@RequestBody UpdateStatusRequestDto requestDto) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<CheckItemAdminResDto> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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<FormDetailAdminResDto> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -224,4 +225,9 @@ public Page<Application> findApplicationsWithAnswersAndUserWithFilter(GetRecruit
}
}

public RecruitmentDetailAdminSvcDto findRecruitmentDetail(Long recruitId) {
Recruitment recruitment = recruitmentAdminRepository.findNotDeletedRecruit(recruitId)
.orElseThrow(() -> new NotExistException("Recruitment not found."));
return new RecruitmentDetailAdminSvcDto(recruitment);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<CheckItemAdminSvcDto> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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<FormDetailAdminSvcDto> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5163655

Please sign in to comment.