Skip to content

Commit

Permalink
Merge pull request #27 from potenday-project/develop
Browse files Browse the repository at this point in the history
질문 재생성 추가
  • Loading branch information
HwangHoYoon authored Dec 15, 2023
2 parents d295604 + a4f3393 commit 7981057
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public enum ExceptionCode {

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

FEEDBACK_NOT_NULL("891", "피드백 데이터가 있습니다."),

TOKEN_NULL("950", "토큰정보가 올바르지 않습니다."),

API_NULL("980", "API 결과 NULL"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,7 +71,7 @@ public List<InterviewListRes> 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")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -103,20 +97,8 @@ public InterviewInsertRes insertInterview(InterviewInsertReq interviewInsertReq,
.build();
Interview interviewRst = interviewRepository.save(interview);

// 질문 답변 저장
List<QaQuestionInsertReq> 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<QaQuestionInsertRes> questionData = qaService.insertQaQuestionList(qaQuestionInsertReqList);
// TODO 이력서 요약과 채용공고 요약을 이용해서 질문, AI 답변 생성
List<QaQuestionInsertRes> questionData = qaService.insertQa(interviewRst);

return InterviewInsertRes.builder()
.interviewId(interviewRst.getInterviewId())
Expand Down Expand Up @@ -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());
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/chwipoClova/qa/request/QaGenerateReq.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
57 changes: 56 additions & 1 deletion src/main/java/com/chwipoClova/qa/service/QaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@
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;
import org.springframework.stereotype.Service;
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;
Expand All @@ -43,6 +48,8 @@ public class QaService {

private final FeedbackService feedbackService;

private final UserRepository userRepository;

@Transactional
public List<QaQuestionInsertRes> insertQaQuestionList(List<QaQuestionInsertReq> qaQuestionInsertReqList) throws IOException {
List<Qa> qaList = new ArrayList<>();
Expand All @@ -62,7 +69,6 @@ public List<QaQuestionInsertRes> insertQaQuestionList(List<QaQuestionInsertReq>
QaQuestionInsertRes qaQuestionInsertRes = QaQuestionInsertRes.builder()
.qaId(qa.getQaId())
.question(qa.getQuestion())
.aiAnswer(qa.getAiAnswer())
.interviewId(qa.getInterview().getInterviewId())
.regDate(qa.getRegDate())
.modifyDate(qa.getModifyDate())
Expand Down Expand Up @@ -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<Qa> 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<QaQuestionInsertRes> insertQa(Interview interviewRst) throws IOException {
String time = LocalDateTime.now().format(DateTimeFormatter.ISO_TIME);
String q1 = "질문1입니다." + time;

String q2 = "질문2입니다." + time;

// 질문 답변 저장
List<QaQuestionInsertReq> 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);
}
}

0 comments on commit 7981057

Please sign in to comment.