Skip to content

Commit b3e2845

Browse files
authored
[URECA-60] Fix: 요약 페이지 API 수정 (#43)
* fix: summary 수정 * fix: response 사라짐 해결 * fix: 주석 제거 * fix: 북마크 api 추가 * fix: 코드 래빗 수정 xml
1 parent 362df10 commit b3e2845

4 files changed

Lines changed: 189 additions & 13 deletions

File tree

‎src/main/java/com/ureca/unity/domain/summary/controller/SummaryController.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ public List<SummaryListResponse> getMySummaries(
2222
return summaryService.getMySummaries(userId);
2323
}
2424

25+
@GetMapping("/bookmarks")
26+
public List<SummaryListResponse> getBookmarkedSummaries(
27+
@RequestParam Long userId
28+
) {
29+
return summaryService.getBookmarkedSummaries(userId);
30+
}
31+
32+
@GetMapping("/{summaryId}")
33+
public SummaryDetailResponse getSummaryDetail(
34+
@PathVariable Long summaryId
35+
) {
36+
return summaryService.getSummaryDetail(summaryId);
37+
38+
) {
39+
return summaryService.getMySummaries(userId);
40+
41+
}
42+
2543
@GetMapping("/{summaryId}")
2644
public SummaryDetailResponse getSummaryDetail(
2745
@PathVariable Long summaryId

‎src/main/java/com/ureca/unity/domain/summary/mapper/SummaryMapper.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ void updateBookmark(
3939
@Param("isBookmarked") boolean isBookmarked
4040
);
4141

42-
// ✅ 목록 조회
42+
43+
List<SummaryModel> findByUserId(@Param("userId") Long userId);
44+
45+
List<SummaryModel> findBookmarkedByUserId(@Param("userId") Long userId);
4346
List<SummaryModel> findByUserId(@Param("userId") Long userId);
4447

45-
// ✅ 상세 조회
4648
SummaryModel findById(@Param("summaryId") Long summaryId);
4749
}

‎src/main/java/com/ureca/unity/domain/summary/service/SummaryService.java‎

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎src/main/resources/mapper/summary/SummaryMapper.xml‎

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<mapper namespace="com.ureca.unity.domain.summary.mapper.SummaryMapper">
77

8-
<!-- 요약 생성 -->
8+
99
<insert id="insertSummary">
1010
INSERT INTO summary (
1111
counseling_result_id,
@@ -31,26 +31,36 @@
3131
LIMIT 1
3232
</select>
3333

34-
<!-- 요약 결과 업데이트 (성공) -->
34+
3535
<update id="updateSummaryResult">
3636
UPDATE summary
3737
SET
3838
title = #{title},
3939
subject = #{subject},
40-
keywords = CAST(#{keywords} AS JSON),
40+
keywords = CASE
41+
WHEN #{keywords} IS NULL THEN NULL
42+
ELSE CAST(#{keywords} AS JSON)
43+
END,
44+
points = CASE
45+
WHEN #{points} IS NULL THEN NULL
46+
ELSE CAST(#{points} AS JSON)
47+
END
48+
WHERE summary_id = #{summaryId}
49+
</update>
50+
51+
4152
points = CAST(#{points} AS JSON),
4253
status = 'SUCCESS'
4354
WHERE summary_id = #{summaryId}
4455
</update>
4556

46-
<!-- 상태 업데이트 (FAIL 등) -->
4757
<update id="updateStatus">
4858
UPDATE summary
4959
SET status = #{status}
5060
WHERE summary_id = #{summaryId}
5161
</update>
5262

53-
<!-- 북마크 -->
63+
5464
<select id="findBookmarkStatus" resultType="boolean">
5565
SELECT is_bookmarked
5666
FROM summary
@@ -63,17 +73,27 @@
6373
WHERE summary_id = #{summaryId}
6474
</update>
6575

66-
<!-- 🔥 요약 리스트 조회 -->
76+
<select id="findByUserId"
77+
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
78+
SELECT
79+
summary_id AS summaryId,
80+
counseling_result_id AS counselingResultId,
81+
user_id AS userId,
82+
6783
<select id="findByUserId"
6884
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
6985
SELECT
7086
summary_id AS summaryId,
7187
counseling_result_id AS counselingResultId,
7288
user_id AS userId,
89+
7390
title,
7491
subject,
7592
keywords,
7693
points,
94+
is_bookmarked AS isBookmarked,
95+
status,
96+
created_at AS createdAt
7797
is_bookmarked AS isBookmarked,
7898
status,
7999
created_at AS createdAt
@@ -82,6 +102,31 @@
82102
ORDER BY created_at DESC
83103
</select>
84104

105+
<select id="findBookmarkedByUserId"
106+
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
107+
SELECT
108+
summary_id AS summaryId,
109+
counseling_result_id AS counselingResultId,
110+
user_id AS userId,
111+
title,
112+
subject,
113+
keywords,
114+
points,
115+
is_bookmarked AS isBookmarked,
116+
status,
117+
created_at AS createdAt
118+
FROM summary
119+
WHERE user_id = #{userId}
120+
AND is_bookmarked = true
121+
ORDER BY created_at DESC
122+
</select>
123+
124+
<select id="findById"
125+
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
126+
SELECT
127+
summary_id AS summaryId,
128+
counseling_result_id AS counselingResultId,
129+
user_id AS userId,
85130
<!-- 요약 상세 조회 -->
86131
<select id="findById"
87132
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
@@ -93,6 +138,9 @@
93138
subject,
94139
keywords,
95140
points,
141+
is_bookmarked AS isBookmarked,
142+
status,
143+
created_at AS createdAt
96144
is_bookmarked AS isBookmarked,
97145
status,
98146
created_at AS createdAt

0 commit comments

Comments
 (0)