Skip to content

Commit

Permalink
[FEAT] #559 application detail api proto
Browse files Browse the repository at this point in the history
  • Loading branch information
wken5577 committed Mar 10, 2024
1 parent 388fc60 commit 60c1b05
Show file tree
Hide file tree
Showing 21 changed files with 293 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,44 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import gg.data.BaseTimeEntity;
import gg.data.recruit.recruitment.Question;
import gg.data.recruit.recruitment.enums.InputType;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ApplicationAnswer extends BaseTimeEntity {
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class ApplicationAnswer extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id", nullable = false)
private Question questionId;
private Question question;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "application_id", nullable = false)
private Application applicationId;
@Getter
private Application application;

public InputType getInputType() {
return question.getInputType();
}

public Long getQuestionId(){
return question.getId();
}

public abstract FormEntityDto toForm();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@

@Entity
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class ApplicationAnswerCheckList extends BaseTimeEntity {
public class ApplicationAnswerCheckList extends ApplicationAnswer {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "application_answer_id", nullable = false)
private ApplicationAnswer applicationAnswerId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "check_list_id", nullable = false)
private CheckList checkListId;
private CheckList checkList;

@Override
public FormEntityDto toForm() {
return new FormEntityDto(this.getQuestionId(), this.getInputType(),
new CheckListEntityDto(checkList.getId(), checkList.getContent()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@

@Entity
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class ApplicationAnswerText extends BaseTimeEntity {
public class ApplicationAnswerText extends ApplicationAnswer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "application_answer_id", nullable = false)
private ApplicationAnswer applicationAnswerId;

@Column(length = 1000)
private String answer;

@Override
public FormEntityDto toForm() {
return new FormEntityDto(this.getQuestionId(), this.getInputType(), answer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gg.data.recruit.application;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class CheckListEntityDto {
private Long checkListId;
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gg.data.recruit.application;
import gg.data.recruit.recruitment.enums.InputType;
import lombok.Getter;

@Getter
public class FormEntityDto {
private Long questionId;
private InputType inputType;

private CheckListEntityDto checkedList;
private String answer;

public FormEntityDto(Long questionId, InputType inputType, CheckListEntityDto checkedList) {
this.questionId = questionId;
this.inputType = inputType;
this.checkedList = checkedList;
}

public FormEntityDto(Long questionId, InputType inputType, String answer) {
this.questionId = questionId;
this.inputType = inputType;
this.answer = answer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

import gg.data.BaseTimeEntity;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
public class CheckList extends BaseTimeEntity {

@Id
Expand All @@ -23,7 +25,7 @@ public class CheckList extends BaseTimeEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id", nullable = false)
private Question questionId;
private Question question;

@Column(length = 100)
private String content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import gg.data.BaseTimeEntity;
import gg.data.recruit.recruitment.enums.InputType;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Question extends BaseTimeEntity {
@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.recruit.api.user.application.controller.response.MyApplicationDetailResDto;
import gg.recruit.api.user.application.controller.response.MyApplicationsResDto;
import gg.recruit.api.user.application.service.ApplicationService;
import gg.recruit.api.user.application.service.response.ApplicationListDto;
import gg.recruit.api.user.application.service.param.FindApplicationDetailParam;
import gg.recruit.api.user.application.service.response.ApplicationListSvcDto;
import gg.recruit.api.user.application.service.response.ApplicationWithAnswerSvcDto;
import lombok.RequiredArgsConstructor;

@RestController
Expand All @@ -19,7 +22,15 @@ public class ApplicationController {
private final ApplicationService applicationService;
@GetMapping("/applications")
public MyApplicationsResDto getMyApplications(@Login UserDto userDto) {
ApplicationListDto res = applicationService.findMyApplications(userDto.getId());
ApplicationListSvcDto res = applicationService.findMyApplications(userDto.getId());
return new MyApplicationsResDto(res);
}

@GetMapping("{recruitmentId}/applications/{applicationId}")
public MyApplicationDetailResDto getMyApplication(@Login UserDto userDto, Long recruitmentId, Long applicationId) {
ApplicationWithAnswerSvcDto res = applicationService
.findMyApplicationDetail(new FindApplicationDetailParam(userDto.getId(), recruitmentId, applicationId));
return new MyApplicationDetailResDto(res);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.time.LocalDateTime;

import gg.recruit.api.user.application.service.response.ApplicationDto;
import gg.recruit.api.user.application.service.response.ApplicationSvcDto;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -17,7 +17,7 @@ public class ApplicationResDto {
private String generation;
private String status;

public ApplicationResDto(ApplicationDto applicationDto) {
public ApplicationResDto(ApplicationSvcDto applicationDto) {
this.recruitId = applicationDto.getRecruitId();
this.applicationId = applicationDto.getApplicationId();
this.startDate = applicationDto.getStartDate();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gg.recruit.api.user.application.controller.response;

import gg.recruit.api.user.application.service.response.CheckListSvcDto;
import lombok.Getter;

@Getter
public class CheckListResDto {
private Long checkListId;
private String content;

public CheckListResDto(CheckListSvcDto checkListSvcDto) {
this.checkListId = checkListSvcDto.getCheckListId();
this.content = checkListSvcDto.getContent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gg.recruit.api.user.application.controller.response;

import static java.util.stream.Collectors.*;

import java.util.List;

import gg.recruit.api.user.application.service.response.FormSvcDto;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public class FormResDto {
private Long questionId;
private String inputType;
private List<CheckListResDto> checkeList;
private String answer;

public FormResDto(FormSvcDto formSvcDto) {
this.questionId = formSvcDto.getQuestionId();
this.inputType = formSvcDto.getInputType();
this.checkeList = formSvcDto.getCheckedList().stream()
.map(CheckListResDto::new).collect(toList());
this.answer = formSvcDto.getAnswer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package gg.recruit.api.user.application.controller.response;

import static java.util.stream.Collectors.*;

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

import gg.recruit.api.user.application.service.response.ApplicationWithAnswerSvcDto;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public class MyApplicationDetailResDto {
private Long applicationId;
private LocalDateTime endTime;
private String title;
private String content;
private List<FormResDto> from;

public MyApplicationDetailResDto(ApplicationWithAnswerSvcDto applicationWithAnswerSvcDto) {
this.applicationId = applicationWithAnswerSvcDto.getApplicationId();
this.endTime = applicationWithAnswerSvcDto.getEndTime();
this.title = applicationWithAnswerSvcDto.getTitle();
this.content = applicationWithAnswerSvcDto.getContent();
this.from = applicationWithAnswerSvcDto.getForm().stream()
.map(FormResDto::new)
.collect(toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import java.util.stream.Collectors;

import gg.recruit.api.user.application.service.response.ApplicationListDto;
import gg.recruit.api.user.application.service.response.ApplicationListSvcDto;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -12,7 +12,7 @@
public class MyApplicationsResDto {
private List<ApplicationResDto> applications;

public MyApplicationsResDto(ApplicationListDto applicationListDto) {
public MyApplicationsResDto(ApplicationListSvcDto applicationListDto) {
applications = applicationListDto.getApplications()
.stream()
.map(ApplicationResDto::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,33 @@
import org.springframework.stereotype.Service;

import gg.data.recruit.application.Application;
import gg.recruit.api.user.application.service.response.ApplicationListDto;
import gg.data.recruit.application.ApplicationAnswer;
import gg.recruit.api.user.application.service.param.FindApplicationDetailParam;
import gg.recruit.api.user.application.service.response.ApplicationListSvcDto;
import gg.recruit.api.user.application.service.response.ApplicationWithAnswerSvcDto;
import gg.repo.recruit.user.application.ApplicationAnswerRepository;
import gg.repo.recruit.user.application.ApplicationRepository;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.NotExistException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ApplicationService {

private final ApplicationRepository applicationRepository;
private final ApplicationAnswerRepository applicationAnswerRepository;

public ApplicationListDto findMyApplications(Long userId) {
public ApplicationListSvcDto findMyApplications(Long userId) {
List<Application> res = applicationRepository.findAllByUserId(userId);
return new ApplicationListDto(res);
return new ApplicationListSvcDto(res);
}

public ApplicationWithAnswerSvcDto findMyApplicationDetail(FindApplicationDetailParam param) {
List<ApplicationAnswer> answers = applicationAnswerRepository
.findAllAnswers(param.getUserId(), param.getRecruitId(), param.getApplicationId());
if (answers.size() == 0)
throw new NotExistException("application not found", ErrorCode.BAD_REQUEST);
return new ApplicationWithAnswerSvcDto(answers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gg.recruit.api.user.application.service.param;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class FindApplicationDetailParam {
private Long userId;
private Long recruitId;
private Long applicationId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import lombok.Getter;

@Getter
public class ApplicationListDto {
List<ApplicationDto> applications;
public class ApplicationListSvcDto {
List<ApplicationSvcDto> applications;

public ApplicationListDto(List<Application> applications) {
this.applications = applications.stream().map(ApplicationDto::new)
public ApplicationListSvcDto(List<Application> applications) {
this.applications = applications.stream().map(ApplicationSvcDto::new)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Getter
@NoArgsConstructor
public class ApplicationDto {
public class ApplicationSvcDto {
private Long recruitId;
private Long applicationId;
private LocalDateTime startDate;
Expand All @@ -17,7 +17,7 @@ public class ApplicationDto {
private String generation;
private String status;

public ApplicationDto(Application application) {
public ApplicationSvcDto(Application application) {
this.recruitId = application.getRecruit().getId();
this.applicationId = application.getId();
this.startDate = application.getRecruit().getStartTime();
Expand Down
Loading

0 comments on commit 60c1b05

Please sign in to comment.