From dfccd65219c4fda8f03b1507208499be74554633 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 6 May 2024 23:23:46 +0900 Subject: [PATCH 01/12] =?UTF-8?q?feat:=20Debate=20Message=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/service/ClovaSummary.java | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java new file mode 100644 index 00000000..1d570111 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java @@ -0,0 +1,112 @@ +package com.rollthedice.backend.domain.debate.service; + +import com.rollthedice.backend.global.error.ErrorCode; +import com.rollthedice.backend.global.error.exception.ExternalApiException; +import net.minidev.json.JSONObject; +import org.apache.tomcat.util.json.JSONParser; +import org.apache.tomcat.util.json.ParseException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatusCode; +import org.springframework.stereotype.Service; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.LinkedHashMap; + +@Service +public class ClovaSummary { + private static final String KOREAN = "ko"; + private static final int POLITE_TONE = 2; + private static final int SUMMARY_COUNT = 4; + + private static final String API_URL = "https://naveropenapi.apigw.ntruss.com/text-summary/v1/summarize"; + + + @Value("${clova.secret-key}") + private String SECRET; + + @Value("${clova.client-id") + private String CLIENT_ID; + + public String summaryDebate(String messages) { + try { + URL url = new URL(API_URL); + HttpURLConnection connection = createRequestHeader(url); + createRequestBody(connection, messages); + + StringBuilder response = getResponse(connection); + + return parseResponse(response); + } catch (Exception e) { + throw new ExternalApiException(ErrorCode.CLOVA_API_ERROR); + } + } + + private HttpURLConnection createRequestHeader(URL url) throws IOException { + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json;"); + connection.setRequestProperty("X-NCP-APIGW-API-KEY-ID", CLIENT_ID); + connection.setRequestProperty("X-NCP-APIGW-API-KEY", SECRET); + return connection; + } + + private void createRequestBody(HttpURLConnection connection, String content) throws IOException { + JSONObject document = new JSONObject(); + document.put("content", content); + + JSONObject option = new JSONObject(); + option.put("language", KOREAN); + option.put("tone", POLITE_TONE); + option.put("summaryCount", SUMMARY_COUNT); + + JSONObject requestObject = new JSONObject(); + requestObject.put("document", document); + requestObject.put("option", option); + + connection.connect(); + DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); + outputStream.write(requestObject.toString().getBytes(StandardCharsets.UTF_8)); + outputStream.flush(); + outputStream.close(); + } + + + private StringBuilder getResponse(HttpURLConnection connection) throws IOException { + BufferedReader reader = checkResponse(connection); + String line; + StringBuilder response = new StringBuilder(); + while ((line = reader.readLine()) != null) { + response.append(line); + } + reader.close(); + return response; + } + + private BufferedReader checkResponse(HttpURLConnection connection) throws IOException { + int responseCode = connection.getResponseCode(); + + return getResponseResult(connection, responseCode); + } + + private BufferedReader getResponseResult(HttpURLConnection connection, int responseCode) throws IOException { + if (HttpStatusCode.valueOf(responseCode).is2xxSuccessful()) { + return new BufferedReader(new InputStreamReader(connection.getInputStream())); + } + return new BufferedReader(new InputStreamReader(connection.getErrorStream())); + } + + + private String parseResponse(StringBuilder response) throws ParseException { + JSONParser parser = new JSONParser(response.toString()); + LinkedHashMap hashMap = (LinkedHashMap) parser.parse(); + JSONObject parsed = new JSONObject(hashMap); + String summary = parsed.get("summary").toString(); + + } +} From bc0e1c81976eb582623eda63bcc0f53334e11464 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 6 May 2024 23:24:34 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20summaryDebateMessage=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EB=B0=8F=20=EA=B2=B0=EA=B3=BC=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/DebateSummaryResponse.java | 15 +++++++++++++++ .../debate/service/DebateMessageService.java | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java new file mode 100644 index 00000000..b5009d46 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java @@ -0,0 +1,15 @@ +package com.rollthedice.backend.domain.debate.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DebateSummaryResponse { + Long roomId; + String summary; +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index 269bde39..6682e66e 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -2,6 +2,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest; import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse; +import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; import com.rollthedice.backend.domain.debate.entity.DebateRoom; import com.rollthedice.backend.domain.debate.exception.DebateRoomNotFoundException; import com.rollthedice.backend.domain.debate.mapper.DebateMessageMapper; @@ -20,6 +21,7 @@ public class DebateMessageService { private final DebateRoomRepository debateRoomRepository; private final DebateMessageRepository debateMessageRepository; private final DebateMessageMapper debateMessageMapper; + private final ClovaSummary clovaSummary; @Transactional public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest request) { @@ -44,4 +46,15 @@ public List getDebateMessages(Long roomId) { .stream().map(debateMessageMapper::toResponse) .collect(Collectors.toList()); } + + public DebateSummaryResponse summaryDebateMessages(final Long roomId) { + StringBuilder sb = new StringBuilder(); + getDebateMessages(roomId).stream().map(message -> sb.append(message.getMessage())); + return DebateSummaryResponse.builder() + .roomId(roomId) + .summary(clovaSummary.summaryDebate(sb.toString())) + .build(); + } + + } From f069015a92fad7c40c8a37738f5c04a898f8e0a8 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 6 May 2024 23:40:21 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20getSummarizedDebate=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/api/DebateApi.java | 18 ++++++++++++++++++ .../domain/debate/api/DebateController.java | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java index 548f4f4c..4a1f3928 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java @@ -4,6 +4,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; +import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; @@ -104,6 +105,23 @@ List getDebateMessages( Long roomId ); + @Operation( + summary = "토론 요약", + description = "토론방의 토론 메세지들을 요약합니다.", + security = {@SecurityRequirement(name = "access_token")}, + tags = {"debate_message"} + ) + @ApiResponse( + responseCode = "200", + description = "OK" + ) + DebateSummaryResponse getSummarizedDebate( + @Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) + Long roomId + ); + + + } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java index 1191ca7c..65955bdd 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java @@ -4,6 +4,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; +import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; import com.rollthedice.backend.domain.debate.service.DebateMessageService; import com.rollthedice.backend.domain.debate.service.DebateRoomService; import jakarta.validation.Valid; @@ -62,4 +63,11 @@ public void saveAIDebateMessage(@PathVariable final Long roomId, @RequestBody fi public List getDebateMessages(@PathVariable final Long roomId) { return debateMessageService.getDebateMessages(roomId); } + + @ResponseStatus(HttpStatus.OK) + @GetMapping("/{roomId}") + @Override + public DebateSummaryResponse getSummarizedDebate(@PathVariable final Long roomId) { + return debateMessageService.summaryDebateMessages(roomId); + } } From 845d337b06b4ca0a981083d6d71df26411232f83 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 6 May 2024 23:40:38 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat:=20response=20dto=20=EC=84=A4?= =?UTF-8?q?=EB=AA=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/dto/response/DebateSummaryResponse.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java index b5009d46..a3a46c11 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java @@ -1,5 +1,6 @@ package com.rollthedice.backend.domain.debate.dto.response; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -11,5 +12,7 @@ @AllArgsConstructor public class DebateSummaryResponse { Long roomId; + + @Schema(description = "4문장의 요약된 토론 내용") String summary; } From d088c04bd09082c3d2480157c931db3392dc1fe8 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 7 May 2024 17:43:16 +0900 Subject: [PATCH 05/12] =?UTF-8?q?fix:=20clova=20connection=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/service/ClovaSummary.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java index 1d570111..6f1b71d7 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java @@ -2,6 +2,7 @@ import com.rollthedice.backend.global.error.ErrorCode; import com.rollthedice.backend.global.error.exception.ExternalApiException; +import lombok.extern.slf4j.Slf4j; import net.minidev.json.JSONObject; import org.apache.tomcat.util.json.JSONParser; import org.apache.tomcat.util.json.ParseException; @@ -18,6 +19,7 @@ import java.nio.charset.StandardCharsets; import java.util.LinkedHashMap; +@Slf4j @Service public class ClovaSummary { private static final String KOREAN = "ko"; @@ -30,25 +32,30 @@ public class ClovaSummary { @Value("${clova.secret-key}") private String SECRET; - @Value("${clova.client-id") + @Value("${clova.client-id}") private String CLIENT_ID; - + public String summaryDebate(String messages) { + log.info("요약할 메세지: {}" ,messages); try { URL url = new URL(API_URL); HttpURLConnection connection = createRequestHeader(url); createRequestBody(connection, messages); + log.info("정상1"); StringBuilder response = getResponse(connection); - + log.info("정상2"); return parseResponse(response); } catch (Exception e) { + e.printStackTrace(); throw new ExternalApiException(ErrorCode.CLOVA_API_ERROR); } } private HttpURLConnection createRequestHeader(URL url) throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json;"); connection.setRequestProperty("X-NCP-APIGW-API-KEY-ID", CLIENT_ID); @@ -98,6 +105,7 @@ private BufferedReader getResponseResult(HttpURLConnection connection, int respo if (HttpStatusCode.valueOf(responseCode).is2xxSuccessful()) { return new BufferedReader(new InputStreamReader(connection.getInputStream())); } + log.error("Clova Api error response code: {}", responseCode); return new BufferedReader(new InputStreamReader(connection.getErrorStream())); } @@ -106,7 +114,6 @@ private String parseResponse(StringBuilder response) throws ParseException { JSONParser parser = new JSONParser(response.toString()); LinkedHashMap hashMap = (LinkedHashMap) parser.parse(); JSONObject parsed = new JSONObject(hashMap); - String summary = parsed.get("summary").toString(); - + return parsed.get("summary").toString(); } } From cbca7e69ba55d3a9fc03bda6eaf5c6a7af1c66e4 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 7 May 2024 17:43:54 +0900 Subject: [PATCH 06/12] refactor: stream().map() -> forEach() --- .../backend/domain/debate/service/DebateMessageService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index 6682e66e..ea7341e4 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -9,12 +9,14 @@ import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; import com.rollthedice.backend.domain.news.repository.DebateMessageRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.stream.Collectors; +@Slf4j @RequiredArgsConstructor @Service public class DebateMessageService { @@ -49,7 +51,7 @@ public List getDebateMessages(Long roomId) { public DebateSummaryResponse summaryDebateMessages(final Long roomId) { StringBuilder sb = new StringBuilder(); - getDebateMessages(roomId).stream().map(message -> sb.append(message.getMessage())); + getDebateMessages(roomId).forEach(message -> sb.append(message.getMessage())); return DebateSummaryResponse.builder() .roomId(roomId) .summary(clovaSummary.summaryDebate(sb.toString())) From c44234b90d4ce0eb1a9fdeb6a7147b1f4045c511 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 7 May 2024 17:44:16 +0900 Subject: [PATCH 07/12] =?UTF-8?q?chore:=20test=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/core/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/core/build.gradle b/backend/core/build.gradle index 4d2ceb6e..4ec647e5 100644 --- a/backend/core/build.gradle +++ b/backend/core/build.gradle @@ -45,8 +45,12 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' + testAnnotationProcessor "org.mapstruct:mapstruct-processor:1.5.5.Final" testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' + testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' } tasks.named('bootBuildImage') { From 87764a58bc30a70d962762bc956eba8bd72bf92f Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 7 May 2024 17:46:40 +0900 Subject: [PATCH 08/12] =?UTF-8?q?fix:=20=EC=9A=94=EC=95=BD=20api=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=A4=91=EB=B3=B5=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rollthedice/backend/domain/debate/api/DebateController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java index 65955bdd..5540319f 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java @@ -65,7 +65,7 @@ public List getDebateMessages(@PathVariable final Long ro } @ResponseStatus(HttpStatus.OK) - @GetMapping("/{roomId}") + @GetMapping("/summary/{roomId}") @Override public DebateSummaryResponse getSummarizedDebate(@PathVariable final Long roomId) { return debateMessageService.summaryDebateMessages(roomId); From 04311fbe82b43002bef9c5840b21439cb42ae10c Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 8 May 2024 02:46:18 +0900 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20DebateRoom=20isClosed=20&=20summa?= =?UTF-8?q?ry=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/entity/DebateRoom.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java index 1d2603f8..566463e4 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java @@ -7,6 +7,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.ColumnDefault; @Getter @Entity @@ -17,6 +18,10 @@ public class DebateRoom extends BaseTimeEntity { private Long id; private String topic; + private String summary; + + @ColumnDefault("false") + private boolean isClosed; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") @@ -27,4 +32,12 @@ public DebateRoom(Member member, String topic) { this.member = member; this.topic = topic; } + + public void closeDebate() { + this.isClosed = true; + } + + public void updateSummary(String summary) { + this.summary = summary; + } } From e5e024ecef06e563b8a25f5d1394ef71a75884ed Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 8 May 2024 02:59:36 +0900 Subject: [PATCH 10/12] =?UTF-8?q?refactor:=20=ED=86=A0=EB=A1=A0=20?= =?UTF-8?q?=EC=9A=94=EC=95=BD=20DebateRoomService=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/api/DebateController.java | 2 +- .../domain/debate/service/DebateMessageService.java | 12 ------------ .../domain/debate/service/DebateRoomService.java | 12 ++++++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java index 5540319f..59b1c0ba 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java @@ -68,6 +68,6 @@ public List getDebateMessages(@PathVariable final Long ro @GetMapping("/summary/{roomId}") @Override public DebateSummaryResponse getSummarizedDebate(@PathVariable final Long roomId) { - return debateMessageService.summaryDebateMessages(roomId); + return debateRoomService.summaryDebateMessages(roomId); } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index ea7341e4..8680945f 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -23,7 +23,6 @@ public class DebateMessageService { private final DebateRoomRepository debateRoomRepository; private final DebateMessageRepository debateMessageRepository; private final DebateMessageMapper debateMessageMapper; - private final ClovaSummary clovaSummary; @Transactional public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest request) { @@ -48,15 +47,4 @@ public List getDebateMessages(Long roomId) { .stream().map(debateMessageMapper::toResponse) .collect(Collectors.toList()); } - - public DebateSummaryResponse summaryDebateMessages(final Long roomId) { - StringBuilder sb = new StringBuilder(); - getDebateMessages(roomId).forEach(message -> sb.append(message.getMessage())); - return DebateSummaryResponse.builder() - .roomId(roomId) - .summary(clovaSummary.summaryDebate(sb.toString())) - .build(); - } - - } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java index ba084130..5b112b20 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -2,6 +2,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; +import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; import com.rollthedice.backend.domain.debate.mapper.DebateRoomMapper; import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; import com.rollthedice.backend.domain.member.entity.Member; @@ -21,6 +22,7 @@ public class DebateRoomService { private final DebateRoomMapper debateRoomMapper; private final DebateRoomRepository debateRoomRepository; private final DebateMessageService debateMessageService; + private final ClovaSummary clovaSummary; @Transactional @@ -42,4 +44,14 @@ public void deleteDebateRoom(Long roomId) { debateMessageService.deleteAllDebateMessages(roomId); debateRoomRepository.deleteById(roomId); } + + @Transactional + public DebateSummaryResponse summaryDebateMessages(final Long roomId) { + StringBuilder sb = new StringBuilder(); + debateMessageService.getDebateMessages(roomId).forEach(message -> sb.append(message.getMessage())); + return DebateSummaryResponse.builder() + .roomId(roomId) + .summary(clovaSummary.summaryDebate(sb.toString())) + .build(); + } } From 6dc5beb7ec9a891f0cbaf02c96f3ca1d3455e394 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 8 May 2024 03:11:10 +0900 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20summary=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/service/DebateMessageService.java | 7 +++++++ .../domain/debate/service/DebateRoomService.java | 13 +++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index 8680945f..032ee552 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -47,4 +47,11 @@ public List getDebateMessages(Long roomId) { .stream().map(debateMessageMapper::toResponse) .collect(Collectors.toList()); } + + public StringBuilder getAllMessages(Long roomId) { + StringBuilder sb = new StringBuilder(); + getDebateMessages(roomId) + .forEach(message -> sb.append(message.getMessage())); + return sb; + } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java index 5b112b20..fb94b037 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -3,6 +3,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; +import com.rollthedice.backend.domain.debate.exception.DebateRoomNotFoundException; import com.rollthedice.backend.domain.debate.mapper.DebateRoomMapper; import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; import com.rollthedice.backend.domain.member.entity.Member; @@ -46,12 +47,16 @@ public void deleteDebateRoom(Long roomId) { } @Transactional - public DebateSummaryResponse summaryDebateMessages(final Long roomId) { - StringBuilder sb = new StringBuilder(); - debateMessageService.getDebateMessages(roomId).forEach(message -> sb.append(message.getMessage())); + public DebateSummaryResponse summaryDebate(final Long roomId) { + StringBuilder sb = debateMessageService.getAllMessages(roomId); + String summary = clovaSummary.summaryDebate(sb.toString()); + debateRoomRepository.findById(roomId).orElseThrow(DebateRoomNotFoundException::new) + .updateSummary(summary); + return DebateSummaryResponse.builder() .roomId(roomId) - .summary(clovaSummary.summaryDebate(sb.toString())) + .summary(summary) .build(); } + } From 20e3d19d515330b79a9299ac59947433fb485cb6 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 8 May 2024 03:11:35 +0900 Subject: [PATCH 12/12] =?UTF-8?q?rename:=20summaryDebateMessages=20->=20su?= =?UTF-8?q?mmaryDebate=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rollthedice/backend/domain/debate/api/DebateController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java index 59b1c0ba..f6c0a530 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java @@ -68,6 +68,6 @@ public List getDebateMessages(@PathVariable final Long ro @GetMapping("/summary/{roomId}") @Override public DebateSummaryResponse getSummarizedDebate(@PathVariable final Long roomId) { - return debateRoomService.summaryDebateMessages(roomId); + return debateRoomService.summaryDebate(roomId); } }