@@ -151,15 +151,21 @@ else if (categories.size() > 1)
151151
152152 // 게시글 필수 항목 다 작성했는지
153153 private void validatePost (PostRequestDto postRequestDto ){
154- if (postRequestDto .getPostTitle ().isBlank () | postRequestDto .getProblem ().isBlank ()
155- | postRequestDto .getErrorMessage ().isBlank () | postRequestDto .getEnvironment ().isBlank ()
156- | postRequestDto .getReproduceCode ().isBlank () | postRequestDto .getSolutionCode ().isBlank ())
154+ if (!StringUtils .hasText (postRequestDto .getPostTitle ())
155+ || !StringUtils .hasText (postRequestDto .getProblem ())
156+ || !StringUtils .hasText (postRequestDto .getErrorMessage ())
157+ || !StringUtils .hasText (postRequestDto .getEnvironment ())
158+ || !StringUtils .hasText (postRequestDto .getReproduceCode ())
159+ || !StringUtils .hasText (postRequestDto .getSolutionCode ()))
157160 throw new CustomException (ErrorCode .REQUIRED_CONTENT_MISSING );
158161 }
159162 private void validatePost (NewPostRequestDto newPostRequestDto ){
160- if (newPostRequestDto .getPostTitle ().isBlank () | newPostRequestDto .getProblem ().isBlank ()
161- | newPostRequestDto .getErrorMessage ().isBlank () | newPostRequestDto .getEnvironment ().isBlank ()
162- | newPostRequestDto .getReproduceCode ().isBlank () | newPostRequestDto .getSolutionCode ().isBlank ())
163+ if (!StringUtils .hasText (newPostRequestDto .getPostTitle ())
164+ || !StringUtils .hasText (newPostRequestDto .getProblem ())
165+ || !StringUtils .hasText (newPostRequestDto .getErrorMessage ())
166+ || !StringUtils .hasText (newPostRequestDto .getEnvironment ())
167+ || !StringUtils .hasText (newPostRequestDto .getReproduceCode ())
168+ || !StringUtils .hasText (newPostRequestDto .getSolutionCode ()))
163169 throw new CustomException (ErrorCode .REQUIRED_CONTENT_MISSING );
164170 }
165171
@@ -176,12 +182,18 @@ public String uploadImage(MultipartFile imageFile){
176182 return "" ;
177183 }
178184
185+ // 게시글 수정하기
179186 @ Transactional
180187 public void editPost (Long postId , NewPostRequestDto newPostRequestDto ) {
181188 Member member = memberService .getCurrentMemberInfo ();
182189 Post post = postRepository .findById (postId )
183190 .orElseThrow (() -> new CustomException (ErrorCode .POST_NOT_FOUND ));
184191
192+ // 게시글 작성자가 본인이 맞는지
193+ if (!member .getUserId ().equals (post .getUserId ().getUserId ())) {
194+ throw new CustomException (ErrorCode .POST_UPDATE_FORBIDDEN );
195+ }
196+
185197 // 북마크 카테고리별로 선택 제한 두기
186198 List <Tag > tags = fetchAndValidateTags (newPostRequestDto .getTags ());
187199
@@ -201,6 +213,8 @@ & compareTags(post.getPostTags(), tags)){
201213 }
202214
203215 // 필드 업데이트
216+ validatePost (newPostRequestDto );
217+
204218 post .changeTitle (newPostRequestDto .getPostTitle ());
205219 post .changeCoverImage (newPostRequestDto .getCoverImageUrl ());
206220 post .changeProblem (newPostRequestDto .getProblem ());
0 commit comments