Skip to content

Commit

Permalink
Merge pull request #8 from potenday-project/develop
Browse files Browse the repository at this point in the history
면접 재시작, 피드백 재생성, 이력서 등록제한, 면접 등록제한 추가
  • Loading branch information
HwangHoYoon authored Dec 12, 2023
2 parents 334de18 + b08ec7d commit 3812bbf
Show file tree
Hide file tree
Showing 22 changed files with 331 additions and 77 deletions.
2 changes: 1 addition & 1 deletion server_config
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class QInterview extends EntityPathBase<Interview> {

public final NumberPath<Long> interviewId = createNumber("interviewId", Long.class);

public final DateTimePath<java.util.Date> modifyDate = createDateTime("modifyDate", java.util.Date.class);

public final StringPath recruitSummary = createString("recruitSummary");

public final DateTimePath<java.util.Date> regDate = createDateTime("regDate", java.util.Date.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ public enum ExceptionCode {

RESUME_NULL("860", "이력서 정보가 올바르지 않습니다."),

RESUME_LIST_OVER("861", "이력서 최대 개수를 초과하였습니다."),

RECRUIT_CONTENT_NULL("870", "채용공고 정보가 올바르지 않습니다."),

INTERVIEW_NULL("880", "면접 정보가 올바르지 않습니다."),

INTERVIEW_LIST_OVER("881", "면접 최대 개수를 초과하였습니다."),

QA_NULL("890", "질문 정보가 올바르지 않습니다."),

TOKEN_NULL("950", "토큰정보가 올바르지 않습니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
package com.chwipoClova.feedback.controller;

import com.chwipoClova.common.response.CommonResponse;
import com.chwipoClova.feedback.request.FeedbackGenerateReq;
import com.chwipoClova.feedback.service.FeedbackService;
import com.chwipoClova.qa.request.QaAnswerInsertReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
@Tag(name = "Feedback", description = "피드백 API")
@RequestMapping("feedback")
public class FeedbackController {

private final FeedbackService feedbackService;

@Operation(summary = "피드백 재생성", description = "피드백 재생성")
@PostMapping("/generateFeedback")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class)))
}
)
public CommonResponse generateFeedback (@RequestBody FeedbackGenerateReq feedbackGenerateReq) throws Exception {
return feedbackService.generateFeedback(feedbackGenerateReq);
}


}
9 changes: 9 additions & 0 deletions src/main/java/com/chwipoClova/feedback/entity/Feedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.chwipoClova.qa.entity.Qa;
import com.chwipoClova.qa.entity.QaEditor;
import com.chwipoClova.user.entity.User;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down Expand Up @@ -60,4 +61,12 @@ public void prePersist() {
public void preUpdate() {
this.modifyDate = new Date(); // 현재 날짜와 시간으로 수정일 업데이트
}

public FeedbackEditor.FeedbackEditorBuilder toEditor() {
return FeedbackEditor.builder()
.content(content);
}
public void edit(FeedbackEditor feedbackEditor) {
content = feedbackEditor.getContent();
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/chwipoClova/feedback/entity/FeedbackEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.chwipoClova.feedback.entity;

import lombok.Builder;
import lombok.Getter;

import java.util.Date;

@Getter
public class FeedbackEditor {

private String content;

@Builder
public FeedbackEditor(String content) {
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.chwipoClova.feedback.repository;

import com.chwipoClova.feedback.entity.Feedback;
import com.chwipoClova.interview.entity.Interview;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface FeedbackRepository extends JpaRepository<Feedback, Long> {

List<Feedback> findByQaQaIdOrderByFeedbackId(Long qaId);

Optional<Feedback> findByQaQaIdAndType(Long qaId, Integer Type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.chwipoClova.feedback.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class FeedbackGenerateReq {

@Schema(description = "유저 ID", example = "1", name = "userId")
private Long userId;
@Schema(description = "면접 ID", example = "1", name = "interviewId")
private Long interviewId;

}
87 changes: 75 additions & 12 deletions src/main/java/com/chwipoClova/feedback/service/FeedbackService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@
import com.chwipoClova.common.response.CommonResponse;
import com.chwipoClova.common.response.MessageCode;
import com.chwipoClova.feedback.entity.Feedback;
import com.chwipoClova.feedback.entity.FeedbackEditor;
import com.chwipoClova.feedback.repository.FeedbackRepository;
import com.chwipoClova.feedback.request.FeedbackGenerateReq;
import com.chwipoClova.feedback.request.FeedbackInsertReq;
import com.chwipoClova.feedback.response.FeedBackApiRes;
import com.chwipoClova.feedback.response.FeedbackListRes;
import com.chwipoClova.interview.entity.Interview;
import com.chwipoClova.interview.repository.InterviewRepository;
import com.chwipoClova.qa.entity.Qa;
import com.chwipoClova.qa.entity.QaEditor;
import com.chwipoClova.qa.repository.QaRepository;
import com.chwipoClova.user.entity.User;
import com.chwipoClova.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RequiredArgsConstructor
@Service
Expand All @@ -29,10 +38,14 @@ public class FeedbackService {

private final QaRepository qaRepository;

private final InterviewRepository interviewRepository;

private final UserRepository userRepository;

@Transactional
public CommonResponse insertFeedback(List<FeedbackInsertReq> feedbackInsertListReq) throws IOException {

// TODO 피드백 연동 필요함
// TODO 피드백 연동 필요함 답변이 있는 경우만 전달하자
// 테스트 데이터
List<FeedBackApiRes> feedBackApiListRes = new ArrayList<>();
feedbackInsertListReq.stream().forEach(feedbackInsertReq -> {
Expand All @@ -49,17 +62,7 @@ public CommonResponse insertFeedback(List<FeedbackInsertReq> feedbackInsertListR
feedBackApiListRes.add(feedBackApiRes2);
});

feedBackApiListRes.stream().forEach(feedBackApiRes -> {
Long qaId = feedBackApiRes.getQaId();
Qa qa = qaRepository.findById(qaId).orElseThrow(() -> new CommonException(ExceptionCode.QA_NULL.getMessage(), ExceptionCode.QA_NULL.getCode()));

Feedback feedback = Feedback.builder()
.type(feedBackApiRes.getType())
.content(feedBackApiRes.getContent())
.qa(qa)
.build();
feedbackRepository.save(feedback);
});
insertAllFeedback(feedBackApiListRes);

return new CommonResponse<>(MessageCode.OK.getCode(), null, MessageCode.OK.getMessage());
}
Expand All @@ -82,4 +85,64 @@ public List<FeedbackListRes> selectFeedbackList(Long qaId) {
return feedbackListResList;
}

@Transactional
public CommonResponse generateFeedback(FeedbackGenerateReq feedbackGenerateReq) {
Long interviewId = feedbackGenerateReq.getInterviewId();
Long userId = feedbackGenerateReq.getUserId();

userRepository.findById(userId).orElseThrow(() -> new CommonException(ExceptionCode.USER_NULL.getMessage(), ExceptionCode.USER_NULL.getCode()));
interviewRepository.findByUserUserIdAndInterviewId(userId, interviewId).orElseThrow(() -> new CommonException(ExceptionCode.INTERVIEW_NULL.getMessage(), ExceptionCode.INTERVIEW_NULL.getCode()));

List<Qa> qaList = qaRepository.findByInterviewInterviewIdOrderByQaId(interviewId);

// TODO 피드백 연동 필요함 답변이 있는 경우만 전달하자
List<FeedBackApiRes> feedBackApiListRes = new ArrayList<>();
qaList.stream().forEach(qa -> {
String answer = qa.getAnswer();
if (StringUtils.isNotBlank(answer)) {
Long qaId = qa.getQaId();
FeedBackApiRes feedBackApiRes = new FeedBackApiRes();
feedBackApiRes.setQaId(qaId);
feedBackApiRes.setType(1);
feedBackApiRes.setContent("재생성 피드백1입니다.");
feedBackApiListRes.add(feedBackApiRes);
FeedBackApiRes feedBackApiRes2 = new FeedBackApiRes();
feedBackApiRes2.setQaId(qaId);
feedBackApiRes2.setType(2);
feedBackApiRes2.setContent("재생성 피드백2입니다.");
feedBackApiListRes.add(feedBackApiRes2);
}
});

insertAllFeedback(feedBackApiListRes);
return new CommonResponse<>(MessageCode.OK.getCode(), null, MessageCode.OK.getMessage());
}

@Transactional
public void insertAllFeedback(List<FeedBackApiRes> feedBackApiListRes) {
feedBackApiListRes.stream().forEach(feedBackApiRes -> {
Long qaId = feedBackApiRes.getQaId();
Qa qa = qaRepository.findById(qaId).orElseThrow(() -> new CommonException(ExceptionCode.QA_NULL.getMessage(), ExceptionCode.QA_NULL.getCode()));

Integer type = feedBackApiRes.getType();
String content = feedBackApiRes.getContent();
// 피드백 데이터가 있다면 수정 없으면 등록
Optional<Feedback> feedbackOptional = feedbackRepository.findByQaQaIdAndType(qaId, type);
if (feedbackOptional.isPresent()) {

Feedback feedbackInfo = feedbackOptional.get();
FeedbackEditor.FeedbackEditorBuilder editorBuilder = feedbackInfo.toEditor();
FeedbackEditor feedbackEditor = editorBuilder.content(content)
.build();
feedbackInfo.edit(feedbackEditor);
} else {
Feedback feedback = Feedback.builder()
.type(type)
.content(content)
.qa(qa)
.build();
feedbackRepository.save(feedback);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
import com.chwipoClova.interview.request.InterviewInsertReq;
import com.chwipoClova.interview.response.InterviewInsertRes;
import com.chwipoClova.interview.response.InterviewListRes;
import com.chwipoClova.interview.response.InterviewNotCompRes;
import com.chwipoClova.interview.response.InterviewRes;
import com.chwipoClova.interview.service.InterviewService;
import com.chwipoClova.resume.response.ResumeListRes;
import com.chwipoClova.resume.response.ResumeUploadRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Encoding;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand Down Expand Up @@ -68,4 +64,18 @@ public List<InterviewListRes> getInterviewList(@Schema(description = "userId", e
return interviewService.selectInterviewList(userId);
}

@Operation(summary = "미완료 면접 질문 조회", description = "미완료 면접 질문 조회")
@GetMapping(path = "/getNotCompInterview")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK")
}
)
public InterviewNotCompRes getNotCompInterview(
@Schema(description = "userId", example = "1", name = "userId") @RequestParam(name = "userId") Long userId,
@Schema(description = "interviewId", example = "1", name = "interviewId") @RequestParam(name = "interviewId") Long interviewId

) {
return interviewService.selectNotCompInterview(userId, interviewId);
}

}
10 changes: 0 additions & 10 deletions src/main/java/com/chwipoClova/interview/entity/Interview.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public class Interview {
@Schema(description = "등록일")
private Date regDate;

@Column(name = "modifyDate")
@Schema(description = "수정일")
private Date modifyDate;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId")
private User user;
Expand All @@ -58,10 +54,4 @@ public void prePersist() {
this.regDate = new Date(); // 현재 날짜와 시간으로 등록일 설정
}

// @PreUpdate 메서드 정의 (업데이트 시 호출)
@PreUpdate
public void preUpdate() {
this.modifyDate = new Date(); // 현재 날짜와 시간으로 수정일 업데이트
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public class InterviewInsertRes {
@Schema(description = "등록일", example = "2023-12-09T10:13:17.838+00:00", name = "regDate")
private Date regDate;

@Schema(description = "수정일", example = "2023-12-09T10:13:17.838+00:00", name = "modifyDate")
private Date modifyDate;

@Schema(description = "질문데이터", name = "questionData")
private List<QaQuestionInsertRes> questionData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ public class InterviewListRes {

@Schema(description = "등록일", example = "2023-12-09T10:13:17.838+00:00", name = "regDate")
private Date regDate;

@Schema(description = "수정일", example = "2023-12-09T10:13:17.838+00:00", name = "modifyDate")
private Date modifyDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.chwipoClova.interview.response;

import com.chwipoClova.qa.response.QaListRes;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
@Builder
public class InterviewNotCompRes {
@Schema(description = "면접 ID", example = "1", name = "interviewId")
private Long interviewId;

@Schema(description = "유저 ID", example = "1", name = "userId")
private Long userId;

@Schema(description = "총개수", example = "10", name = "totalCnt")
private Integer totalCnt;

@Schema(description = "답변개수", example = "1", name = "useCnt")
private Integer useCnt;

@Schema(description = "마지막 질문 ID", example = "1", name = "lastQaId")
private Long lastQaId;

@Schema(description = "질문데이터", name = "qaData")
private List<QaListRes> qaData;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chwipoClova.interview.response;

import com.chwipoClova.qa.response.QaListForFeedbackRes;
import com.chwipoClova.qa.response.QaListRes;
import com.chwipoClova.qa.response.QaQuestionInsertRes;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -21,9 +22,7 @@ public class InterviewRes {
private String title;
@Schema(description = "등록일", example = "2023-12-09T10:13:17.838+00:00", name = "regDate")
private Date regDate;
@Schema(description = "수정일", example = "2023-12-09T10:13:17.838+00:00", name = "modifyDate")
private Date modifyDate;
@Schema(description = "질문데이터", name = "qaData")
private List<QaListRes> qaData;
private List<QaListForFeedbackRes> qaData;

}
Loading

0 comments on commit 3812bbf

Please sign in to comment.