diff --git a/src/main/java/com/chwipoClova/common/exception/ExceptionCode.java b/src/main/java/com/chwipoClova/common/exception/ExceptionCode.java index 0d9cbe1..29d9354 100644 --- a/src/main/java/com/chwipoClova/common/exception/ExceptionCode.java +++ b/src/main/java/com/chwipoClova/common/exception/ExceptionCode.java @@ -47,6 +47,8 @@ public enum ExceptionCode { QA_NULL("890", "질문 정보가 올바르지 않습니다."), + FEEDBACK_NOT_NULL("891", "피드백 데이터가 있습니다."), + TOKEN_NULL("950", "토큰정보가 올바르지 않습니다."), API_NULL("980", "API 결과 NULL"), diff --git a/src/main/java/com/chwipoClova/interview/controller/InterviewController.java b/src/main/java/com/chwipoClova/interview/controller/InterviewController.java index d713edb..7994666 100644 --- a/src/main/java/com/chwipoClova/interview/controller/InterviewController.java +++ b/src/main/java/com/chwipoClova/interview/controller/InterviewController.java @@ -9,6 +9,7 @@ import com.chwipoClova.interview.response.InterviewRes; import com.chwipoClova.interview.service.InterviewService; import com.chwipoClova.qa.request.QaAnswerInsertReq; +import com.chwipoClova.qa.request.QaGenerateReq; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -70,7 +71,7 @@ public List getInterviewList(@Schema(description = "userId", e return interviewService.selectInterviewList(userId); } - @Operation(summary = "면접 질문 조회", description = "면접 질문 조회") + @Operation(summary = "질문 조회", description = "질문 조회") @GetMapping(path = "/getQaList") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK") @@ -114,6 +115,15 @@ public void downloadInterview( interviewService.downloadInterview(userId, interviewId, response); } + @Operation(summary = "질문 재생성", description = "질문 재생성") + @PostMapping("/generateQa") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))) + } + ) + public CommonResponse generateQa (@RequestBody QaGenerateReq qaGenerateReq) throws Exception { + return interviewService.generateQa(qaGenerateReq); + } @Operation(summary = "피드백 재생성", description = "피드백 재생성") @PostMapping("/generateFeedback") diff --git a/src/main/java/com/chwipoClova/interview/service/InterviewService.java b/src/main/java/com/chwipoClova/interview/service/InterviewService.java index e2bd7f1..6f9b578 100644 --- a/src/main/java/com/chwipoClova/interview/service/InterviewService.java +++ b/src/main/java/com/chwipoClova/interview/service/InterviewService.java @@ -16,6 +16,7 @@ import com.chwipoClova.interview.response.InterviewQaListRes; import com.chwipoClova.interview.response.InterviewRes; import com.chwipoClova.qa.request.QaAnswerInsertReq; +import com.chwipoClova.qa.request.QaGenerateReq; import com.chwipoClova.qa.request.QaQuestionInsertReq; import com.chwipoClova.qa.response.QaCountRes; import com.chwipoClova.qa.response.QaListForFeedbackRes; @@ -87,13 +88,6 @@ public InterviewInsertRes insertInterview(InterviewInsertReq interviewInsertReq, String recruitSummary = recruitInsertRes.getSummary(); String resumeSummary = resume.getSummary(); - // TODO 이력서 요약과 채용공고 요약을 이용해서 질문, AI 답변 생성 - String q1 = "질문1입니다."; - String qAi1 = "질문1 AI 답변입니다."; - - String q2 = "질문2입니다."; - String qAi2 = "질문2 AI 답변입니다."; - // 면접 저장 Interview interview = Interview.builder() .title(title) @@ -103,20 +97,8 @@ public InterviewInsertRes insertInterview(InterviewInsertReq interviewInsertReq, .build(); Interview interviewRst = interviewRepository.save(interview); - // 질문 답변 저장 - List qaQuestionInsertReqList = new ArrayList<>(); - QaQuestionInsertReq qaQuestionInsertReq1 = new QaQuestionInsertReq(); - qaQuestionInsertReq1.setInterview(interview); - qaQuestionInsertReq1.setQuestion(q1); - qaQuestionInsertReq1.setAiAnswer(qAi1); - qaQuestionInsertReqList.add(qaQuestionInsertReq1); - - QaQuestionInsertReq qaQuestionInsertReq2 = new QaQuestionInsertReq(); - qaQuestionInsertReq2.setInterview(interview); - qaQuestionInsertReq2.setQuestion(q2); - qaQuestionInsertReq2.setAiAnswer(qAi2); - qaQuestionInsertReqList.add(qaQuestionInsertReq2); - List questionData = qaService.insertQaQuestionList(qaQuestionInsertReqList); + // TODO 이력서 요약과 채용공고 요약을 이용해서 질문, AI 답변 생성 + List questionData = qaService.insertQa(interviewRst); return InterviewInsertRes.builder() .interviewId(interviewRst.getInterviewId()) @@ -300,4 +282,9 @@ public CommonResponse deleteInterview(InterviewDeleteReq interviewDeleteReq) { interviewRepository.delete(interview); return new CommonResponse<>(MessageCode.OK.getCode(), null, MessageCode.OK.getMessage()); } + + public CommonResponse generateQa(QaGenerateReq qaGenerateReq) throws IOException { + qaService.generateQa(qaGenerateReq); + return new CommonResponse<>(MessageCode.OK.getCode(), null, MessageCode.OK.getMessage()); + } } diff --git a/src/main/java/com/chwipoClova/qa/request/QaGenerateReq.java b/src/main/java/com/chwipoClova/qa/request/QaGenerateReq.java new file mode 100644 index 0000000..53ce537 --- /dev/null +++ b/src/main/java/com/chwipoClova/qa/request/QaGenerateReq.java @@ -0,0 +1,13 @@ +package com.chwipoClova.qa.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class QaGenerateReq { + @Schema(description = "유저 ID", example = "1", name = "userId") + private Long userId; + + @Schema(description = "면접 ID", example = "1", name = "interviewId") + private Long interviewId; +} diff --git a/src/main/java/com/chwipoClova/qa/response/QaQuestionInsertRes.java b/src/main/java/com/chwipoClova/qa/response/QaQuestionInsertRes.java index efeff28..9141d11 100644 --- a/src/main/java/com/chwipoClova/qa/response/QaQuestionInsertRes.java +++ b/src/main/java/com/chwipoClova/qa/response/QaQuestionInsertRes.java @@ -19,9 +19,6 @@ public class QaQuestionInsertRes { @Schema(description = "질문", example = "질문1", name = "question") private String question; - @Schema(description = "AI 답변", example = "AI답변1", name = "aiAnswer") - private String aiAnswer; - @Schema(description = "등록일", example = "2023-12-09T10:13:17.838+00:00", name = "regDate") private Date regDate; diff --git a/src/main/java/com/chwipoClova/qa/service/QaService.java b/src/main/java/com/chwipoClova/qa/service/QaService.java index 7b5a145..ce89a12 100644 --- a/src/main/java/com/chwipoClova/qa/service/QaService.java +++ b/src/main/java/com/chwipoClova/qa/service/QaService.java @@ -14,11 +14,13 @@ import com.chwipoClova.qa.repository.QaRepository; import com.chwipoClova.qa.request.QaAnswerDataInsertReq; import com.chwipoClova.qa.request.QaAnswerInsertReq; +import com.chwipoClova.qa.request.QaGenerateReq; import com.chwipoClova.qa.request.QaQuestionInsertReq; import com.chwipoClova.qa.response.QaCountRes; import com.chwipoClova.qa.response.QaListForFeedbackRes; import com.chwipoClova.qa.response.QaListRes; import com.chwipoClova.qa.response.QaQuestionInsertRes; +import com.chwipoClova.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -26,6 +28,9 @@ import org.springframework.transaction.annotation.Transactional; import java.io.IOException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -43,6 +48,8 @@ public class QaService { private final FeedbackService feedbackService; + private final UserRepository userRepository; + @Transactional public List insertQaQuestionList(List qaQuestionInsertReqList) throws IOException { List qaList = new ArrayList<>(); @@ -62,7 +69,6 @@ public List insertQaQuestionList(List QaQuestionInsertRes qaQuestionInsertRes = QaQuestionInsertRes.builder() .qaId(qa.getQaId()) .question(qa.getQuestion()) - .aiAnswer(qa.getAiAnswer()) .interviewId(qa.getInterview().getInterviewId()) .regDate(qa.getRegDate()) .modifyDate(qa.getModifyDate()) @@ -207,4 +213,53 @@ public void initQa(Long interviewId) { public void deleteQa(Long interviewId) { qaRepository.deleteByInterviewInterviewId(interviewId); } + + public void generateQa(QaGenerateReq qaGenerateReq) throws IOException { + Long interviewId = qaGenerateReq.getInterviewId(); + Long userId = qaGenerateReq.getUserId(); + + userRepository.findById(userId).orElseThrow(() -> new CommonException(ExceptionCode.USER_NULL.getMessage(), ExceptionCode.USER_NULL.getCode())); + Interview interview = interviewRepository.findByUserUserIdAndInterviewId(userId, interviewId).orElseThrow(() -> new CommonException(ExceptionCode.INTERVIEW_NULL.getMessage(), ExceptionCode.INTERVIEW_NULL.getCode())); + Integer status = interview.getStatus(); + + if (status != 0) { + throw new CommonException(ExceptionCode.INTERVIEW_COMPLETE.getMessage(), ExceptionCode.INTERVIEW_COMPLETE.getCode()); + } + + List qaList = qaRepository.findByInterviewInterviewIdOrderByQaId(interviewId); + + // 피드백 데이터가 있는지 확인 있으면 오류 발생 + qaList.stream().forEach(qa -> { + int feedbackSize = feedbackService.selectFeedbackList(qa.getQaId()).size(); + if (feedbackSize > 0) { + throw new CommonException(ExceptionCode.FEEDBACK_NOT_NULL.getMessage(), ExceptionCode.FEEDBACK_NOT_NULL.getCode()); + } + }); + + // 기존 질문 전부 삭제 + qaRepository.deleteAll(qaList); + + // 새로운 질문 생성 + insertQa(interview); + } + + public List insertQa(Interview interviewRst) throws IOException { + String time = LocalDateTime.now().format(DateTimeFormatter.ISO_TIME); + String q1 = "질문1입니다." + time; + + String q2 = "질문2입니다." + time; + + // 질문 답변 저장 + List qaQuestionInsertReqList = new ArrayList<>(); + QaQuestionInsertReq qaQuestionInsertReq1 = new QaQuestionInsertReq(); + qaQuestionInsertReq1.setInterview(interviewRst); + qaQuestionInsertReq1.setQuestion(q1); + qaQuestionInsertReqList.add(qaQuestionInsertReq1); + + QaQuestionInsertReq qaQuestionInsertReq2 = new QaQuestionInsertReq(); + qaQuestionInsertReq2.setInterview(interviewRst); + qaQuestionInsertReq2.setQuestion(q2); + qaQuestionInsertReqList.add(qaQuestionInsertReq2); + return insertQaQuestionList(qaQuestionInsertReqList); + } }