From 49e8339576e8504aba7c3ce6a7c3b5e639cfbbcc Mon Sep 17 00:00:00 2001 From: semsemin Date: Mon, 23 Jun 2025 01:39:08 +0900 Subject: [PATCH 1/8] =?UTF-8?q?fix:#96-=EA=B8=B0=EB=B3=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/FixLog/dto/post/MyPostPageResponseDto.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java b/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java index 8bc8529..e83f70e 100644 --- a/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java +++ b/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java @@ -23,6 +23,13 @@ public class MyPostPageResponseDto { private int likeCount; private int forkCount; private String nickname; + private String profileImageUrl;; + + public static String getDefaultImage(String image) { + return (image == null || image.isBlank()) + ? "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png" + : image; + } public static MyPostPageResponseDto from(Post post, int forkCount) { return MyPostPageResponseDto.builder() @@ -30,7 +37,8 @@ public static MyPostPageResponseDto from(Post post, int forkCount) { .nickname(post.getUserId().getNickname()) .postTitle(post.getPostTitle()) .postSummary(generateSummary(post.getProblem())) - .imageUrl(post.getCoverImage()) + .imageUrl(getDefaultImage(post.getCoverImage())) + .profileImageUrl(getDefaultImage(post.getUserId().getProfileImageUrl())) .tags(post.getPostTags().stream().map(tag -> tag.getTagId().getTagName()).toList()) .createdAt(post.getCreatedAt()) .likeCount(post.getPostLikes().size()) From e7d0d4a5c412eedb467e42bdcd698c90cffca100 Mon Sep 17 00:00:00 2001 From: youngseo22 Date: Mon, 23 Jun 2025 11:20:25 +0900 Subject: [PATCH 2/8] =?UTF-8?q?fix(image)=20:=20#97=20-=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FixLog/service/MainPageService.java | 27 ++++++++++++------- .../example/FixLog/service/PostService.java | 19 ++++++++----- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/example/FixLog/service/MainPageService.java b/src/main/java/com/example/FixLog/service/MainPageService.java index 3b27b2d..cdc1ec5 100644 --- a/src/main/java/com/example/FixLog/service/MainPageService.java +++ b/src/main/java/com/example/FixLog/service/MainPageService.java @@ -27,13 +27,20 @@ public MainPageService(PostRepository postRepository, MemberService memberServic this.memberService = memberService; } - // 이미지 null일 때 default 사진으로 변경 (프로필 사진, - public String getDefaultImage(String image){ + // 이미지 null일 때 default 사진으로 변경 - 프로필 사진 + public String getDefaultProfile(String image){ String imageUrl = (image == null || image.isBlank()) ? "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png" : image; System.out.println(imageUrl); return imageUrl; } + // 이미지 null일 때 default 사진으로 변경 - 썸네일 + public String getDefaultCover(String image){ + String imageUrl = (image == null || image.isBlank()) + ? "https://core-cdn-fe.toss.im/image/optimize/?src=https://blog-cdn.tosspayments.com/wp-content/uploads/2021/08/28011146/semo9.png?&w=3840&q=75" : image; + System.out.println(imageUrl); + return imageUrl; + } // 메인페이지 보기 public MainPageResponseDto mainPageView(int sort, int size){ @@ -44,9 +51,9 @@ public MainPageResponseDto mainPageView(int sort, int size){ if (optionalMember.isPresent()) { Member member = optionalMember.get(); String imageUrl = member.getProfileImageUrl(); - profileImageUrl = getDefaultImage(imageUrl); + profileImageUrl = getDefaultProfile(imageUrl); } else { - profileImageUrl = "https://example.com/default-cover-image.png"; // 비로그인 기본 이미지 + profileImageUrl = "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png"; // 비로그인 기본 이미지 } // 페이지 (글 12개) 불러오기 @@ -67,11 +74,11 @@ public MainPageResponseDto mainPageView(int sort, int size){ List postList = posts.stream() .map(post -> new MainPagePostResponseDto( post.getPostTitle(), - getDefaultImage(post.getCoverImage()), + getDefaultCover(post.getCoverImage()), post.getPostTags().stream() .map(postTag -> postTag.getTagId().getTagName()) .collect(Collectors.toList()), - getDefaultImage(post.getUserId().getProfileImageUrl()), + getDefaultProfile(post.getUserId().getProfileImageUrl()), post.getUserId().getNickname(), post.getCreatedAt().toLocalDate(), post.getPostLikes().size() @@ -90,9 +97,9 @@ public MainPageResponseDto mainPageFullView(int sort, int page, int size){ if (optionalMember.isPresent()) { Member member = optionalMember.get(); String imageUrl = member.getProfileImageUrl(); - profileImageUrl = getDefaultImage(imageUrl); + profileImageUrl = getDefaultProfile(imageUrl); } else { - profileImageUrl = "https://example.com/default-cover-image.png"; // 비로그인 기본 이미지 + profileImageUrl = "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png"; // 비로그인 기본 이미지 } // 페이지 설정 (한 페이지당 12개) @@ -109,11 +116,11 @@ public MainPageResponseDto mainPageFullView(int sort, int page, int size){ List postList = postPage.stream() .map(post -> new MainPagePostResponseDto( post.getPostTitle(), - getDefaultImage(post.getCoverImage()), + getDefaultCover(post.getCoverImage()), post.getPostTags().stream() .map(postTag -> postTag.getTagId().getTagName()) .collect(Collectors.toList()), - getDefaultImage(post.getUserId().getProfileImageUrl()), + getDefaultProfile(post.getUserId().getProfileImageUrl()), post.getUserId().getNickname(), post.getCreatedAt().toLocalDate(), post.getPostLikes().size() diff --git a/src/main/java/com/example/FixLog/service/PostService.java b/src/main/java/com/example/FixLog/service/PostService.java index 6970fe5..8aeccc1 100644 --- a/src/main/java/com/example/FixLog/service/PostService.java +++ b/src/main/java/com/example/FixLog/service/PostService.java @@ -20,9 +20,9 @@ import com.example.FixLog.repository.post.PostRepository; import com.example.FixLog.repository.tag.TagRepository; import jakarta.transaction.Transactional; -import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; import java.time.LocalDate; @@ -55,13 +55,20 @@ public PostService(PostRepository postRepository, PostLikeRepository postLikeRep this.s3Service = s3Service; } - // 이미지 null일 때 default 사진으로 변경 (프로필 사진, - public String getDefaultImage(String image){ + // 이미지 null일 때 default 사진으로 변경 - 프로필 사진 + public String getDefaultProfile(String image){ String imageUrl = (image == null || image.isBlank()) ? "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png" : image; System.out.println(imageUrl); return imageUrl; } + // 이미지 null일 때 default 사진으로 변경 - 썸네일 + public String getDefaultCover(String image){ + String imageUrl = (image == null || image.isBlank()) + ? "https://core-cdn-fe.toss.im/image/optimize/?src=https://blog-cdn.tosspayments.com/wp-content/uploads/2021/08/28011146/semo9.png?&w=3840&q=75" : image; + System.out.println(imageUrl); + return imageUrl; + } // 게시글 작성하기 @Transactional @@ -233,7 +240,7 @@ public PostResponseDto viewPost(Long postId){ currentPost.getUserId().getUserId(), currentPost.getUserId().getNickname(), currentPost.getPostTitle(), - getDefaultImage(currentPost.getCoverImage()), + getDefaultCover(currentPost.getCoverImage()), currentPost.getProblem(), currentPost.getErrorMessage(), currentPost.getEnvironment(), @@ -253,7 +260,7 @@ public PostResponseDto viewPost(Long postId){ Member member = optionalMember.get(); nickname = member.getNickname(); String imageUrl = member.getProfileImageUrl(); - profileImageUrl = getDefaultImage(imageUrl); + profileImageUrl = getDefaultProfile(imageUrl); isLiked = currentPost.getPostLikes().stream() .anyMatch(postLike -> postLike.getUserId().equals(member)); @@ -261,7 +268,7 @@ public PostResponseDto viewPost(Long postId){ .anyMatch(bookmark -> bookmark.getFolderId().getUserId().equals(member)); } else { nickname = "로그인하지 않았습니다."; - profileImageUrl = "https://example.com/default-cover-image.png"; // 비로그인 기본 이미지 + profileImageUrl = "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png"; // 비로그인 기본 이미지 isLiked = false; isMarked = false; } From 7be13b5a10ce7e370f9b4f8813a2778f712868ac Mon Sep 17 00:00:00 2001 From: youngseo22 Date: Mon, 23 Jun 2025 11:23:58 +0900 Subject: [PATCH 3/8] =?UTF-8?q?fix(eidt=20post)=20:=20=ED=95=84=EC=88=98?= =?UTF-8?q?=20=ED=95=AD=EB=AA=A9=20=EC=9E=91=EC=84=B1=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?,=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=9E=91=EC=84=B1=EC=9E=90?= =?UTF-8?q?=20=EB=B3=B8=EC=9D=B8=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/FixLog/exception/ErrorCode.java | 1 + .../example/FixLog/service/PostService.java | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/FixLog/exception/ErrorCode.java b/src/main/java/com/example/FixLog/exception/ErrorCode.java index db86c04..d1eeb1a 100644 --- a/src/main/java/com/example/FixLog/exception/ErrorCode.java +++ b/src/main/java/com/example/FixLog/exception/ErrorCode.java @@ -24,6 +24,7 @@ public enum ErrorCode { TAG_NOT_FOUND(HttpStatus.NOT_FOUND, "없는 태그 번호입니다."), SORT_NOT_EXIST(HttpStatus.BAD_REQUEST, "사용할 수 없는 정렬입니다."), INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지 않습니다."), + POST_UPDATE_FORBIDDEN(HttpStatus.BAD_REQUEST, "본인 게시글만 수정할 수 있습니다."), REQUIRED_TAGS_MISSING(HttpStatus.BAD_REQUEST, "태그를 선택해주세요."), REQUIRED_CONTENT_MISSING(HttpStatus.BAD_REQUEST, "필수 본문이 입력되지 않았습니다."), SAME_AS_OLD_PASSWORD(HttpStatus.BAD_REQUEST, "다른 비밀번호 입력 바랍니다."), diff --git a/src/main/java/com/example/FixLog/service/PostService.java b/src/main/java/com/example/FixLog/service/PostService.java index 8aeccc1..797ae3d 100644 --- a/src/main/java/com/example/FixLog/service/PostService.java +++ b/src/main/java/com/example/FixLog/service/PostService.java @@ -151,15 +151,21 @@ else if (categories.size() > 1) // 게시글 필수 항목 다 작성했는지 private void validatePost(PostRequestDto postRequestDto){ - if (postRequestDto.getPostTitle().isBlank() | postRequestDto.getProblem().isBlank() - | postRequestDto.getErrorMessage().isBlank() | postRequestDto.getEnvironment().isBlank() - | postRequestDto.getReproduceCode().isBlank() | postRequestDto.getSolutionCode().isBlank()) + if (!StringUtils.hasText(postRequestDto.getPostTitle()) + || !StringUtils.hasText(postRequestDto.getProblem()) + || !StringUtils.hasText(postRequestDto.getErrorMessage()) + || !StringUtils.hasText(postRequestDto.getEnvironment()) + || !StringUtils.hasText(postRequestDto.getReproduceCode()) + || !StringUtils.hasText(postRequestDto.getSolutionCode())) throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING); } private void validatePost(NewPostRequestDto newPostRequestDto){ - if (newPostRequestDto.getPostTitle().isBlank() | newPostRequestDto.getProblem().isBlank() - | newPostRequestDto.getErrorMessage().isBlank() | newPostRequestDto.getEnvironment().isBlank() - | newPostRequestDto.getReproduceCode().isBlank() | newPostRequestDto.getSolutionCode().isBlank()) + if (!StringUtils.hasText(newPostRequestDto.getPostTitle()) + || !StringUtils.hasText(newPostRequestDto.getProblem()) + || !StringUtils.hasText(newPostRequestDto.getErrorMessage()) + || !StringUtils.hasText(newPostRequestDto.getEnvironment()) + || !StringUtils.hasText(newPostRequestDto.getReproduceCode()) + || !StringUtils.hasText(newPostRequestDto.getSolutionCode())) throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING); } @@ -176,12 +182,18 @@ public String uploadImage(MultipartFile imageFile){ return "![image](" + imageUrl + ")"; } + // 게시글 수정하기 @Transactional public void editPost(Long postId, NewPostRequestDto newPostRequestDto) { Member member = memberService.getCurrentMemberInfo(); Post post = postRepository.findById(postId) .orElseThrow(() -> new CustomException(ErrorCode.POST_NOT_FOUND)); + // 게시글 작성자가 본인이 맞는지 + if (!member.getUserId().equals(post.getUserId().getUserId())) { + throw new CustomException(ErrorCode.POST_UPDATE_FORBIDDEN); + } + // 북마크 카테고리별로 선택 제한 두기 List tags = fetchAndValidateTags(newPostRequestDto.getTags()); @@ -201,6 +213,8 @@ & compareTags(post.getPostTags(), tags)){ } // 필드 업데이트 + validatePost(newPostRequestDto); + post.changeTitle(newPostRequestDto.getPostTitle()); post.changeCoverImage(newPostRequestDto.getCoverImageUrl()); post.changeProblem(newPostRequestDto.getProblem()); From 7edda349dd6bd01fd58b97316f6d611aa12868fc Mon Sep 17 00:00:00 2001 From: youngseo22 Date: Mon, 23 Jun 2025 12:23:18 +0900 Subject: [PATCH 4/8] =?UTF-8?q?fix(coverImage)=20:=20#96=20-=20=EC=8D=B8?= =?UTF-8?q?=EB=84=A4=EC=9D=BC=20=EB=A7=81=ED=81=AC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/FixLog/service/MainPageService.java | 2 +- src/main/java/com/example/FixLog/service/PostService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/FixLog/service/MainPageService.java b/src/main/java/com/example/FixLog/service/MainPageService.java index cdc1ec5..9c8ff00 100644 --- a/src/main/java/com/example/FixLog/service/MainPageService.java +++ b/src/main/java/com/example/FixLog/service/MainPageService.java @@ -37,7 +37,7 @@ public String getDefaultProfile(String image){ // 이미지 null일 때 default 사진으로 변경 - 썸네일 public String getDefaultCover(String image){ String imageUrl = (image == null || image.isBlank()) - ? "https://core-cdn-fe.toss.im/image/optimize/?src=https://blog-cdn.tosspayments.com/wp-content/uploads/2021/08/28011146/semo9.png?&w=3840&q=75" : image; + ? "https://fixlogsmwubucket.s3.ap-northeast-2.amazonaws.com/default/DefaulThumnail.png" : image; System.out.println(imageUrl); return imageUrl; } diff --git a/src/main/java/com/example/FixLog/service/PostService.java b/src/main/java/com/example/FixLog/service/PostService.java index 797ae3d..720178e 100644 --- a/src/main/java/com/example/FixLog/service/PostService.java +++ b/src/main/java/com/example/FixLog/service/PostService.java @@ -65,7 +65,7 @@ public String getDefaultProfile(String image){ // 이미지 null일 때 default 사진으로 변경 - 썸네일 public String getDefaultCover(String image){ String imageUrl = (image == null || image.isBlank()) - ? "https://core-cdn-fe.toss.im/image/optimize/?src=https://blog-cdn.tosspayments.com/wp-content/uploads/2021/08/28011146/semo9.png?&w=3840&q=75" : image; + ? "https://fixlogsmwubucket.s3.ap-northeast-2.amazonaws.com/default/DefaulThumnail.png" : image; System.out.println(imageUrl); return imageUrl; } From 62124801a849573eaea357a75288e8308aff5860 Mon Sep 17 00:00:00 2001 From: youngseo22 Date: Mon, 23 Jun 2025 13:09:07 +0900 Subject: [PATCH 5/8] =?UTF-8?q?fix(image)=20:=20#96=20-=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/post/MyPostPageResponseDto.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java b/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java index e83f70e..49db433 100644 --- a/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java +++ b/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java @@ -25,10 +25,19 @@ public class MyPostPageResponseDto { private String nickname; private String profileImageUrl;; - public static String getDefaultImage(String image) { - return (image == null || image.isBlank()) - ? "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png" - : image; + // 이미지 null일 때 default 사진으로 변경 - 프로필 사진 + public static String getDefaultProfile(String image){ + String imageUrl = (image == null || image.isBlank()) + ? "https://fixlog-bucket.s3.ap-northeast-2.amazonaws.com/default/profile.png" : image; + System.out.println(imageUrl); + return imageUrl; + } + // 이미지 null일 때 default 사진으로 변경 - 썸네일 + public static String getDefaultCover(String image){ + String imageUrl = (image == null || image.isBlank()) + ? "https://fixlogsmwubucket.s3.ap-northeast-2.amazonaws.com/default/DefaulThumnail.png" : image; + System.out.println(imageUrl); + return imageUrl; } public static MyPostPageResponseDto from(Post post, int forkCount) { @@ -37,8 +46,8 @@ public static MyPostPageResponseDto from(Post post, int forkCount) { .nickname(post.getUserId().getNickname()) .postTitle(post.getPostTitle()) .postSummary(generateSummary(post.getProblem())) - .imageUrl(getDefaultImage(post.getCoverImage())) - .profileImageUrl(getDefaultImage(post.getUserId().getProfileImageUrl())) + .imageUrl(getDefaultCover(post.getCoverImage())) + .profileImageUrl(getDefaultProfile(post.getUserId().getProfileImageUrl())) .tags(post.getPostTags().stream().map(tag -> tag.getTagId().getTagName()).toList()) .createdAt(post.getCreatedAt()) .likeCount(post.getPostLikes().size()) From 7276827f5e6d146d5f14a6b9c62ce939d87313c2 Mon Sep 17 00:00:00 2001 From: youngseo22 Date: Mon, 23 Jun 2025 13:26:54 +0900 Subject: [PATCH 6/8] =?UTF-8?q?fix(post)=20:=20=ED=83=9C=EA=B7=B8=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EB=B0=8F=20=ED=83=9C=EA=B7=B8=20=EB=AA=A9?= =?UTF-8?q?=EC=97=85=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/FixLog/domain/tag/Tag.java | 8 ++- .../FixLog/dto/post/NewPostRequestDto.java | 2 +- .../FixLog/dto/post/PostRequestDto.java | 2 +- .../FixLog/exception/CustomException.java | 11 ++- .../FixLog/mock/TagMockDataInitializer.java | 67 ++++++++++--------- .../FixLog/repository/tag/TagRepository.java | 3 + .../example/FixLog/service/PostService.java | 14 ++-- 7 files changed, 62 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/example/FixLog/domain/tag/Tag.java b/src/main/java/com/example/FixLog/domain/tag/Tag.java index 69fa2b6..c4297d4 100644 --- a/src/main/java/com/example/FixLog/domain/tag/Tag.java +++ b/src/main/java/com/example/FixLog/domain/tag/Tag.java @@ -21,9 +21,15 @@ public class Tag { @Column(length = 20, nullable = false) private String tagName; - @Column(nullable = false) private String tagInfo; + public static Tag of(TagCategory tagCategory, String tagName) { + Tag tag = new Tag(); + tag.tagCategory = tagCategory; + tag.tagName = tagName; + return tag; + } + public static Tag of(TagCategory tagCategory, String tagName, String tagInfo) { Tag tag = new Tag(); tag.tagCategory = tagCategory; diff --git a/src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java b/src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java index 34c4696..518084d 100644 --- a/src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java +++ b/src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java @@ -17,5 +17,5 @@ public class NewPostRequestDto { private String referenceLink; private String extraContent; - private List tags; + private List tags; } diff --git a/src/main/java/com/example/FixLog/dto/post/PostRequestDto.java b/src/main/java/com/example/FixLog/dto/post/PostRequestDto.java index 558c662..6efad06 100644 --- a/src/main/java/com/example/FixLog/dto/post/PostRequestDto.java +++ b/src/main/java/com/example/FixLog/dto/post/PostRequestDto.java @@ -17,5 +17,5 @@ public class PostRequestDto { private String referenceLink; private String extraContent; - private List tags; + private List tags; } diff --git a/src/main/java/com/example/FixLog/exception/CustomException.java b/src/main/java/com/example/FixLog/exception/CustomException.java index 3c61011..4db97c7 100644 --- a/src/main/java/com/example/FixLog/exception/CustomException.java +++ b/src/main/java/com/example/FixLog/exception/CustomException.java @@ -4,7 +4,16 @@ import lombok.RequiredArgsConstructor; @Getter -@RequiredArgsConstructor public class CustomException extends RuntimeException { private final ErrorCode errorCode; + + public CustomException(ErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } + + public CustomException(ErrorCode errorCode, String detailMessage) { + super(detailMessage); + this.errorCode = errorCode; + } } diff --git a/src/main/java/com/example/FixLog/mock/TagMockDataInitializer.java b/src/main/java/com/example/FixLog/mock/TagMockDataInitializer.java index 51d3ee9..7284d14 100644 --- a/src/main/java/com/example/FixLog/mock/TagMockDataInitializer.java +++ b/src/main/java/com/example/FixLog/mock/TagMockDataInitializer.java @@ -32,45 +32,46 @@ public void run(String... args) { List tagsToInsert = new ArrayList<>(); // BIG_CATEGORY - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(BIG_CATEGORY, "백엔드", "backend")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(BIG_CATEGORY, "머신러닝", "machine learning")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(BIG_CATEGORY, "프론트엔드", "frontend")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(BIG_CATEGORY, "backend")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(BIG_CATEGORY, "machine-learning")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(BIG_CATEGORY, "frontend")); // MAJOR_CATEGORY - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "장고", "django")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "스프링부트", "spring-boot")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "넥스트", "next.js")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "케라스", "keras")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "파이토치", "pytorch")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "사이킷런", "scikit-learn")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "노드", "node.js")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "리액트", "react")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "리액트 네이티브", "react-native")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "django")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "spring-boot")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "next.js")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "keras")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "pytorch")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "scikit-learn")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "node.js")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "react")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MAJOR_CATEGORY, "react-native")); // MIDDLE_CATEGORY - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "CSS", "css")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "자바스크립트", "javascript")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "R", "r")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "JSON", "json")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "자바", "java")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "Haskell", "haskell")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "파이썬", "python")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "C", "c")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "css")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "javascript")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "r")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "json")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "java")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "haskell")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "python")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MIDDLE_CATEGORY, "c")); // MINOR_CATEGORY - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "NullPointerException", "null-pointer-exception")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "500 Internal Server Error", "500-error")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "CORS 정책 오류", "cors-error")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "Database connection timeout", "db-timeout")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "ClassNotFoundException", "class-not-found")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "Cannot read property of undefined", "undefined-property")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "상태(state) 업데이트 누락", "state-missing")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "HTTP 에러", "http-error")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "렌더링 무한 루프", "render-loop")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "스타일 깨짐", "style-break")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "404 Not Found", "404-error")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "Permission Error", "permission-error")); - addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "OutOfMemoryError", "out-of-memory")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "null-pointer-exception", "NullPointerException")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "500-error", "500 Internal Server Error")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "cors-error", "CORS 정책 오류")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "db-timeout", "Database connection timeout")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "class-not-found", "ClassNotFoundException")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "undefined-property", "Cannot read property of undefined")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "state-missing", "상태(state) 업데이트 누락")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "http-error", "HTTP 에러")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "render-loop", "렌더링 무한 루프")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "style-break", "스타일 깨짐")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "404-error", "404 Not Found")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "permission-error", "Permission Error")); + addIfNotExist(tagsToInsert, existingTagNames, Tag.of(MINOR_CATEGORY, "out-of-memory", "OutOfMemoryError")); + if (!tagsToInsert.isEmpty()) { tagRepository.saveAll(tagsToInsert); diff --git a/src/main/java/com/example/FixLog/repository/tag/TagRepository.java b/src/main/java/com/example/FixLog/repository/tag/TagRepository.java index 29ef940..af00f35 100644 --- a/src/main/java/com/example/FixLog/repository/tag/TagRepository.java +++ b/src/main/java/com/example/FixLog/repository/tag/TagRepository.java @@ -5,6 +5,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface TagRepository extends JpaRepository { Page findAll(Pageable pageable); + Optional findByTagName(String tagName); } diff --git a/src/main/java/com/example/FixLog/service/PostService.java b/src/main/java/com/example/FixLog/service/PostService.java index 720178e..0898abc 100644 --- a/src/main/java/com/example/FixLog/service/PostService.java +++ b/src/main/java/com/example/FixLog/service/PostService.java @@ -108,10 +108,10 @@ public void createPost(PostRequestDto postRequestDto){ } // 태그 다 선택 했는지 - private List fetchAndValidateTags(List tagIds){ - // 태그 ID로 Tag 엔티티 조회 - List tags = tagIds.stream() - .map(tagId -> tagRepository.findById(tagId) + private List fetchAndValidateTags(List tagNames){ + // 태그 이름으로 Tag 엔티티 조회 + List tags = tagNames.stream() + .map(tagName -> tagRepository.findByTagName(tagName) .orElseThrow(() -> new CustomException(ErrorCode.TAG_NOT_FOUND))) .toList(); @@ -141,10 +141,8 @@ else if (categories.size() > 1) } if (!issues.isEmpty()) { - throw new CustomException(ErrorCode.REQUIRED_TAGS_MISSING); - // throw new CustomException(ErrorCode.REQUIRED_TAGS_MISSING, String.join(", ", issues)); - // throw new CustomException(ErrorCode.REQUIRED_TAGS_MISSING.withDetail(missingTypes.toString())); - // Todo 어떤 태그가 선택 안된건지 보여지도록 수정 + String message = String.join(" / ", issues); + throw new CustomException(ErrorCode.REQUIRED_TAGS_MISSING, message); } return tags; } From d2ec52b6fa0ba0785e21430359e33a0b38066347 Mon Sep 17 00:00:00 2001 From: youngseo22 Date: Mon, 23 Jun 2025 13:56:10 +0900 Subject: [PATCH 7/8] =?UTF-8?q?style=20:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/post/MyPostPageResponseDto.java | 2 +- .../example/FixLog/exception/ErrorCode.java | 2 +- .../example/FixLog/service/PostService.java | 41 ++++++++----------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java b/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java index 49db433..7a94dbe 100644 --- a/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java +++ b/src/main/java/com/example/FixLog/dto/post/MyPostPageResponseDto.java @@ -23,7 +23,7 @@ public class MyPostPageResponseDto { private int likeCount; private int forkCount; private String nickname; - private String profileImageUrl;; + private String profileImageUrl; // 이미지 null일 때 default 사진으로 변경 - 프로필 사진 public static String getDefaultProfile(String image){ diff --git a/src/main/java/com/example/FixLog/exception/ErrorCode.java b/src/main/java/com/example/FixLog/exception/ErrorCode.java index d1eeb1a..9e64cb0 100644 --- a/src/main/java/com/example/FixLog/exception/ErrorCode.java +++ b/src/main/java/com/example/FixLog/exception/ErrorCode.java @@ -24,7 +24,7 @@ public enum ErrorCode { TAG_NOT_FOUND(HttpStatus.NOT_FOUND, "없는 태그 번호입니다."), SORT_NOT_EXIST(HttpStatus.BAD_REQUEST, "사용할 수 없는 정렬입니다."), INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지 않습니다."), - POST_UPDATE_FORBIDDEN(HttpStatus.BAD_REQUEST, "본인 게시글만 수정할 수 있습니다."), + POST_UPDATE_FORBIDDEN(HttpStatus.FORBIDDEN, "본인 게시글만 수정할 수 있습니다."), REQUIRED_TAGS_MISSING(HttpStatus.BAD_REQUEST, "태그를 선택해주세요."), REQUIRED_CONTENT_MISSING(HttpStatus.BAD_REQUEST, "필수 본문이 입력되지 않았습니다."), SAME_AS_OLD_PASSWORD(HttpStatus.BAD_REQUEST, "다른 비밀번호 입력 바랍니다."), diff --git a/src/main/java/com/example/FixLog/service/PostService.java b/src/main/java/com/example/FixLog/service/PostService.java index 0898abc..5e71dca 100644 --- a/src/main/java/com/example/FixLog/service/PostService.java +++ b/src/main/java/com/example/FixLog/service/PostService.java @@ -150,20 +150,11 @@ else if (categories.size() > 1) // 게시글 필수 항목 다 작성했는지 private void validatePost(PostRequestDto postRequestDto){ if (!StringUtils.hasText(postRequestDto.getPostTitle()) - || !StringUtils.hasText(postRequestDto.getProblem()) - || !StringUtils.hasText(postRequestDto.getErrorMessage()) - || !StringUtils.hasText(postRequestDto.getEnvironment()) - || !StringUtils.hasText(postRequestDto.getReproduceCode()) - || !StringUtils.hasText(postRequestDto.getSolutionCode())) - throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING); - } - private void validatePost(NewPostRequestDto newPostRequestDto){ - if (!StringUtils.hasText(newPostRequestDto.getPostTitle()) - || !StringUtils.hasText(newPostRequestDto.getProblem()) - || !StringUtils.hasText(newPostRequestDto.getErrorMessage()) - || !StringUtils.hasText(newPostRequestDto.getEnvironment()) - || !StringUtils.hasText(newPostRequestDto.getReproduceCode()) - || !StringUtils.hasText(newPostRequestDto.getSolutionCode())) + || !StringUtils.hasText(postRequestDto.getProblem()) + || !StringUtils.hasText(postRequestDto.getErrorMessage()) + || !StringUtils.hasText(postRequestDto.getEnvironment()) + || !StringUtils.hasText(postRequestDto.getReproduceCode()) + || !StringUtils.hasText(postRequestDto.getSolutionCode())) throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING); } @@ -196,17 +187,17 @@ public void editPost(Long postId, NewPostRequestDto newPostRequestDto) { List tags = fetchAndValidateTags(newPostRequestDto.getTags()); // 아무것도 변경이 없으면 예외처리 - if (Objects.equals(post.getPostTitle(), newPostRequestDto.getPostTitle()) - & Objects.equals(post.getCoverImage(), newPostRequestDto.getCoverImageUrl()) - & Objects.equals(post.getProblem(), newPostRequestDto.getProblem()) - & Objects.equals(post.getErrorMessage(), newPostRequestDto.getErrorMessage()) - & Objects.equals(post.getEnvironment(), newPostRequestDto.getEnvironment()) - & Objects.equals(post.getReproduceCode(), newPostRequestDto.getReproduceCode()) - & Objects.equals(post.getSolutionCode(), newPostRequestDto.getSolutionCode()) - & Objects.equals(post.getCauseAnalysis(), newPostRequestDto.getCauseAnalysis()) - & Objects.equals(post.getReferenceLink(), newPostRequestDto.getReferenceLink()) - & Objects.equals(post.getExtraContent(), newPostRequestDto.getExtraContent()) - & compareTags(post.getPostTags(), tags)){ + if (Objects.equals(post.getPostTitle(), postRequestDto.getPostTitle()) + && Objects.equals(post.getCoverImage(), postRequestDto.getCoverImageUrl()) + && Objects.equals(post.getProblem(), postRequestDto.getProblem()) + && Objects.equals(post.getErrorMessage(), postRequestDto.getErrorMessage()) + && Objects.equals(post.getEnvironment(), postRequestDto.getEnvironment()) + && Objects.equals(post.getReproduceCode(), postRequestDto.getReproduceCode()) + && Objects.equals(post.getSolutionCode(), postRequestDto.getSolutionCode()) + && Objects.equals(post.getCauseAnalysis(), postRequestDto.getCauseAnalysis()) + && Objects.equals(post.getReferenceLink(), postRequestDto.getReferenceLink()) + && Objects.equals(post.getExtraContent(), postRequestDto.getExtraContent()) + && compareTags(post.getPostTags(), tags)){ throw new CustomException(ErrorCode.NO_CONTENT_CHANGED); } From 0ac9ff27094436e4910e2f6c15e47da814743353 Mon Sep 17 00:00:00 2001 From: youngseo22 Date: Mon, 23 Jun 2025 13:56:37 +0900 Subject: [PATCH 8/8] =?UTF-8?q?fix(edit=20post)=20:=20dto=20=ED=95=98?= =?UTF-8?q?=EB=82=98=EB=A1=9C=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FixLog/controller/PostController.java | 5 ++-- .../FixLog/dto/post/NewPostRequestDto.java | 21 -------------- .../example/FixLog/service/PostService.java | 29 +++++++++---------- 3 files changed, 16 insertions(+), 39 deletions(-) delete mode 100644 src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java diff --git a/src/main/java/com/example/FixLog/controller/PostController.java b/src/main/java/com/example/FixLog/controller/PostController.java index 9497952..84d6601 100644 --- a/src/main/java/com/example/FixLog/controller/PostController.java +++ b/src/main/java/com/example/FixLog/controller/PostController.java @@ -1,6 +1,5 @@ package com.example.FixLog.controller; -import com.example.FixLog.dto.post.NewPostRequestDto; import com.example.FixLog.dto.post.PostRequestDto; import com.example.FixLog.dto.Response; import com.example.FixLog.dto.post.PostResponseDto; @@ -34,8 +33,8 @@ public Response uploadImage(@RequestPart("imageFile") MultipartFile imag // 게시글 수정하기 @PatchMapping("/{postId}/edit") public Response editPost(@PathVariable("postId") Long postId, - @RequestBody NewPostRequestDto newPostRequestDto){ - postService.editPost(postId, newPostRequestDto); + @RequestBody PostRequestDto postRequestDto){ + postService.editPost(postId, postRequestDto); return Response.success("게시글 수정 성공.", null); } diff --git a/src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java b/src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java deleted file mode 100644 index 518084d..0000000 --- a/src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.FixLog.dto.post; - -import lombok.Getter; - -import java.util.List; - -@Getter -public class NewPostRequestDto { - private String postTitle; - private String coverImageUrl; - private String problem; - private String errorMessage; - private String environment; - private String reproduceCode; - private String solutionCode; - private String causeAnalysis; - private String referenceLink; - private String extraContent; - - private List tags; -} diff --git a/src/main/java/com/example/FixLog/service/PostService.java b/src/main/java/com/example/FixLog/service/PostService.java index 5e71dca..2197a18 100644 --- a/src/main/java/com/example/FixLog/service/PostService.java +++ b/src/main/java/com/example/FixLog/service/PostService.java @@ -8,7 +8,6 @@ import com.example.FixLog.domain.post.PostTag; import com.example.FixLog.domain.tag.Tag; import com.example.FixLog.domain.tag.TagCategory; -import com.example.FixLog.dto.post.NewPostRequestDto; import com.example.FixLog.dto.post.PostDto; import com.example.FixLog.dto.post.PostRequestDto; import com.example.FixLog.dto.post.PostResponseDto; @@ -173,7 +172,7 @@ public String uploadImage(MultipartFile imageFile){ // 게시글 수정하기 @Transactional - public void editPost(Long postId, NewPostRequestDto newPostRequestDto) { + public void editPost(Long postId, PostRequestDto postRequestDto) { Member member = memberService.getCurrentMemberInfo(); Post post = postRepository.findById(postId) .orElseThrow(() -> new CustomException(ErrorCode.POST_NOT_FOUND)); @@ -184,7 +183,7 @@ public void editPost(Long postId, NewPostRequestDto newPostRequestDto) { } // 북마크 카테고리별로 선택 제한 두기 - List tags = fetchAndValidateTags(newPostRequestDto.getTags()); + List tags = fetchAndValidateTags(postRequestDto.getTags()); // 아무것도 변경이 없으면 예외처리 if (Objects.equals(post.getPostTitle(), postRequestDto.getPostTitle()) @@ -202,18 +201,18 @@ && compareTags(post.getPostTags(), tags)){ } // 필드 업데이트 - validatePost(newPostRequestDto); - - post.changeTitle(newPostRequestDto.getPostTitle()); - post.changeCoverImage(newPostRequestDto.getCoverImageUrl()); - post.changeProblem(newPostRequestDto.getProblem()); - post.changeErrorMessage(newPostRequestDto.getErrorMessage()); - post.changeEnvironment(newPostRequestDto.getEnvironment()); - post.changeReproduceCode(newPostRequestDto.getReproduceCode()); - post.changeSolutionCode(newPostRequestDto.getSolutionCode()); - post.changeCauseAnalysis(newPostRequestDto.getCauseAnalysis()); - post.changeReferenceLink(newPostRequestDto.getReferenceLink()); - post.changeExtraContent(newPostRequestDto.getExtraContent()); + validatePost(postRequestDto); + + post.changeTitle(postRequestDto.getPostTitle()); + post.changeCoverImage(postRequestDto.getCoverImageUrl()); + post.changeProblem(postRequestDto.getProblem()); + post.changeErrorMessage(postRequestDto.getErrorMessage()); + post.changeEnvironment(postRequestDto.getEnvironment()); + post.changeReproduceCode(postRequestDto.getReproduceCode()); + post.changeSolutionCode(postRequestDto.getSolutionCode()); + post.changeCauseAnalysis(postRequestDto.getCauseAnalysis()); + post.changeReferenceLink(postRequestDto.getReferenceLink()); + post.changeExtraContent(postRequestDto.getExtraContent()); post.updateEditedAt(LocalDateTime.now()); // 태그 저장