From 3d7601861b2eb146452157332dab3470b5d5328d Mon Sep 17 00:00:00 2001 From: JaehongDev Date: Tue, 9 Jul 2024 01:07:59 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=B0=B8=EA=B3=A0=20=EB=A7=81?= =?UTF-8?q?=ED=81=AC=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/InterviewSubmitCommand.java | 3 +- .../core/interview/entity/AIFeedback.java | 11 ++++++- .../payload/InterviewSubmitRequest.java | 6 ++-- .../payload/TailQuestionSubmitRequest.java | 6 ++-- .../converter/ReferenceLinksConverter.java | 29 +++++++++++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 backend/src/main/java/in/backend/global/converter/ReferenceLinksConverter.java diff --git a/backend/src/main/java/in/backend/core/interview/application/InterviewSubmitCommand.java b/backend/src/main/java/in/backend/core/interview/application/InterviewSubmitCommand.java index cff7c89..4a8ad14 100644 --- a/backend/src/main/java/in/backend/core/interview/application/InterviewSubmitCommand.java +++ b/backend/src/main/java/in/backend/core/interview/application/InterviewSubmitCommand.java @@ -1,6 +1,7 @@ package in.backend.core.interview.application; import in.backend.core.question.entity.AnswerState; +import java.util.List; import lombok.Builder; @Builder @@ -8,7 +9,6 @@ public record InterviewSubmitCommand( Long interviewId, Long interviewQuestionId, int currentIndex, - AnswerState answerState, FeedbackInfo feedback, AnswerInfo answer @@ -27,6 +27,7 @@ public record AnswerInfo( public record FeedbackInfo( String aiFeedback, String tailQuestion, + List referenceLinks, int score ) { } diff --git a/backend/src/main/java/in/backend/core/interview/entity/AIFeedback.java b/backend/src/main/java/in/backend/core/interview/entity/AIFeedback.java index 16ee726..ccab4d0 100644 --- a/backend/src/main/java/in/backend/core/interview/entity/AIFeedback.java +++ b/backend/src/main/java/in/backend/core/interview/entity/AIFeedback.java @@ -2,8 +2,11 @@ import in.backend.core.interview.application.InterviewSubmitCommand.FeedbackInfo; +import in.backend.global.converter.ReferenceLinksConverter; import jakarta.persistence.Column; +import jakarta.persistence.Convert; import jakarta.persistence.Embeddable; +import java.util.List; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -21,11 +24,17 @@ public class AIFeedback { private int score; + @Column(length = 1000) + @Convert(converter = ReferenceLinksConverter.class) + private List referenceLinks; + + @Builder(access = AccessLevel.PROTECTED) - protected AIFeedback(String tailQuestion, String feedbackContent, int score) { + protected AIFeedback(String tailQuestion, String feedbackContent, int score, List referenceLinks) { this.tailQuestion = tailQuestion; this.feedbackContent = feedbackContent; this.score = score; + this.referenceLinks = referenceLinks; } public static AIFeedback empty() { diff --git a/backend/src/main/java/in/backend/core/interview/presentation/payload/InterviewSubmitRequest.java b/backend/src/main/java/in/backend/core/interview/presentation/payload/InterviewSubmitRequest.java index 396c436..ed7c0f6 100644 --- a/backend/src/main/java/in/backend/core/interview/presentation/payload/InterviewSubmitRequest.java +++ b/backend/src/main/java/in/backend/core/interview/presentation/payload/InterviewSubmitRequest.java @@ -4,6 +4,7 @@ import in.backend.core.interview.application.InterviewSubmitCommand.AnswerInfo; import in.backend.core.interview.application.InterviewSubmitCommand.FeedbackInfo; import in.backend.core.question.entity.AnswerState; +import java.util.List; import lombok.Builder; import lombok.extern.slf4j.Slf4j; @@ -18,13 +19,14 @@ public record InterviewSubmitRequest( String tailQuestion, Integer timeToAnswer, String answerContent, - Integer score + Integer score, + List referenceLinks ) { public InterviewSubmitCommand to() { - log.info("{}", this); var feedback = FeedbackInfo.builder() .aiFeedback(aiFeedback) .tailQuestion(tailQuestion) + .referenceLinks(referenceLinks) .score(score) .build(); diff --git a/backend/src/main/java/in/backend/core/question/presentation/payload/TailQuestionSubmitRequest.java b/backend/src/main/java/in/backend/core/question/presentation/payload/TailQuestionSubmitRequest.java index 460c370..33023fd 100644 --- a/backend/src/main/java/in/backend/core/question/presentation/payload/TailQuestionSubmitRequest.java +++ b/backend/src/main/java/in/backend/core/question/presentation/payload/TailQuestionSubmitRequest.java @@ -5,6 +5,7 @@ import in.backend.core.question.application.TailQuestionSubmitCommand; import in.backend.core.question.entity.AnswerState; import jakarta.validation.constraints.NotNull; +import java.util.List; import lombok.Builder; @Builder @@ -16,15 +17,16 @@ public record TailQuestionSubmitRequest( @NotNull String tailQuestion, @NotNull Integer timeToAnswer, @NotNull String answerContent, - @NotNull Integer score + @NotNull Integer score, + List referenceLinks ) { public TailQuestionSubmitCommand to() { - var feedback = FeedbackInfo.builder() .aiFeedback(aiFeedback) .tailQuestion(tailQuestion) .score(score) + .referenceLinks(referenceLinks) .build(); var answer = AnswerInfo.builder() diff --git a/backend/src/main/java/in/backend/global/converter/ReferenceLinksConverter.java b/backend/src/main/java/in/backend/global/converter/ReferenceLinksConverter.java new file mode 100644 index 0000000..2477ad3 --- /dev/null +++ b/backend/src/main/java/in/backend/global/converter/ReferenceLinksConverter.java @@ -0,0 +1,29 @@ +package in.backend.global.converter; + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.apache.logging.log4j.util.Strings; + +@Converter +public class ReferenceLinksConverter implements AttributeConverter, String> { + + private static final char DELIMITER = ','; + + @Override + public String convertToDatabaseColumn(List strings) { + return Strings.join(strings, DELIMITER); + } + + @Override + public List convertToEntityAttribute(String s) { + if (Objects.isNull(s)) { + return Collections.emptyList(); + } + return Arrays.stream(s.split(",")) + .toList(); + } +}