Skip to content

Commit

Permalink
✨ [Feature] 개인일정 삭제 api 삭제 검증 추가 #1058
Browse files Browse the repository at this point in the history
  • Loading branch information
taehyeon committed Dec 31, 2024
1 parent d9824eb commit 0812ca1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import gg.data.calendar.PrivateSchedule;
import gg.data.calendar.PublicSchedule;
import gg.data.calendar.ScheduleGroup;
import gg.data.calendar.type.ScheduleStatus;
import gg.data.user.User;
import gg.repo.calendar.PrivateScheduleRepository;
import gg.repo.calendar.PublicScheduleRepository;
import gg.repo.calendar.ScheduleGroupRepository;
import gg.repo.user.UserRepository;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.DuplicationException;
import gg.utils.exception.custom.ForbiddenException;
import gg.utils.exception.custom.InvalidParameterException;
import gg.utils.exception.custom.NotExistException;
Expand Down Expand Up @@ -69,9 +71,17 @@ public PrivateScheduleUpdateResDto updatePrivateSchedule(UserDto userDto,
public void deletePrivateSchedule(UserDto userDto, Long privateScheduleId) {
PrivateSchedule privateSchedule = privateScheduleRepository.findById(privateScheduleId)
.orElseThrow(() -> new NotExistException(ErrorCode.PRIVATE_SCHEDULE_NOT_FOUND));
validateDeletion(privateSchedule.getStatus());
validateAuthor(userDto.getIntraId(), privateSchedule.getPublicSchedule().getAuthor());
privateSchedule.delete();
}

public void validateDeletion(ScheduleStatus status) {
if (status == ScheduleStatus.DELETE) {
throw new DuplicationException(ErrorCode.CALENDAR_ALREADY_DELETE);
}
}

public void validateTimeRange(LocalDateTime startTime, LocalDateTime endTime) {
if (endTime.isBefore(startTime)) {
throw new InvalidParameterException(ErrorCode.CALENDAR_BEFORE_DATE);
Expand Down
3 changes: 2 additions & 1 deletion gg-utils/src/main/java/gg/utils/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ public enum ErrorCode {
CALENDAR_AUTHOR_NOT_MATCH(403, "CA205", "잘못된 사용자입니다."),
PRIVATE_SCHEDULE_NOT_FOUND(404, "CA101", "개인 일정을 찾을 수 없습니다."),
PUBLIC_SCHEDULE_NOT_FOUND(404, "CA102", "공유 일정을 찾을 수 없습니다."),
SCHEDULE_GROUP_NOT_FOUND(404, "CA103", "스캐줄 그룹을 찾을 수 없습니다.");
SCHEDULE_GROUP_NOT_FOUND(404, "CA103", "스캐줄 그룹을 찾을 수 없습니다."),
CALENDAR_ALREADY_DELETE(409, "CA104", "이미 삭제된 일정입니다.");

private final int status;
private final String errCode;
Expand Down

0 comments on commit 0812ca1

Please sign in to comment.