1818import com .example .log4u .domain .diary .dto .DiaryResponseDto ;
1919import com .example .log4u .domain .diary .entity .Diary ;
2020import com .example .log4u .domain .diary .exception .NotFoundDiaryException ;
21+ import com .example .log4u .domain .diary .exception .OwnerAccessDeniedException ;
2122import com .example .log4u .domain .diary .repository .DiaryRepository ;
2223import com .example .log4u .domain .follow .repository .FollowRepository ;
2324import com .example .log4u .domain .media .entity .Media ;
@@ -99,7 +100,7 @@ public PageResponse<DiaryResponseDto> getDiariesByCursor(Long userId, Long targe
99100 @ Transactional
100101 public void updateDiary (Long userId , Long diaryId , DiaryRequestDto request ) {
101102 Diary diary = findDiaryOrThrow (diaryId );
102- diary . validateOwner (userId );
103+ validateOwner (diary , userId );
103104
104105 if (request .mediaList () != null ) {
105106 mediaService .updateMediaByDiaryId (diary .getDiaryId (), request .mediaList ());
@@ -113,7 +114,7 @@ public void updateDiary(Long userId, Long diaryId, DiaryRequestDto request) {
113114 @ Transactional
114115 public void deleteDiary (Long userId , Long diaryId ) {
115116 Diary diary = findDiaryOrThrow (diaryId );
116- diary . validateOwner (userId );
117+ validateOwner (diary , userId );
117118 mediaService .deleteMediaByDiaryId (diaryId );
118119 diaryRepository .delete (diary );
119120 }
@@ -155,6 +156,13 @@ private List<DiaryResponseDto> getDiaryResponsesWithMedia(List<Diary> diaries) {
155156 .toList ();
156157 }
157158
159+ // 다이어리 작성자 본인 체크
160+ private void validateOwner (Diary diary , Long userId ) {
161+ if (!diary .isOwner (userId )) {
162+ throw new OwnerAccessDeniedException ();
163+ }
164+ }
165+
158166 // 다이어리 목록 조회 시 권한 체크
159167 private List <VisibilityType > determineAccessibleVisibilities (Long userId , Long targetUserId ) {
160168 if (userId .equals (targetUserId )) {
0 commit comments