diff --git a/src/main/java/chzzk/grassdiary/domain/diary/controller/DiaryController.java b/src/main/java/chzzk/grassdiary/domain/diary/controller/DiaryController.java index 046aec25..6c162653 100644 --- a/src/main/java/chzzk/grassdiary/domain/diary/controller/DiaryController.java +++ b/src/main/java/chzzk/grassdiary/domain/diary/controller/DiaryController.java @@ -41,6 +41,14 @@ public DiaryUpdateResponseDTO update( return diaryService.update(diaryId, requestDto); } + @PatchMapping("/{diaryId}/visibility") + public ResponseEntity updateVisibility( + @PathVariable(name = "diaryId") Long diaryId, + @AuthenticatedMember AuthMemberPayload loginMember) { + diaryService.updateVisibility(diaryId, loginMember.id()); + return ResponseEntity.noContent().build(); + } + @DeleteMapping("/{diaryId}") public Long delete(@PathVariable(name = "diaryId") Long diaryId, @AuthenticatedMember AuthMemberPayload payload) { diff --git a/src/main/java/chzzk/grassdiary/domain/diary/entity/Diary.java b/src/main/java/chzzk/grassdiary/domain/diary/entity/Diary.java index b6920453..bc506dcd 100644 --- a/src/main/java/chzzk/grassdiary/domain/diary/entity/Diary.java +++ b/src/main/java/chzzk/grassdiary/domain/diary/entity/Diary.java @@ -79,6 +79,10 @@ public void update(String content, Boolean isPrivate, Boolean hasTag, this.conditionLevel = conditionLevel; } + public void updateVisibility() { + this.isPrivate = !this.isPrivate; + } + public LocalDateTime getCreatedAt() { return super.getCreatedAt(); } diff --git a/src/main/java/chzzk/grassdiary/domain/diary/service/DiaryService.java b/src/main/java/chzzk/grassdiary/domain/diary/service/DiaryService.java index 14c41a39..6b28a4a9 100644 --- a/src/main/java/chzzk/grassdiary/domain/diary/service/DiaryService.java +++ b/src/main/java/chzzk/grassdiary/domain/diary/service/DiaryService.java @@ -83,6 +83,14 @@ public DiaryUpdateResponseDTO update(Long id, DiaryUpdateRequestDTO requestDto) return updateDiary(requestDto, originalDiary); } + @Transactional + public void updateVisibility(Long diaryId, Long loginMemberId) { + Diary diary = getDiaryById(diaryId); + + validateDiaryOwner(diary, loginMemberId); + diary.updateVisibility(); + } + /** * diaryId를 이용해서 diaryTag, MemberTag 를 찾아내기 diaryTag 삭제 -> deleteAllInBatch 고려해보기 MemberTag 삭제 해당 일기의 좋아요 찾기 및 삭제 * 이미지 삭제