@@ -26,36 +26,27 @@ public class SummaryService {
2626 private final ObjectMapper objectMapper ;
2727
2828 @ Transactional
29-
3029 public void createSummary (
3130 Long counselingResultId ,
3231 Long userId ,
3332 String counselingText
3433 ) {
3534 if (userId == null ) {
36- throw new CustomException (ErrorCode .INVALID_OAUTH_PROVIDER );
37-
35+ throw new CustomException (ErrorCode .INVALID_INPUT_VALUE );
3836 }
3937
40- if (userId ==null ) throw new CustomException (ErrorCode .INVALID_INPUT_VALUE );
4138 summaryMapper .insertSummary (counselingResultId , userId );
4239
43- Long summaryId =
44- summaryMapper .findLatestSummaryId (userId , counselingResultId );
40+ Long summaryId = summaryMapper .findLatestSummaryId (userId , counselingResultId );
4541
4642 try {
47- GeminiSummaryResponse gemini =
48- geminiSummaryService .summarize (counselingText );
43+ GeminiSummaryResponse gemini = geminiSummaryService .summarize (counselingText );
4944
5045 if (gemini .getKeywords () == null || gemini .getKeywords ().isEmpty ()
5146 || gemini .getPoints () == null || gemini .getPoints ().isEmpty ()) {
5247 summaryMapper .updateStatus (summaryId , "FAIL" );
5348 throw new RuntimeException ("Gemini 결과 누락" );
5449 }
55- || gemini .getPoints () == null || gemini .getPoints ().isEmpty ()){
56- summaryMapper .updateStatus (summaryId , "FAIL" );
57- throw new RuntimeException ("Gemini 결과 누락" );
58- }
5950
6051 List <String > keywords = gemini .getKeywords ();
6152 List <String > points = gemini .getPoints ();
@@ -64,17 +55,18 @@ public void createSummary(
6455 summaryId ,
6556 gemini .getTitle (),
6657 gemini .getSubject (),
67- objectMapper .writeValueAsString (gemini . getKeywords () ),
68- objectMapper .writeValueAsString (gemini . getPoints () )
58+ objectMapper .writeValueAsString (keywords ),
59+ objectMapper .writeValueAsString (points )
6960 );
7061
7162 summaryMapper .updateStatus (summaryId , "SUCCESS" );
7263
64+ // 필요하면 반환형으로 바꾸거나, 로그용으로 사용
7365 new SummaryResponse (
7466 gemini .getTitle (),
7567 gemini .getSubject (),
76- gemini . getKeywords () ,
77- gemini . getPoints ()
68+ keywords ,
69+ points
7870 );
7971
8072 } catch (Exception e ) {
@@ -90,8 +82,7 @@ public List<SummaryListResponse> getMySummaries(Long userId) {
9082 try {
9183 List <String > keywords =
9284 summary .getKeywords () != null
93- ? objectMapper .readValue (
94- summary .getKeywords (),
85+ ? objectMapper .readValue (summary .getKeywords (),
9586 new TypeReference <List <String >>() {})
9687 : List .of ();
9788
@@ -116,8 +107,7 @@ public List<SummaryListResponse> getBookmarkedSummaries(Long userId) {
116107 try {
117108 List <String > keywords =
118109 summary .getKeywords () != null
119- ? objectMapper .readValue (
120- summary .getKeywords (),
110+ ? objectMapper .readValue (summary .getKeywords (),
121111 new TypeReference <List <String >>() {})
122112 : List .of ();
123113
@@ -146,15 +136,13 @@ public SummaryDetailResponse getSummaryDetail(Long summaryId) {
146136 try {
147137 List <String > keywords =
148138 summary .getKeywords () != null
149- ? objectMapper .readValue (
150- summary .getKeywords (),
139+ ? objectMapper .readValue (summary .getKeywords (),
151140 new TypeReference <List <String >>() {})
152141 : List .of ();
153142
154143 List <String > points =
155144 summary .getPoints () != null
156- ? objectMapper .readValue (
157- summary .getPoints (),
145+ ? objectMapper .readValue (summary .getPoints (),
158146 new TypeReference <List <String >>() {})
159147 : List .of ();
160148
@@ -170,75 +158,6 @@ public SummaryDetailResponse getSummaryDetail(Long summaryId) {
170158 );
171159
172160 } catch (Exception e ) {
173-
174-
175- summaryMapper .updateStatus (summaryId , "FAIL" );
176- throw new IllegalStateException (e );
177- }
178- }
179-
180- @ Transactional (readOnly = true )
181- public List <SummaryListResponse > getMySummaries (Long userId ) {
182- return summaryMapper .findByUserId (userId ).stream ()
183- .map (summary -> {
184- try {
185- List <String > keywords =
186- summary .getKeywords () != null
187- ? objectMapper .readValue (
188- summary .getKeywords (),
189- new TypeReference <List <String >>() {})
190- : List .of ();
191-
192- return new SummaryListResponse (
193- summary .getSummaryId (),
194- summary .getTitle (),
195- summary .getStatus (),
196- keywords ,
197- summary .getCreatedAt ()
198- );
199- } catch (Exception e ) {
200- throw new IllegalStateException (e );
201- }
202- })
203- .toList ();
204- }
205-
206- @ Transactional (readOnly = true )
207- public SummaryDetailResponse getSummaryDetail (Long summaryId ) {
208- SummaryModel summary = summaryMapper .findById (summaryId );
209-
210- if (summary == null ) {
211- return null ;
212- }
213-
214- try {
215- List <String > keywords =
216- summary .getKeywords () != null
217- ? objectMapper .readValue (
218- summary .getKeywords (),
219- new TypeReference <List <String >>() {})
220- : List .of ();
221-
222- List <String > points =
223- summary .getPoints () != null
224- ? objectMapper .readValue (
225- summary .getPoints (),
226- new TypeReference <List <String >>() {})
227- : List .of ();
228-
229- return new SummaryDetailResponse (
230- summary .getSummaryId (),
231- summary .getTitle (),
232- summary .getSubject (),
233- keywords ,
234- points ,
235- summary .getStatus (),
236- summary .getIsBookmarked (),
237- summary .getCreatedAt ()
238- );
239-
240- } catch (Exception e ) {
241-
242161 throw new IllegalStateException (e );
243162 }
244163 }
@@ -248,10 +167,7 @@ public void toggleBookmark(Long summaryId) {
248167 Boolean isBookmarked = summaryMapper .findBookmarkStatus (summaryId );
249168
250169 if (isBookmarked == null ) {
251-
252170 throw new IllegalArgumentException ("summary not found" );
253-
254- throw new IllegalArgumentException ();
255171 }
256172
257173 summaryMapper .updateBookmark (summaryId , !isBookmarked );
0 commit comments