Skip to content

Commit

Permalink
Merge pull request #144 from studio-recoding/dev
Browse files Browse the repository at this point in the history
[🚀feat] 25차 배포
  • Loading branch information
JeonHaeseung authored Jul 16, 2024
2 parents fe3d9d0 + 825a342 commit 5aa81ed
Showing 1 changed file with 82 additions and 76 deletions.
158 changes: 82 additions & 76 deletions src/main/java/Ness/Backend/domain/schedule/ScheduleService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package Ness.Backend.domain.schedule;

import Ness.Backend.domain.bookmark.BookmarkRepository;
import Ness.Backend.domain.bookmark.entity.Bookmark;
import Ness.Backend.domain.category.CategoryRepository;
import Ness.Backend.domain.category.entity.Category;
import Ness.Backend.domain.chat.ChatRepository;
Expand Down Expand Up @@ -38,6 +40,7 @@
public class ScheduleService {
private final ScheduleRepository scheduleRepository;
private final MemberRepository memberRepository;
private final BookmarkRepository bookmarkRepository;
private final CategoryRepository categoryRepository;
private final ChatRepository chatRepository;
private final ChatService chatService;
Expand Down Expand Up @@ -67,28 +70,39 @@ public GetScheduleListDto getOneDayUserSchedule(Long memberId, ZonedDateTime dat
.findOneDaySchedulesByMember_Id(memberId, date));
}

/* 사용자가 직접 삭제한 스케쥴 */
public GetScheduleListDto deleteSchedule(Long memberId, Long scheduleId){
Schedule schedule = scheduleRepository.findScheduleById(scheduleId);
ZonedDateTime scheduleTime = schedule.getStartTime().withZoneSameInstant(ZoneId.of("Asia/Seoul"));
/* 사용자가 직접 생성한 스케쥴을 RDB & VectorDB에 저장 */
public GetScheduleListDto postNewUserSchedule(Long memberId, PostScheduleDto postScheduleDto){
Member memberEntity = memberRepository.findMemberById(memberId);
Category category = categoryRepository.findCategoryById(postScheduleDto.getCategoryNum());

//VectorDB에서 삭제
DeleteFastApiScheduleDto dto = DeleteFastApiScheduleDto.builder()
.member_id(memberId)
.schedule_id(scheduleId)
//새로운 채팅 생성
Schedule newSchedule = Schedule.builder()
.info(postScheduleDto.getInfo())
.location(postScheduleDto.getLocation())
.person(postScheduleDto.getPerson())
.startTime(postScheduleDto.getStartTime())
.endTime(postScheduleDto.getEndTime())
.member(memberEntity)
.category(category)
//.chat() //사용자가 직접 생성했으므로 연관관계 없음
.build();

ResponseEntity<JsonNode> responseNode = fastApiDeleteScheduleApi.deleteFastApiSchedule(dto);
if (responseNode.getStatusCode() == HttpStatusCode.valueOf(204)) {
log.info("Succeed to delete data in Vector DB");
} else {
log.error("Failed to delete data in Vector DB");
}
scheduleRepository.save(newSchedule);

//RDB에서 삭제
scheduleRepository.delete(schedule);
postNewAiSchedule(
postScheduleDto.getInfo(),
postScheduleDto.getLocation(),
postScheduleDto.getPerson(),
postScheduleDto.getStartTime(),
postScheduleDto.getEndTime(),
category.getName(),
category.getId(),
category.getColor(),
newSchedule.getMember().getId(),
newSchedule.getId());

return getOneDayUserSchedule(memberId, scheduleTime);
log.info("Succeed to save user created schedule data in RDB & VectorDB");
return getOneDayUserSchedule(memberId, newSchedule.getStartTime().withZoneSameInstant(ZoneId.of("Asia/Seoul")));
}

/* 사용자가 AI가 생성한 스케쥴을 Accept/Deny한 여부에 따라서 채팅 및 스케쥴 저장 */
Expand Down Expand Up @@ -144,9 +158,36 @@ public GetChatListDto postAiScheduleAccept(Long memberId, Boolean idAccepted, Lo
return chatService.getOneWeekUserChat(memberId);
}

/* 사용자가 직접 삭제한 스케쥴 */
public GetScheduleListDto deleteSchedule(Long memberId, Long scheduleId){
Schedule schedule = scheduleRepository.findScheduleById(scheduleId);
List<Bookmark> bookmarks = bookmarkRepository.findBookmarksBySchedule_Id(scheduleId);
ZonedDateTime scheduleTime = schedule.getStartTime().withZoneSameInstant(ZoneId.of("Asia/Seoul"));

//VectorDB에서 삭제
DeleteFastApiScheduleDto dto = DeleteFastApiScheduleDto.builder()
.member_id(memberId)
.schedule_id(scheduleId)
.build();

ResponseEntity<JsonNode> responseNode = fastApiDeleteScheduleApi.deleteFastApiSchedule(dto);
if (responseNode.getStatusCode() == HttpStatusCode.valueOf(204)) {
log.info("Succeed to delete data in Vector DB");
} else {
log.error("Failed to delete data in Vector DB");
}

//RDB에서 삭제
bookmarkRepository.deleteAll(bookmarks);
scheduleRepository.delete(schedule);

return getOneDayUserSchedule(memberId, scheduleTime);
}

/* 사용자가 AI가 삭제 요청한 스케쥴을 Accept/Deny한 여부에 따라서 채팅 및 스케쥴 저장 */
public GetChatListDto deleteAiScheduleAccept(Long memberId, Boolean idAccepted, Long scheduleId){
Member member = memberRepository.findMemberById(memberId);
List<Bookmark> bookmarks = bookmarkRepository.findBookmarksBySchedule_Id(scheduleId);
Schedule schedule = scheduleRepository.findScheduleById(scheduleId);

/* 사용자가 Accept 했으면 스케쥴 생성하기 */
Expand All @@ -169,6 +210,7 @@ public GetChatListDto deleteAiScheduleAccept(Long memberId, Boolean idAccepted,
String info = schedule.getInfo();

//RDB에서 삭제
bookmarkRepository.deleteAll(bookmarks);
scheduleRepository.delete(schedule);

chatService.createNewChat("\"" + info + "\" " + "일정을 삭제해드렸습니다!", ChatType.AI, 1, member);
Expand All @@ -184,40 +226,34 @@ public GetChatListDto deleteAiScheduleAccept(Long memberId, Boolean idAccepted,
return chatService.getOneWeekUserChat(memberId);
}

/* 사용자가 직접 변경한 스케쥴을 RDB & VectorDB에 저장 */
public GetScheduleListDto changeSchedule(Long memberId, PutScheduleDto putScheduleDto){
Schedule schedule = scheduleRepository.findScheduleById(putScheduleDto.getId());
Category category = categoryRepository.findCategoryById(putScheduleDto.getCategoryNum());

/* 사용자가 직접 생성한 스케쥴을 RDB & VectorDB에 저장 */
public GetScheduleListDto postNewUserSchedule(Long memberId, PostScheduleDto postScheduleDto){
Member memberEntity = memberRepository.findMemberById(memberId);
Category category = categoryRepository.findCategoryById(postScheduleDto.getCategoryNum());

//새로운 채팅 생성
Schedule newSchedule = Schedule.builder()
.info(postScheduleDto.getInfo())
.location(postScheduleDto.getLocation())
.person(postScheduleDto.getPerson())
.startTime(postScheduleDto.getStartTime())
.endTime(postScheduleDto.getEndTime())
.member(memberEntity)
.category(category)
//.chat() //사용자가 직접 생성했으므로 연관관계 없음
.build();

scheduleRepository.save(newSchedule);
//RDB에서 변경
schedule.changeSchedule(
putScheduleDto.getInfo(),
putScheduleDto.getLocation(),
putScheduleDto.getPerson(),
putScheduleDto.getStartTime(),
putScheduleDto.getEndTime(),
category);

postNewAiSchedule(
postScheduleDto.getInfo(),
postScheduleDto.getLocation(),
postScheduleDto.getPerson(),
postScheduleDto.getStartTime(),
postScheduleDto.getEndTime(),
//VectorDB에서 변경
putAiSchedule(
putScheduleDto.getInfo(),
putScheduleDto.getLocation(),
putScheduleDto.getPerson(),
putScheduleDto.getStartTime(),
putScheduleDto.getEndTime(),
category.getName(),
category.getId(),
category.getColor(),
newSchedule.getMember().getId(),
newSchedule.getId());
memberId,
putScheduleDto.getId());

log.info("Succeed to save user created schedule data in RDB & VectorDB");
return getOneDayUserSchedule(memberId, newSchedule.getStartTime().withZoneSameInstant(ZoneId.of("Asia/Seoul")));
return getOneDayUserSchedule(memberId, putScheduleDto.getOriginalTime().withZoneSameInstant(ZoneId.of("Asia/Seoul")));
}

/* 새로운 스케쥴을 VectorDB에 저장하는 API 호출 */
Expand Down Expand Up @@ -252,37 +288,7 @@ public void postNewAiSchedule(String info, String location, String person,
}
}

/* 사용자가 직접 변경한 스케쥴 RDB에 저장하는 로직 */
public GetScheduleListDto changeSchedule(Long memberId, PutScheduleDto putScheduleDto){
Schedule schedule = scheduleRepository.findScheduleById(putScheduleDto.getId());
Category category = categoryRepository.findCategoryById(putScheduleDto.getCategoryNum());

//RDB에서 변경
schedule.changeSchedule(
putScheduleDto.getInfo(),
putScheduleDto.getLocation(),
putScheduleDto.getPerson(),
putScheduleDto.getStartTime(),
putScheduleDto.getEndTime(),
category);

//VectorDB에서 변경
putAiSchedule(
putScheduleDto.getInfo(),
putScheduleDto.getLocation(),
putScheduleDto.getPerson(),
putScheduleDto.getStartTime(),
putScheduleDto.getEndTime(),
category.getName(),
category.getId(),
category.getColor(),
memberId,
putScheduleDto.getId());

return getOneDayUserSchedule(memberId, putScheduleDto.getOriginalTime().withZoneSameInstant(ZoneId.of("Asia/Seoul")));
}

/*스케쥴 변경을 VectorDB에 저장하는 API 호출 */
/* 변경된 스케쥴을 VectorDB에 저장하는 API 호출 */
public void putAiSchedule(String info, String location, String person,
ZonedDateTime startTime, ZonedDateTime endTime,
String category, Long category_id, String category_color, Long memberId, Long scheduleId){
Expand Down

0 comments on commit 5aa81ed

Please sign in to comment.