Skip to content

Commit

Permalink
Merge pull request #129 from studio-recoding/feat-chat-delete
Browse files Browse the repository at this point in the history
[🚀feat] 채팅으로 일정 삭제 API
  • Loading branch information
JeonHaeseung authored Jul 6, 2024
2 parents b10fde4 + fc12d7a commit 2e266ed
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ public ResponseEntity<GetChatListDto> PostAiSchedule(@AuthUser Member member, @R
GetChatListDto oneUserChats = scheduleService.postAiScheduleAccept(member.getId(), isAccepted, chatId, postScheduleDto);
return new ResponseEntity<>(oneUserChats, HttpStatusCode.valueOf(200));
}

@DeleteMapping("/ai")
@Operation(summary = "AI에 의해서 삭제된 스케쥴", description = "프론트가 보내주는 AI에 의해서 생성된 새로운 스케쥴을 Accept/Deny합니다.")
public ResponseEntity<GetChatListDto> DeleteAiSchedule(@AuthUser Member member, @RequestParam Boolean isAccepted, @RequestParam Long scheduleId){
GetChatListDto oneUserChats = scheduleService.deleteAiScheduleAccept(member.getId(), isAccepted, scheduleId);
return new ResponseEntity<>(oneUserChats, HttpStatusCode.valueOf(200));
}
}
39 changes: 39 additions & 0 deletions src/main/java/Ness/Backend/domain/schedule/ScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import Ness.Backend.domain.schedule.dto.response.GetScheduleListDto;
import Ness.Backend.domain.schedule.entity.Schedule;
import Ness.Backend.global.error.exception.NotFoundCategoryException;
import Ness.Backend.global.error.exception.NotFoundScheduleException;
import Ness.Backend.global.fastApi.FastApiDeleteScheduleApi;
import Ness.Backend.global.fastApi.FastApiPostScheduleApi;
import Ness.Backend.global.fastApi.FastApiPutScheduleApi;
Expand Down Expand Up @@ -170,6 +171,44 @@ public GetChatListDto postAiScheduleAccept(Long memberId, Boolean idAccepted, Lo
return chatService.getOneWeekUserChat(memberId);
}

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

/* 사용자가 Accept 했으면 스케쥴 생성하기 */
if(idAccepted){
/* 삭제할 스케쥴이 정상적으로 존재하는 경우 */
if(schedule != null){
//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에서 삭제
scheduleRepository.delete(schedule);

chatService.createNewChat("일정을 삭제해드렸습니다!", ChatType.AI, 1, member);
}
else{
throw new NotFoundScheduleException();
}
} else {
chatService.createNewChat("일정 추가를 취소했습니다.\n다른 할 일이 있으면 알려주세요.", ChatType.AI, 1, member);
}

// 모든 채팅 내역 반환
return chatService.getOneWeekUserChat(memberId);
}


/* 사용자가 직접 생성한 스케쥴을 RDB & VectorDB에 저장 */
public GetScheduleListDto postNewUserSchedule(Long memberId, PostScheduleDto postScheduleDto){
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/Ness/Backend/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public enum ErrorCode {
NOTFOUND_CATEGORY(BAD_REQUEST, "CATE003", "해당 카테고리가 해당 맴버에게 존재하지 않습니다."),

/* 리포트 관련 */
MISMATCH_REPORT_RECOMMEND(BAD_REQUEST, "RPT001", "한 줄 추천이 존재하지 않습니다.");
MISMATCH_REPORT_RECOMMEND(BAD_REQUEST, "RPT001", "한 줄 추천이 존재하지 않습니다."),

/* 스케쥴 관련 */
NOTFOUND_SCHEDULE(BAD_REQUEST, "SCHE001", "해당 스케쥴이 존재하지 않습니다.");

private final HttpStatus httpStatus;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Ness.Backend.global.error.exception;

import Ness.Backend.global.error.ErrorCode;
import lombok.Getter;

@Getter
public class NotFoundScheduleException extends BaseException {
public NotFoundScheduleException() {
super(ErrorCode.NOTFOUND_SCHEDULE, ErrorCode.NOTFOUND_SCHEDULE.getMessage());
}
public NotFoundScheduleException(String message) {
super(ErrorCode.NOTFOUND_SCHEDULE, message);
}
public NotFoundScheduleException(ErrorCode errorCode) {
super(errorCode, errorCode.getMessage());
}
}

0 comments on commit 2e266ed

Please sign in to comment.