9
9
import Ness .Backend .domain .chat .entity .ChatType ;
10
10
import Ness .Backend .domain .member .MemberRepository ;
11
11
import Ness .Backend .domain .member .entity .Member ;
12
- import Ness .Backend .domain .schedule .dto .request .PostFastApiScheduleDto ;
13
- import Ness .Backend .domain .schedule .dto .request .PostScheduleDto ;
14
- import Ness .Backend .domain .schedule .dto .request .PutScheduleDto ;
12
+ import Ness .Backend .domain .schedule .dto .request .*;
15
13
import Ness .Backend .domain .schedule .dto .response .GetScheduleListDto ;
16
14
import Ness .Backend .domain .schedule .dto .response .GetScheduleDetailDto ;
17
15
import Ness .Backend .domain .schedule .dto .response .GetScheduleDto ;
18
16
import Ness .Backend .domain .schedule .entity .Schedule ;
19
- import Ness .Backend .global .fastApi .FastApiScheduleApi ;
17
+ import Ness .Backend .global .fastApi .FastApiDeleteScheduleApi ;
18
+ import Ness .Backend .global .fastApi .FastApiPostScheduleApi ;
19
+ import Ness .Backend .global .fastApi .FastApiPutScheduleApi ;
20
20
import com .fasterxml .jackson .databind .JsonNode ;
21
21
import lombok .RequiredArgsConstructor ;
22
22
import lombok .extern .slf4j .Slf4j ;
@@ -39,7 +39,9 @@ public class ScheduleService {
39
39
private final CategoryRepository categoryRepository ;
40
40
private final ChatRepository chatRepository ;
41
41
private final ChatService chatService ;
42
- private final FastApiScheduleApi fastApiScheduleApi ;
42
+ private final FastApiPostScheduleApi fastApiPostScheduleApi ;
43
+ private final FastApiDeleteScheduleApi fastApiDeleteScheduleApi ;
44
+ private final FastApiPutScheduleApi fastApiPutScheduleApi ;
43
45
44
46
// 한 달치 스케쥴 가져오는 로직
45
47
@ Transactional (readOnly = true )
@@ -64,9 +66,11 @@ public GetScheduleListDto getOneDayUserSchedule(Long memberId, ZonedDateTime dat
64
66
}
65
67
66
68
/* 사용자가 직접 변경한 스케쥴 RDB에 저장하는 로직 */
67
- public GetScheduleListDto changeSchedule (Long memberId , PutScheduleDto putScheduleDto , String date ){
69
+ public GetScheduleListDto changeSchedule (Long memberId , PutScheduleDto putScheduleDto ){
68
70
Schedule schedule = scheduleRepository .findScheduleById (putScheduleDto .getId ());
69
71
Category category = categoryRepository .findCategoryById (putScheduleDto .getCategoryNum ());
72
+
73
+ //RDB에서 변경
70
74
schedule .changeSchedule (
71
75
putScheduleDto .getInfo (),
72
76
putScheduleDto .getLocation (),
@@ -75,15 +79,57 @@ public GetScheduleListDto changeSchedule(Long memberId, PutScheduleDto putSchedu
75
79
putScheduleDto .getEndTime (),
76
80
category );
77
81
78
- return getOneDayUserSchedule (memberId , schedule .getStartTime ().withZoneSameInstant (ZoneId .of ("Asia/Seoul" )));
82
+ //VectorDB에서 변경
83
+ ZonedDateTime endTime = putScheduleDto .getEndTime ();
84
+ if (endTime == null ){
85
+ endTime = putScheduleDto .getStartTime ();
86
+ }
87
+
88
+ PutFastApiScheduleDto dto = PutFastApiScheduleDto .builder ()
89
+ .info (putScheduleDto .getInfo ())
90
+ .location (putScheduleDto .getLocation ())
91
+ .person (putScheduleDto .getPerson ())
92
+ .startTime (putScheduleDto .getStartTime ())
93
+ .endTime (endTime )
94
+ .category (category .getName ())
95
+ .category_id (category .getId ())
96
+ .member_id (memberId )
97
+ .schedule_id (putScheduleDto .getId ())
98
+ .build ();
99
+
100
+ ResponseEntity <JsonNode > responseNode = fastApiPutScheduleApi .putFastApiSchedule (dto );
101
+
102
+ if (responseNode .getStatusCode () == HttpStatusCode .valueOf (201 )) {
103
+ log .info ("Succeed to put data in Vector DB" );
104
+ } else {
105
+ log .error ("Failed to put data in Vector DB" );
106
+ }
107
+
108
+ return getOneDayUserSchedule (memberId , putScheduleDto .getOriginalTime ().withZoneSameInstant (ZoneId .of ("Asia/Seoul" )));
79
109
}
80
110
81
111
/* 사용자가 직접 삭제한 스케쥴 */
82
- public GetScheduleListDto deleteSchedule (Long memberId ){
83
- Schedule schedule = scheduleRepository .findScheduleById (memberId );
112
+ public GetScheduleListDto deleteSchedule (Long memberId , Long scheduleId ){
113
+ Schedule schedule = scheduleRepository .findScheduleById (scheduleId );
114
+ ZonedDateTime scheduleTime = schedule .getStartTime ().withZoneSameInstant (ZoneId .of ("Asia/Seoul" ));
115
+
116
+ //VectorDB에서 삭제
117
+ DeleteFastApiScheduleDto dto = DeleteFastApiScheduleDto .builder ()
118
+ .member_id (memberId )
119
+ .schedule_id (scheduleId )
120
+ .build ();
121
+
122
+ ResponseEntity <JsonNode > responseNode = fastApiDeleteScheduleApi .deleteFastApiSchedule (dto );
123
+ if (responseNode .getStatusCode () == HttpStatusCode .valueOf (204 )) {
124
+ log .info ("Succeed to delete data in Vector DB" );
125
+ } else {
126
+ log .error ("Failed to delete data in Vector DB" );
127
+ }
128
+
129
+ //RDB에서 삭제
84
130
scheduleRepository .delete (schedule );
85
131
86
- return getOneDayUserSchedule (memberId , schedule . getStartTime (). withZoneSameInstant ( ZoneId . of ( "Asia/Seoul" )) );
132
+ return getOneDayUserSchedule (memberId , scheduleTime );
87
133
}
88
134
89
135
/* 사용자가 AI가 생성한 스케쥴을 Accept/Deny한 여부에 따라서 채팅 및 스케쥴 저장 */
@@ -144,17 +190,19 @@ public GetScheduleListDto postNewUserSchedule(Long memberId, PostScheduleDto pos
144
190
postScheduleDto .getPerson (),
145
191
postScheduleDto .getStartTime (),
146
192
postScheduleDto .getEndTime (),
147
- postScheduleDto .getCategoryNum (),
193
+ category .getName (),
194
+ category .getId (),
148
195
newSchedule .getMember ().getId (),
149
196
newSchedule .getId ());
150
197
198
+ log .info ("Succeed to save user created schedule data in RDB & VectorDB" );
151
199
return getOneDayUserSchedule (memberId , newSchedule .getStartTime ().withZoneSameInstant (ZoneId .of ("Asia/Seoul" )));
152
200
}
153
201
154
202
/* 새로운 스케쥴을 VectorDB에 저장하는 API 호출 */
155
203
public void postNewAiSchedule (String info , String location , String person ,
156
204
ZonedDateTime startTime , ZonedDateTime endTime ,
157
- Long category , Long memberId , Long scheduleId ){
205
+ String category , Long category_id , Long memberId , Long scheduleId ){
158
206
159
207
if (endTime == null ){
160
208
endTime = startTime ;
@@ -167,11 +215,12 @@ public void postNewAiSchedule(String info, String location, String person,
167
215
.startTime (startTime )
168
216
.endTime (endTime )
169
217
.category (category )
218
+ .category_id (category_id )
170
219
.member_id (memberId )
171
220
.schedule_id (scheduleId )
172
221
.build ();
173
222
174
- ResponseEntity <JsonNode > responseNode = fastApiScheduleApi .creatFastApiSchedule (dto );
223
+ ResponseEntity <JsonNode > responseNode = fastApiPostScheduleApi .creatFastApiSchedule (dto );
175
224
if (responseNode .getStatusCode () == HttpStatusCode .valueOf (201 )) {
176
225
log .info ("Succeed to save data in Vector DB" );
177
226
} else {
0 commit comments