@@ -25,11 +25,18 @@ public class SummaryService {
2525 private final SummaryMapper summaryMapper ;
2626 private final ObjectMapper objectMapper ;
2727
28+ @ Transactional
29+
2830 public void createSummary (
2931 Long counselingResultId ,
3032 Long userId ,
3133 String counselingText
3234 ) {
35+ if (userId == null ) {
36+ throw new CustomException (ErrorCode .INVALID_OAUTH_PROVIDER );
37+
38+ }
39+
3340 if (userId ==null ) throw new CustomException (ErrorCode .INVALID_INPUT_VALUE );
3441 summaryMapper .insertSummary (counselingResultId , userId );
3542
@@ -41,6 +48,10 @@ public void createSummary(
4148 geminiSummaryService .summarize (counselingText );
4249
4350 if (gemini .getKeywords () == null || gemini .getKeywords ().isEmpty ()
51+ || gemini .getPoints () == null || gemini .getPoints ().isEmpty ()) {
52+ summaryMapper .updateStatus (summaryId , "FAIL" );
53+ throw new RuntimeException ("Gemini 결과 누락" );
54+ }
4455 || gemini .getPoints () == null || gemini .getPoints ().isEmpty ()){
4556 summaryMapper .updateStatus (summaryId , "FAIL" );
4657 throw new RuntimeException ("Gemini 결과 누락" );
@@ -53,20 +64,114 @@ public void createSummary(
5364 summaryId ,
5465 gemini .getTitle (),
5566 gemini .getSubject (),
56- objectMapper .writeValueAsString (keywords ),
57- objectMapper .writeValueAsString (points )
67+ objectMapper .writeValueAsString (gemini . getKeywords () ),
68+ objectMapper .writeValueAsString (gemini . getPoints () )
5869 );
5970
6071 summaryMapper .updateStatus (summaryId , "SUCCESS" );
6172
6273 new SummaryResponse (
6374 gemini .getTitle (),
6475 gemini .getSubject (),
76+ gemini .getKeywords (),
77+ gemini .getPoints ()
78+ );
79+
80+ } catch (Exception e ) {
81+ summaryMapper .updateStatus (summaryId , "FAIL" );
82+ throw new IllegalStateException (e );
83+ }
84+ }
85+
86+ @ Transactional (readOnly = true )
87+ public List <SummaryListResponse > getMySummaries (Long userId ) {
88+ return summaryMapper .findByUserId (userId ).stream ()
89+ .map (summary -> {
90+ try {
91+ List <String > keywords =
92+ summary .getKeywords () != null
93+ ? objectMapper .readValue (
94+ summary .getKeywords (),
95+ new TypeReference <List <String >>() {})
96+ : List .of ();
97+
98+ return new SummaryListResponse (
99+ summary .getSummaryId (),
100+ summary .getTitle (),
101+ summary .getStatus (),
102+ keywords ,
103+ summary .getCreatedAt ()
104+ );
105+ } catch (Exception e ) {
106+ throw new IllegalStateException (e );
107+ }
108+ })
109+ .toList ();
110+ }
111+
112+ @ Transactional (readOnly = true )
113+ public List <SummaryListResponse > getBookmarkedSummaries (Long userId ) {
114+ return summaryMapper .findBookmarkedByUserId (userId ).stream ()
115+ .map (summary -> {
116+ try {
117+ List <String > keywords =
118+ summary .getKeywords () != null
119+ ? objectMapper .readValue (
120+ summary .getKeywords (),
121+ new TypeReference <List <String >>() {})
122+ : List .of ();
123+
124+ return new SummaryListResponse (
125+ summary .getSummaryId (),
126+ summary .getTitle (),
127+ summary .getStatus (),
128+ keywords ,
129+ summary .getCreatedAt ()
130+ );
131+ } catch (Exception e ) {
132+ throw new IllegalStateException (e );
133+ }
134+ })
135+ .toList ();
136+ }
137+
138+ @ Transactional (readOnly = true )
139+ public SummaryDetailResponse getSummaryDetail (Long summaryId ) {
140+ SummaryModel summary = summaryMapper .findById (summaryId );
141+
142+ if (summary == null ) {
143+ return null ;
144+ }
145+
146+ try {
147+ List <String > keywords =
148+ summary .getKeywords () != null
149+ ? objectMapper .readValue (
150+ summary .getKeywords (),
151+ new TypeReference <List <String >>() {})
152+ : List .of ();
153+
154+ List <String > points =
155+ summary .getPoints () != null
156+ ? objectMapper .readValue (
157+ summary .getPoints (),
158+ new TypeReference <List <String >>() {})
159+ : List .of ();
160+
161+ return new SummaryDetailResponse (
162+ summary .getSummaryId (),
163+ summary .getTitle (),
164+ summary .getSubject (),
65165 keywords ,
66- points
166+ points ,
167+ summary .getStatus (),
168+ summary .getIsBookmarked (),
169+ summary .getCreatedAt ()
67170 );
68171
69172 } catch (Exception e ) {
173+
174+
70175 summaryMapper .updateStatus (summaryId , "FAIL" );
71176 throw new IllegalStateException (e );
72177 }
@@ -133,16 +238,19 @@ public SummaryDetailResponse getSummaryDetail(Long summaryId) {
133238 );
134239
135240 } catch (Exception e ) {
241+
136242 throw new IllegalStateException (e );
137243 }
138244 }
139245
140246 @ Transactional
141247 public void toggleBookmark (Long summaryId ) {
142- Boolean isBookmarked =
143- summaryMapper .findBookmarkStatus (summaryId );
248+ Boolean isBookmarked = summaryMapper .findBookmarkStatus (summaryId );
144249
145250 if (isBookmarked == null ) {
251+
252+ throw new IllegalArgumentException ("summary not found" );
253+
146254 throw new IllegalArgumentException ();
147255 }
148256
0 commit comments