Skip to content

Commit

Permalink
✨ feat: 공고 수정 기능 예외 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
이소정 authored and 이소정 committed Jan 28, 2024
1 parent c23b07d commit db4fb38
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public void increaseViewCount() {
this.viewCount++;
}

public void update(String title, AnnouncementType type, AnnouncementCategory category, String content) {
public void update(String title, AnnouncementType type, AnnouncementCategory category, String content, AnnouncementStatus status) {
this.title = title == null ? this.title : title;
this.type = type == null ? this.type : type;
this.category = category == null ? this.category : category;
this.content = content == null ? this.content : content;
this.status = (status != null) ? status : this.status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum AnnouncementErrorCode implements BaseErrorCode {
ANNOUNCEMENT_ERROR(HttpStatus.BAD_REQUEST, "ANC4000", "공지사항 관련 에러"),
ANNOUNCEMENT_ALREADY_DELETED(HttpStatus.BAD_REQUEST, "ANC4001", "이미 삭제된 공지사항입니다."),
INVALID_ORGANIZATION(HttpStatus.BAD_REQUEST, "ANC4002", "해당 단체의 공고가 아닙니다."),
INVALID_ANNOUNCEMENT_STATUS(HttpStatus.BAD_REQUEST, "ANC4003", "해당 상태의 공고는 수정할 수 없습니다."),
ANNOUNCEMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "ANC4040", "해당 공지사항이 존재하지 않습니다.");

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ public AnnouncementUpdateResponse updateAnnouncement(Organization authOrganizati
final Announcement announcement = announcementRepository.findById(proposeId)
.orElseThrow(() -> new AnnouncementException(AnnouncementErrorCode.ANNOUNCEMENT_NOT_FOUND));

if (announcement.getStatus() != AnnouncementStatus.POSTED)
throw new AnnouncementException(AnnouncementErrorCode.INVALID_ANNOUNCEMENT_STATUS);
if (!isOrganizationsAnnouncement(authOrganization.getId(), announcement))
throw new AnnouncementException(AnnouncementErrorCode.INVALID_ORGANIZATION);

announcement.update(request.title(), request.type(), request.category(), request.content());
announcement.update(request.title(), request.type(), request.category(), request.content(), request.status());
announcementRepository.save(announcement);
return AnnouncementUpdateResponse.from(announcement);
}
Expand Down

0 comments on commit db4fb38

Please sign in to comment.