9
9
import java .util .function .Function ;
10
10
import java .util .stream .Collectors ;
11
11
import lombok .RequiredArgsConstructor ;
12
- import org .checkerframework .checker .units .qual .A ;
13
12
import org .springframework .data .mongodb .core .MongoTemplate ;
14
13
import org .springframework .data .mongodb .core .query .Criteria ;
15
14
import org .springframework .data .mongodb .core .query .Query ;
@@ -50,18 +49,15 @@ public ContentListResponse saveRecommendContents(String memberId, LocalDate date
50
49
diaryAnalysisService .getDiaryAnalysisByMemberIdAndDate (memberId , date );
51
50
Member member = memberService .getMemberById (memberId );
52
51
53
- String prompt = "이 일기의 감정에 정신적으로 도움이 되는 메타데이터를 10개 추천해줘" ;
52
+ String prompt = "이 일기와 조금이라도 관련있는 메타데이터를 10개 추천해줘" ;
54
53
prompt = recommendService .createPrompt (
55
54
analysis .getEmotions (), analysis .getEvent (), member , prompt
56
55
);
57
56
List <Content > recommendedContents
58
57
= getRecommendContentsByAnalysis (analysis , member , prompt );
59
58
60
- List <Content > savedContents = saveOrUpdateContents (recommendedContents );
61
- diaryAnalysisService .saveRecommendContents (analysis , savedContents );
62
-
63
59
return ContentListResponse .from (
64
- savedContents .stream ()
60
+ recommendedContents .stream ()
65
61
.map (content -> ContentListResponse .ContentResponse .from (
66
62
content ,
67
63
contentQueryService .getContentLikeNumber (content ),
@@ -81,7 +77,6 @@ public ContentListResponse saveReRecommendContents(
81
77
DiaryAnalysis analysis =
82
78
diaryAnalysisService .getDiaryAnalysisByMemberIdAndDate (memberId , date );
83
79
Member member = memberService .getMemberById (memberId );
84
- List <String > recommendedUrls = extractRecommendContentUrls (analysis );
85
80
86
81
String prompt = "지금 사용자의 상태에 따라 관련되거나 정신적으로 도움 되는 콘텐츠 10개를 추천해줘" ;
87
82
prompt = recommendService .createPrompt (
@@ -91,12 +86,8 @@ public ContentListResponse saveReRecommendContents(
91
86
= getRecommendContentsByAnalysis (analysis , member , prompt );
92
87
// TODO: 추후에 feedback을 통해서 재추천 컨텐츠를 가져와야 함
93
88
94
- List <Content > savedContents = saveOrUpdateContents (recommendedContents );
95
-
96
- diaryAnalysisService .saveRecommendContents (analysis , savedContents );
97
-
98
89
return ContentListResponse .from (
99
- savedContents .stream ()
90
+ recommendedContents .stream ()
100
91
.map (content -> ContentListResponse .ContentResponse .from (
101
92
content ,
102
93
contentQueryService .getContentLikeNumber (content ),
@@ -152,41 +143,7 @@ private List<Content> getRecommendContentsByAnalysis(
152
143
}
153
144
}
154
145
155
- private List <Content > getRecommendContentsByAnalysis (
156
- DiaryAnalysis analysis ,
157
- List <String > recommendedUrls ,
158
- String feedback
159
- ) {
160
- // TODO: gpt api와 youtube api를 통해서 재추천 컨텐츠를 가져와야 함
161
- return null ;
162
- }
163
-
164
- private List <Content > saveOrUpdateContents (List <Content > recommendedContents ) {
165
- List <String > urls = recommendedContents .stream ().map (Content ::getUrl ).toList ();
166
- Map <String , Content > existingContents = contentRepository .findByUrlIn (urls ).stream ()
167
- .collect (Collectors .toMap (Content ::getUrl , Function .identity ()));
168
-
169
- List <Content > toSaveContents = new ArrayList <>();
170
- for (Content content : recommendedContents ) {
171
- Content existingContent = existingContents .get (content .getUrl ());
172
- if (existingContent != null ) {
173
- existingContent .updateContent (content );
174
- toSaveContents .add (existingContent );
175
- } else {
176
- toSaveContents .add (content );
177
- }
178
- }
179
-
180
- return contentRepository .saveAll (toSaveContents );
181
- }
182
-
183
146
private void validateRecommendLimit (String memberId ) {
184
147
memberService .decrementRemainRecommendNumber (memberId );
185
148
}
186
-
187
- private List <String > extractRecommendContentUrls (DiaryAnalysis analysis ) {
188
- return analysis .getRecommendContents ().stream ()
189
- .map (RecommendContent ::getContentUrl )
190
- .toList ();
191
- }
192
149
}
0 commit comments