11package com .ureca .unity .domain .summary .service ;
22
3+ import com .fasterxml .jackson .core .type .TypeReference ;
34import com .fasterxml .jackson .databind .ObjectMapper ;
45import com .ureca .unity .domain .gemini .dto .GeminiSummaryResponse ;
56import com .ureca .unity .domain .gemini .service .GeminiSummaryService ;
7+ import com .ureca .unity .domain .summary .dto .response .SummaryDetailResponse ;
8+ import com .ureca .unity .domain .summary .dto .response .SummaryListResponse ;
69import com .ureca .unity .domain .summary .dto .response .SummaryResponse ;
710import com .ureca .unity .domain .summary .mapper .SummaryMapper ;
11+ import com .ureca .unity .domain .summary .model .SummaryModel ;
812import lombok .RequiredArgsConstructor ;
913import org .springframework .stereotype .Service ;
1014import org .springframework .transaction .annotation .Transactional ;
@@ -26,7 +30,6 @@ public SummaryResponse createSummary(
2630 Long userId ,
2731 String counselingText
2832 ) {
29- // 1. summary 먼저 생성 (loading)
3033 summaryMapper .insertSummary (counselingResultId , userId );
3134
3235 Long summaryId =
@@ -54,6 +57,8 @@ public SummaryResponse createSummary(
5457 objectMapper .writeValueAsString (points )
5558 );
5659
60+ summaryMapper .updateStatus (summaryId , "SUCCESS" );
61+
5762 return new SummaryResponse (
5863 gemini .getTitle (),
5964 gemini .getSubject (),
@@ -62,8 +67,73 @@ public SummaryResponse createSummary(
6267 );
6368
6469 } catch (Exception e ) {
65- summaryMapper .updateStatus (summaryId , "fail" );
66- throw new IllegalStateException ("요약 생성 실패" , e );
70+ summaryMapper .updateStatus (summaryId , "FAIL" );
71+ throw new IllegalStateException (e );
72+ }
73+ }
74+
75+ @ Transactional (readOnly = true )
76+ public List <SummaryListResponse > getMySummaries (Long userId ) {
77+ return summaryMapper .findByUserId (userId ).stream ()
78+ .map (summary -> {
79+ try {
80+ List <String > keywords =
81+ summary .getKeywords () != null
82+ ? objectMapper .readValue (
83+ summary .getKeywords (),
84+ new TypeReference <List <String >>() {})
85+ : List .of ();
86+
87+ return new SummaryListResponse (
88+ summary .getSummaryId (),
89+ summary .getTitle (),
90+ summary .getStatus (),
91+ keywords ,
92+ summary .getCreatedAt ()
93+ );
94+ } catch (Exception e ) {
95+ throw new IllegalStateException (e );
96+ }
97+ })
98+ .toList ();
99+ }
100+
101+ @ Transactional (readOnly = true )
102+ public SummaryDetailResponse getSummaryDetail (Long summaryId ) {
103+ SummaryModel summary = summaryMapper .findById (summaryId );
104+
105+ if (summary == null ) {
106+ return null ;
107+ }
108+
109+ try {
110+ List <String > keywords =
111+ summary .getKeywords () != null
112+ ? objectMapper .readValue (
113+ summary .getKeywords (),
114+ new TypeReference <List <String >>() {})
115+ : List .of ();
116+
117+ List <String > points =
118+ summary .getPoints () != null
119+ ? objectMapper .readValue (
120+ summary .getPoints (),
121+ new TypeReference <List <String >>() {})
122+ : List .of ();
123+
124+ return new SummaryDetailResponse (
125+ summary .getSummaryId (),
126+ summary .getTitle (),
127+ summary .getSubject (),
128+ keywords ,
129+ points ,
130+ summary .getStatus (),
131+ summary .getIsBookmarked (),
132+ summary .getCreatedAt ()
133+ );
134+
135+ } catch (Exception e ) {
136+ throw new IllegalStateException (e );
67137 }
68138 }
69139
@@ -73,7 +143,7 @@ public void toggleBookmark(Long summaryId) {
73143 summaryMapper .findBookmarkStatus (summaryId );
74144
75145 if (isBookmarked == null ) {
76- throw new IllegalArgumentException ("Summary not found" );
146+ throw new IllegalArgumentException ();
77147 }
78148
79149 summaryMapper .updateBookmark (summaryId , !isBookmarked );
0 commit comments