Skip to content

Commit a0dcef5

Browse files
authored
[FIX] 오타 수정 및 DTO 정리
2 parents 13a0a31 + 0ac9ff2 commit a0dcef5

5 files changed

Lines changed: 34 additions & 66 deletions

File tree

src/main/java/com/example/FixLog/controller/PostController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.example.FixLog.controller;
22

3-
import com.example.FixLog.dto.post.NewPostRequestDto;
43
import com.example.FixLog.dto.post.PostRequestDto;
54
import com.example.FixLog.dto.Response;
65
import com.example.FixLog.dto.post.PostResponseDto;
@@ -34,8 +33,8 @@ public Response<String> uploadImage(@RequestPart("imageFile") MultipartFile imag
3433
// 게시글 수정하기
3534
@PatchMapping("/{postId}/edit")
3635
public Response<Object> editPost(@PathVariable("postId") Long postId,
37-
@RequestBody NewPostRequestDto newPostRequestDto){
38-
postService.editPost(postId, newPostRequestDto);
36+
@RequestBody PostRequestDto postRequestDto){
37+
postService.editPost(postId, postRequestDto);
3938
return Response.success("게시글 수정 성공.", null);
4039
}
4140

src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MyPostPageResponseDto {
2323
private int likeCount;
2424
private int forkCount;
2525
private String nickname;
26-
private String profileImageUrl;;
26+
private String profileImageUrl;
2727

2828
// 이미지 null일 때 default 사진으로 변경 - 프로필 사진
2929
public static String getDefaultProfile(String image){

src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/com/example/FixLog/exception/ErrorCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum ErrorCode {
2424
TAG_NOT_FOUND(HttpStatus.NOT_FOUND, "없는 태그 번호입니다."),
2525
SORT_NOT_EXIST(HttpStatus.BAD_REQUEST, "사용할 수 없는 정렬입니다."),
2626
INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지 않습니다."),
27-
POST_UPDATE_FORBIDDEN(HttpStatus.BAD_REQUEST, "본인 게시글만 수정할 수 있습니다."),
27+
POST_UPDATE_FORBIDDEN(HttpStatus.FORBIDDEN, "본인 게시글만 수정할 수 있습니다."),
2828
REQUIRED_TAGS_MISSING(HttpStatus.BAD_REQUEST, "태그를 선택해주세요."),
2929
REQUIRED_CONTENT_MISSING(HttpStatus.BAD_REQUEST, "필수 본문이 입력되지 않았습니다."),
3030
SAME_AS_OLD_PASSWORD(HttpStatus.BAD_REQUEST, "다른 비밀번호 입력 바랍니다."),

src/main/java/com/example/FixLog/service/PostService.java

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.example.FixLog.domain.post.PostTag;
99
import com.example.FixLog.domain.tag.Tag;
1010
import com.example.FixLog.domain.tag.TagCategory;
11-
import com.example.FixLog.dto.post.NewPostRequestDto;
1211
import com.example.FixLog.dto.post.PostDto;
1312
import com.example.FixLog.dto.post.PostRequestDto;
1413
import com.example.FixLog.dto.post.PostResponseDto;
@@ -150,20 +149,11 @@ else if (categories.size() > 1)
150149
// 게시글 필수 항목 다 작성했는지
151150
private void validatePost(PostRequestDto postRequestDto){
152151
if (!StringUtils.hasText(postRequestDto.getPostTitle())
153-
|| !StringUtils.hasText(postRequestDto.getProblem())
154-
|| !StringUtils.hasText(postRequestDto.getErrorMessage())
155-
|| !StringUtils.hasText(postRequestDto.getEnvironment())
156-
|| !StringUtils.hasText(postRequestDto.getReproduceCode())
157-
|| !StringUtils.hasText(postRequestDto.getSolutionCode()))
158-
throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING);
159-
}
160-
private void validatePost(NewPostRequestDto newPostRequestDto){
161-
if (!StringUtils.hasText(newPostRequestDto.getPostTitle())
162-
|| !StringUtils.hasText(newPostRequestDto.getProblem())
163-
|| !StringUtils.hasText(newPostRequestDto.getErrorMessage())
164-
|| !StringUtils.hasText(newPostRequestDto.getEnvironment())
165-
|| !StringUtils.hasText(newPostRequestDto.getReproduceCode())
166-
|| !StringUtils.hasText(newPostRequestDto.getSolutionCode()))
152+
|| !StringUtils.hasText(postRequestDto.getProblem())
153+
|| !StringUtils.hasText(postRequestDto.getErrorMessage())
154+
|| !StringUtils.hasText(postRequestDto.getEnvironment())
155+
|| !StringUtils.hasText(postRequestDto.getReproduceCode())
156+
|| !StringUtils.hasText(postRequestDto.getSolutionCode()))
167157
throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING);
168158
}
169159

@@ -182,7 +172,7 @@ public String uploadImage(MultipartFile imageFile){
182172

183173
// 게시글 수정하기
184174
@Transactional
185-
public void editPost(Long postId, NewPostRequestDto newPostRequestDto) {
175+
public void editPost(Long postId, PostRequestDto postRequestDto) {
186176
Member member = memberService.getCurrentMemberInfo();
187177
Post post = postRepository.findById(postId)
188178
.orElseThrow(() -> new CustomException(ErrorCode.POST_NOT_FOUND));
@@ -193,36 +183,36 @@ public void editPost(Long postId, NewPostRequestDto newPostRequestDto) {
193183
}
194184

195185
// 북마크 카테고리별로 선택 제한 두기
196-
List<Tag> tags = fetchAndValidateTags(newPostRequestDto.getTags());
186+
List<Tag> tags = fetchAndValidateTags(postRequestDto.getTags());
197187

198188
// 아무것도 변경이 없으면 예외처리
199-
if (Objects.equals(post.getPostTitle(), newPostRequestDto.getPostTitle())
200-
& Objects.equals(post.getCoverImage(), newPostRequestDto.getCoverImageUrl())
201-
& Objects.equals(post.getProblem(), newPostRequestDto.getProblem())
202-
& Objects.equals(post.getErrorMessage(), newPostRequestDto.getErrorMessage())
203-
& Objects.equals(post.getEnvironment(), newPostRequestDto.getEnvironment())
204-
& Objects.equals(post.getReproduceCode(), newPostRequestDto.getReproduceCode())
205-
& Objects.equals(post.getSolutionCode(), newPostRequestDto.getSolutionCode())
206-
& Objects.equals(post.getCauseAnalysis(), newPostRequestDto.getCauseAnalysis())
207-
& Objects.equals(post.getReferenceLink(), newPostRequestDto.getReferenceLink())
208-
& Objects.equals(post.getExtraContent(), newPostRequestDto.getExtraContent())
209-
& compareTags(post.getPostTags(), tags)){
189+
if (Objects.equals(post.getPostTitle(), postRequestDto.getPostTitle())
190+
&& Objects.equals(post.getCoverImage(), postRequestDto.getCoverImageUrl())
191+
&& Objects.equals(post.getProblem(), postRequestDto.getProblem())
192+
&& Objects.equals(post.getErrorMessage(), postRequestDto.getErrorMessage())
193+
&& Objects.equals(post.getEnvironment(), postRequestDto.getEnvironment())
194+
&& Objects.equals(post.getReproduceCode(), postRequestDto.getReproduceCode())
195+
&& Objects.equals(post.getSolutionCode(), postRequestDto.getSolutionCode())
196+
&& Objects.equals(post.getCauseAnalysis(), postRequestDto.getCauseAnalysis())
197+
&& Objects.equals(post.getReferenceLink(), postRequestDto.getReferenceLink())
198+
&& Objects.equals(post.getExtraContent(), postRequestDto.getExtraContent())
199+
&& compareTags(post.getPostTags(), tags)){
210200
throw new CustomException(ErrorCode.NO_CONTENT_CHANGED);
211201
}
212202

213203
// 필드 업데이트
214-
validatePost(newPostRequestDto);
215-
216-
post.changeTitle(newPostRequestDto.getPostTitle());
217-
post.changeCoverImage(newPostRequestDto.getCoverImageUrl());
218-
post.changeProblem(newPostRequestDto.getProblem());
219-
post.changeErrorMessage(newPostRequestDto.getErrorMessage());
220-
post.changeEnvironment(newPostRequestDto.getEnvironment());
221-
post.changeReproduceCode(newPostRequestDto.getReproduceCode());
222-
post.changeSolutionCode(newPostRequestDto.getSolutionCode());
223-
post.changeCauseAnalysis(newPostRequestDto.getCauseAnalysis());
224-
post.changeReferenceLink(newPostRequestDto.getReferenceLink());
225-
post.changeExtraContent(newPostRequestDto.getExtraContent());
204+
validatePost(postRequestDto);
205+
206+
post.changeTitle(postRequestDto.getPostTitle());
207+
post.changeCoverImage(postRequestDto.getCoverImageUrl());
208+
post.changeProblem(postRequestDto.getProblem());
209+
post.changeErrorMessage(postRequestDto.getErrorMessage());
210+
post.changeEnvironment(postRequestDto.getEnvironment());
211+
post.changeReproduceCode(postRequestDto.getReproduceCode());
212+
post.changeSolutionCode(postRequestDto.getSolutionCode());
213+
post.changeCauseAnalysis(postRequestDto.getCauseAnalysis());
214+
post.changeReferenceLink(postRequestDto.getReferenceLink());
215+
post.changeExtraContent(postRequestDto.getExtraContent());
226216
post.updateEditedAt(LocalDateTime.now());
227217

228218
// 태그 저장

0 commit comments

Comments
 (0)