Skip to content

Commit 402fbce

Browse files
committed
fix: 머지 후 발생한 오류 수정
1 parent b3e2845 commit 402fbce

4 files changed

Lines changed: 28 additions & 156 deletions

File tree

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,21 @@ public class SummaryController {
1515

1616
private final SummaryService summaryService;
1717

18+
// 전체 요약 리스트
1819
@GetMapping
19-
public List<SummaryListResponse> getMySummaries(
20-
@RequestParam Long userId
21-
) {
20+
public List<SummaryListResponse> getMySummaries(@RequestParam Long userId) {
2221
return summaryService.getMySummaries(userId);
2322
}
2423

24+
// 북마크 요약 리스트
2525
@GetMapping("/bookmarks")
26-
public List<SummaryListResponse> getBookmarkedSummaries(
27-
@RequestParam Long userId
28-
) {
26+
public List<SummaryListResponse> getBookmarkedSummaries(@RequestParam Long userId) {
2927
return summaryService.getBookmarkedSummaries(userId);
3028
}
3129

30+
// 요약 상세
3231
@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-
43-
@GetMapping("/{summaryId}")
44-
public SummaryDetailResponse getSummaryDetail(
45-
@PathVariable Long summaryId
46-
) {
32+
public SummaryDetailResponse getSummaryDetail(@PathVariable Long summaryId) {
4733
return summaryService.getSummaryDetail(summaryId);
4834
}
4935
}

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

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

42-
42+
// 전체 목록
4343
List<SummaryModel> findByUserId(@Param("userId") Long userId);
4444

45+
// 북마크 목록
4546
List<SummaryModel> findBookmarkedByUserId(@Param("userId") Long userId);
46-
List<SummaryModel> findByUserId(@Param("userId") Long userId);
4747

48+
// 상세
4849
SummaryModel findById(@Param("summaryId") Long summaryId);
4950
}

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

Lines changed: 12 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

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

Lines changed: 7 additions & 38 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,14 @@
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 = 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-
52-
points = CAST(#{points} AS JSON),
53-
status = 'SUCCESS'
40+
keywords = CAST(#{keywords} AS JSON),
41+
points = CAST(#{points} AS JSON)
5442
WHERE summary_id = #{summaryId}
5543
</update>
5644

@@ -60,7 +48,6 @@
6048
WHERE summary_id = #{summaryId}
6149
</update>
6250

63-
6451
<select id="findBookmarkStatus" resultType="boolean">
6552
SELECT is_bookmarked
6653
FROM summary
@@ -73,35 +60,26 @@
7360
WHERE summary_id = #{summaryId}
7461
</update>
7562

63+
<!-- 전체 리스트 조회 -->
7664
<select id="findByUserId"
7765
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
7866
SELECT
7967
summary_id AS summaryId,
8068
counseling_result_id AS counselingResultId,
8169
user_id AS userId,
82-
83-
<select id="findByUserId"
84-
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
85-
SELECT
86-
summary_id AS summaryId,
87-
counseling_result_id AS counselingResultId,
88-
user_id AS userId,
89-
9070
title,
9171
subject,
9272
keywords,
9373
points,
9474
is_bookmarked AS isBookmarked,
9575
status,
9676
created_at AS createdAt
97-
is_bookmarked AS isBookmarked,
98-
status,
99-
created_at AS createdAt
10077
FROM summary
10178
WHERE user_id = #{userId}
10279
ORDER BY created_at DESC
10380
</select>
10481

82+
<!-- 북마크 리스트 조회 -->
10583
<select id="findBookmarkedByUserId"
10684
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
10785
SELECT
@@ -121,29 +99,20 @@
12199
ORDER BY created_at DESC
122100
</select>
123101

102+
<!-- 요약 상세 조회 -->
124103
<select id="findById"
125104
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
126105
SELECT
127106
summary_id AS summaryId,
128107
counseling_result_id AS counselingResultId,
129108
user_id AS userId,
130-
<!-- 요약 상세 조회 -->
131-
<select id="findById"
132-
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
133-
SELECT
134-
summary_id AS summaryId,
135-
counseling_result_id AS counselingResultId,
136-
user_id AS userId,
137109
title,
138110
subject,
139111
keywords,
140112
points,
141113
is_bookmarked AS isBookmarked,
142114
status,
143115
created_at AS createdAt
144-
is_bookmarked AS isBookmarked,
145-
status,
146-
created_at AS createdAt
147116
FROM summary
148117
WHERE summary_id = #{summaryId}
149118
</select>

0 commit comments

Comments
 (0)