Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#552 feature 공고 상세 조회 api #738

Merged
merged 9 commits into from
Mar 19, 2024
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package gg.data.recruit.recruitment;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
Expand All @@ -10,6 +13,7 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import gg.data.BaseTimeEntity;
import gg.data.recruit.recruitment.enums.InputType;
Expand All @@ -27,7 +31,7 @@ public class Question extends BaseTimeEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recruit_id", nullable = false)
private Recruitments recruitId;
private Recruitments recruit;

@Enumerated(EnumType.STRING)
@Column(length = 20, nullable = false)
Expand All @@ -36,6 +40,9 @@ public class Question extends BaseTimeEntity {
@Column(length = 300)
private String question;

@OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
private List<CheckList> checkLists;

private int sortNum;

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public Recruitments(String title, String contents, String generation, LocalDateT
this.isFinish = false;
this.isDeleted = false;
}

public void del() {
this.isDeleted = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
public enum InputType {

TEXT("text", "텍스트"),
CHECK_LIST("checkList", "체크리스트");
SINGLE_CHECK("single_check", "싱글 체크리스트"),
MULTI_CHECK("multi_check", "멀티 체크리스트");
private final String type;
private final String desc;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,37 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.recruit.api.user.controller.response.ActiveRecruitmentListResDto;
import gg.recruit.api.user.controller.response.RecruitmentDetailResDto;
import gg.recruit.api.user.service.ApplicationService;
import gg.recruit.api.user.service.RecruitmentService;
import gg.utils.dto.PageRequestDto;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/recruitments")
public class RecruitmentController {
private final RecruitmentService recruitmentService;
private final ApplicationService applicationService;

@GetMapping
public ActiveRecruitmentListResDto findActiveRecruitmentList(PageRequestDto requestDto) {
Pageable pageable = PageRequest.of(requestDto.getPage() - 1, requestDto.getSize());
return new ActiveRecruitmentListResDto(recruitmentService.findActiveRecruitmentList(pageable));
}

@GetMapping("/{recruitmentId}")
public RecruitmentDetailResDto findRecruitmentDetail(@Parameter(hidden = true) @Login UserDto user,
@PathVariable Long recruitmentId) {
return new RecruitmentDetailResDto(recruitmentService.findRecruitmentDetail(recruitmentId),
applicationService.findApplicationByUserAndRecruit(user.getId(), recruitmentId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gg.recruit.api.user.controller.response;

import gg.recruit.api.user.service.response.CheckItemSvcDto;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class CheckItemResDto {
private Long id;
private String contents;

public CheckItemResDto(CheckItemSvcDto dto) {
this.id = dto.getId();
this.contents = dto.getContents();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gg.recruit.api.user.controller.response;

import java.util.List;
import java.util.stream.Collectors;

import gg.data.recruit.recruitment.enums.InputType;
import gg.recruit.api.user.service.response.FormDetailSvcDto;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class FormDetailResDto {
private Long questionId;
private String question;
private InputType inputType;
private List<CheckItemResDto> checkList;

public FormDetailResDto(FormDetailSvcDto dto) {
this.questionId = dto.getQuestionId();
this.question = dto.getQuestion();
this.inputType = dto.getInputType();
this.checkList = dto.getCheckList().stream().map(CheckItemResDto::new).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gg.recruit.api.user.controller.response;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

import gg.recruit.api.user.service.response.RecruitmentDetailSvcDto;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class RecruitmentDetailResDto {
private LocalDateTime startDate;
private LocalDateTime endDate;
private String title;
private String contents;
private String generation;
private List<FormDetailResDto> forms;
private Long applicationId;

public RecruitmentDetailResDto(RecruitmentDetailSvcDto dto, Long applicationId) {
this.startDate = dto.getStartDate();
this.endDate = dto.getEndDate();
this.title = dto.getTitle();
this.contents = dto.getContents();
this.generation = dto.getGeneration();
this.forms = dto.getForms().stream().map(FormDetailResDto::new).collect(Collectors.toList());
this.applicationId = applicationId;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gg.recruit.api.user.service;

import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -35,4 +36,9 @@ public ApplicationWithAnswerSvcDto findMyApplicationDetail(FindApplicationDetail
}
return new ApplicationWithAnswerSvcDto(answers);
}

public Long findApplicationByUserAndRecruit(Long userId, Long recruitId) {
Optional<Application> application = applicationRepository.findByUserIdAndRecruitId(userId, recruitId);
return application.map(Application::getId).orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gg.recruit.api.user.service;

import java.util.List;

import org.springframework.stereotype.Service;

import gg.data.recruit.recruitment.Question;
import gg.repo.recruit.user.recruitment.QuestionRepository;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class QuestionService {
private final QuestionRepository questionRepository;

public List<Question> findQuestionsByRecruitId(Long recruitId) {
return questionRepository.findAllByRecruitId(recruitId);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package gg.recruit.api.user.service;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import gg.data.recruit.recruitment.Question;
import gg.data.recruit.recruitment.Recruitments;
import gg.recruit.api.user.service.response.RecruitmentDetailSvcDto;
import gg.recruit.api.user.service.response.RecruitmentListSvcDto;
import gg.repo.recruit.user.recruitment.RecruitmentRepository;
import gg.utils.exception.custom.NotExistException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class RecruitmentService {
private final RecruitmentRepository recruitmentRepository;
private final QuestionService questionService;

public RecruitmentListSvcDto findActiveRecruitmentList(Pageable pageable) {
Page<Recruitments> pages = recruitmentRepository.findActiveRecruitmentList(LocalDateTime.now(), pageable);
return new RecruitmentListSvcDto(pages.getContent(), pages.getTotalPages());
}

public RecruitmentDetailSvcDto findRecruitmentDetail(Long recruitmentId) {
Recruitments recruit = recruitmentRepository.findByActiveRecruit(recruitmentId, LocalDateTime.now())
.orElseThrow(() -> new NotExistException("Recruitment id 가 유효하지 않습니다."));
List<Question> questions = questionService.findQuestionsByRecruitId(recruitmentId);
return new RecruitmentDetailSvcDto(recruit, questions);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gg.recruit.api.user.service.response;

import gg.data.recruit.recruitment.CheckList;
import lombok.Getter;

@Getter
public class CheckItemSvcDto {
private Long id;
private String contents;

public CheckItemSvcDto(CheckList checkList) {
this.id = checkList.getId();
this.contents = checkList.getContent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package gg.recruit.api.user.service.response;

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 FormDetailSvcDto {
private Long questionId;
private String question;
private InputType inputType;
private List<CheckItemSvcDto> checkList;

public FormDetailSvcDto(Question question) {
this.questionId = question.getId();
this.question = question.getQuestion();
this.inputType = question.getInputType();
this.checkList = question.getCheckLists().stream().map(CheckItemSvcDto::new).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package gg.recruit.api.user.service.response;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

import gg.data.recruit.recruitment.Question;
import gg.data.recruit.recruitment.Recruitments;
import lombok.Getter;

@Getter
public class RecruitmentDetailSvcDto {
private LocalDateTime startDate;
private LocalDateTime endDate;
private String title;
private String contents;
private String generation;
private List<FormDetailSvcDto> forms;

public RecruitmentDetailSvcDto(Recruitments recruit, List<Question> questions) {
this.startDate = recruit.getStartTime();
this.endDate = recruit.getEndTime();
this.title = recruit.getTitle();
this.contents = recruit.getContents();
this.generation = recruit.getGeneration();
this.forms = questions.stream().map(FormDetailSvcDto::new).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

import com.fasterxml.jackson.databind.ObjectMapper;

import gg.data.recruit.application.Application;
import gg.data.recruit.recruitment.Recruitments;
import gg.data.user.User;
import gg.recruit.api.user.controller.response.ActiveRecruitmentListResDto;
import gg.recruit.api.user.controller.response.RecruitmentDetailResDto;
import gg.utils.RecruitMockData;
import gg.utils.TestDataUtils;
import gg.utils.annotation.IntegrationTest;
Expand Down Expand Up @@ -55,4 +57,55 @@ void findActiveRecruitmentList() throws Exception {
assertThat(resDto.getRecruitments().size()).isEqualTo(3);
assertThat(resDto.getTotalPage()).isEqualTo(1);
}

@Test
@DisplayName("GET /recruitments/{recruitmentId} -> 200 OK TEST")
void findRecruitmentDetail() throws Exception {
//given
User user = testDataUtils.createNewUser();
String accessToken = testDataUtils.getLoginAccessTokenFromUser(user);

Recruitments recruitments = recruitMockData.createRecruitments();
//when
String res = mockMvc.perform(get("/recruitments/" + recruitments.getId())
.header("Authorization", "Bearer " + accessToken))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();

//then
}

@Test
@DisplayName("GET /recruitments/{recruitmentId} -> 404 NOT FOUND TEST")
void findRecruitmentDetailDel() throws Exception {
//given
User user = testDataUtils.createNewUser();
String accessToken = testDataUtils.getLoginAccessTokenFromUser(user);

Recruitments recruitments = recruitMockData.createRecruitmentsDel();
//when
String res = mockMvc.perform(get("/recruitments/" + recruitments.getId())
.header("Authorization", "Bearer " + accessToken))
.andExpect(status().isNotFound()).andReturn().getResponse().getContentAsString();

//then
}

@Test
@DisplayName("GET /recruitments/{recruitmentId} 지원서 id 조회 -> 200 OK TEST")
void findRecruitmentDetailAndApplicationId() throws Exception {
//given
User user = testDataUtils.createNewUser();
String accessToken = testDataUtils.getLoginAccessTokenFromUser(user);

Recruitments recruitments = recruitMockData.createRecruitments();
Application application = recruitMockData.createApplication(user, recruitments);
//when
String result = mockMvc.perform(get("/recruitments/" + recruitments.getId())
.header("Authorization", "Bearer " + accessToken))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();

//then
RecruitmentDetailResDto res = objectMapper.readValue(result, RecruitmentDetailResDto.class);
assertThat(res.getApplicationId()).isNotNull();
}
}
Loading
Loading