Skip to content

Commit 1486ebc

Browse files
authored
[URECA-60] Fix: 요약 페이지 API 수정 (#38)
* fix: summary 수정 * fix: response 사라짐 해결 * fix: 주석 제거
1 parent fb5c331 commit 1486ebc

7 files changed

Lines changed: 172 additions & 32 deletions

File tree

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,31 @@
11
package com.ureca.unity.domain.summary.controller;
22

3-
import com.ureca.unity.domain.summary.dto.request.SummaryRequest;
4-
import com.ureca.unity.domain.summary.dto.response.SummaryResponse;
3+
import com.ureca.unity.domain.summary.dto.response.SummaryDetailResponse;
4+
import com.ureca.unity.domain.summary.dto.response.SummaryListResponse;
55
import com.ureca.unity.domain.summary.service.SummaryService;
6-
import io.swagger.v3.oas.annotations.tags.Tag;
7-
import jakarta.validation.Valid;
86
import lombok.RequiredArgsConstructor;
97
import org.springframework.web.bind.annotation.*;
108

11-
@Tag(
12-
name = "4. Summary",
13-
description = "요약 관련 API"
14-
)
9+
import java.util.List;
1510

1611
@RestController
17-
@RequiredArgsConstructor
1812
@RequestMapping("/api/summaries")
13+
@RequiredArgsConstructor
1914
public class SummaryController {
2015

2116
private final SummaryService summaryService;
2217

23-
@PostMapping
24-
public SummaryResponse create(
25-
@Valid @RequestBody SummaryRequest request
18+
@GetMapping
19+
public List<SummaryListResponse> getMySummaries(
20+
@RequestParam Long userId
2621
) {
27-
return summaryService.createSummary(
28-
request.getCounselingResultId(),
29-
request.getUserId(),
30-
request.getCounselingText()
31-
);
22+
return summaryService.getMySummaries(userId);
3223
}
3324

34-
@PatchMapping("/{summaryId}/bookmark")
35-
public void toggleBookmark(
25+
@GetMapping("/{summaryId}")
26+
public SummaryDetailResponse getSummaryDetail(
3627
@PathVariable Long summaryId
3728
) {
38-
summaryService.toggleBookmark(summaryId);
29+
return summaryService.getSummaryDetail(summaryId);
3930
}
4031
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.ureca.unity.domain.summary.dto.response;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
import java.time.LocalDateTime;
7+
import java.util.List;
8+
9+
@Getter
10+
@AllArgsConstructor
11+
public class SummaryDetailResponse {
12+
13+
private Long summaryId;
14+
private String title;
15+
private String subject;
16+
private List<String> keywords;
17+
private List<String> points;
18+
private String status;
19+
private Boolean isBookmarked;
20+
private LocalDateTime createdAt;
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.ureca.unity.domain.summary.dto.response;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.List;
5+
6+
public record SummaryListResponse(
7+
Long summaryId,
8+
String title,
9+
String status,
10+
List<String> keywords,
11+
LocalDateTime createdAt
12+
) {}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.ureca.unity.domain.summary.mapper;
22

3+
import com.ureca.unity.domain.summary.model.SummaryModel;
34
import org.apache.ibatis.annotations.Mapper;
45
import org.apache.ibatis.annotations.Param;
56

7+
import java.util.List;
8+
69
@Mapper
710
public interface SummaryMapper {
811

@@ -35,4 +38,10 @@ void updateBookmark(
3538
@Param("summaryId") Long summaryId,
3639
@Param("isBookmarked") boolean isBookmarked
3740
);
41+
42+
// ✅ 목록 조회
43+
List<SummaryModel> findByUserId(@Param("userId") Long userId);
44+
45+
// ✅ 상세 조회
46+
SummaryModel findById(@Param("summaryId") Long summaryId);
3847
}

‎src/main/java/com/ureca/unity/domain/summary/model/SummaryModel.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public class SummaryModel {
1414
private String title;
1515
private String subject;
1616

17-
private String keywords; // JSON
18-
private String points; // JSON
17+
private String keywords;
18+
private String points;
1919

20-
private boolean isBookmarked;
20+
private Boolean isBookmarked;
2121
private String status;
2222
private LocalDateTime createdAt;
2323
}

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

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.ureca.unity.domain.summary.service;
22

3+
import com.fasterxml.jackson.core.type.TypeReference;
34
import com.fasterxml.jackson.databind.ObjectMapper;
45
import com.ureca.unity.domain.gemini.dto.GeminiSummaryResponse;
56
import 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;
69
import com.ureca.unity.domain.summary.dto.response.SummaryResponse;
710
import com.ureca.unity.domain.summary.mapper.SummaryMapper;
11+
import com.ureca.unity.domain.summary.model.SummaryModel;
812
import lombok.RequiredArgsConstructor;
913
import org.springframework.stereotype.Service;
1014
import 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);

src/main/resources/mapper/summary/Summary.xml renamed to src/main/resources/mapper/summary/SummaryMapper.xml

Lines changed: 42 additions & 5 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-
<!-- summary 생성 (loading) -->
8+
<!-- 요약 생성 -->
99
<insert id="insertSummary">
1010
INSERT INTO summary (
1111
counseling_result_id,
@@ -16,7 +16,7 @@
1616
) VALUES (
1717
#{counselingResultId},
1818
#{userId},
19-
'loading',
19+
'LOADING',
2020
false,
2121
NOW()
2222
)
@@ -31,19 +31,19 @@
3131
LIMIT 1
3232
</select>
3333

34-
<!-- 요약 결과 업데이트 -->
34+
<!-- 요약 결과 업데이트 (성공) -->
3535
<update id="updateSummaryResult">
3636
UPDATE summary
3737
SET
3838
title = #{title},
3939
subject = #{subject},
4040
keywords = CAST(#{keywords} AS JSON),
4141
points = CAST(#{points} AS JSON),
42-
status = 'success'
42+
status = 'SUCCESS'
4343
WHERE summary_id = #{summaryId}
4444
</update>
4545

46-
<!-- 실패 처리 -->
46+
<!-- 상태 업데이트 (FAIL 등) -->
4747
<update id="updateStatus">
4848
UPDATE summary
4949
SET status = #{status}
@@ -63,4 +63,41 @@
6363
WHERE summary_id = #{summaryId}
6464
</update>
6565

66+
<!-- 🔥 요약 리스트 조회 -->
67+
<select id="findByUserId"
68+
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
69+
SELECT
70+
summary_id AS summaryId,
71+
counseling_result_id AS counselingResultId,
72+
user_id AS userId,
73+
title,
74+
subject,
75+
keywords,
76+
points,
77+
is_bookmarked AS isBookmarked,
78+
status,
79+
created_at AS createdAt
80+
FROM summary
81+
WHERE user_id = #{userId}
82+
ORDER BY created_at DESC
83+
</select>
84+
85+
<!-- 요약 상세 조회 -->
86+
<select id="findById"
87+
resultType="com.ureca.unity.domain.summary.model.SummaryModel">
88+
SELECT
89+
summary_id AS summaryId,
90+
counseling_result_id AS counselingResultId,
91+
user_id AS userId,
92+
title,
93+
subject,
94+
keywords,
95+
points,
96+
is_bookmarked AS isBookmarked,
97+
status,
98+
created_at AS createdAt
99+
FROM summary
100+
WHERE summary_id = #{summaryId}
101+
</select>
102+
66103
</mapper>

0 commit comments

Comments
 (0)