From 05b03cd8b99a47ee7cd3d1c6d66c18c691df1970 Mon Sep 17 00:00:00 2001 From: Jeyong Date: Mon, 21 Apr 2025 13:38:20 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=20DTO=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80=20(=EC=9E=91?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=97=AC=EB=B6=80,=20id)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/Recruitment/dto/response/CommentResponse.java | 6 +++++- .../dto/response/RecruitmentDetailResponse.java | 9 +++++++-- .../Recruitment/dto/response/RecruitmentResponse.java | 6 +++++- .../domain/Recruitment/service/RecruitmentService.java | 7 +++---- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java index fd254f1..00c4385 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java @@ -11,6 +11,8 @@ public class CommentResponse { private Long commentId; + private Long authorId; + private String authorName; private String content; @@ -20,8 +22,9 @@ public class CommentResponse { private LocalDateTime updatedAt; @Builder - private CommentResponse(Long commentId, String authorName, String content, LocalDateTime createdAt, LocalDateTime updatedAt) { + private CommentResponse(Long commentId, Long authorId, String authorName, String content, LocalDateTime createdAt, LocalDateTime updatedAt) { this.commentId = commentId; + this.authorId = authorId; this.authorName = authorName; this.content = content; this.createdAt = createdAt; @@ -31,6 +34,7 @@ private CommentResponse(Long commentId, String authorName, String content, Local public static CommentResponse of(Comment comment) { return CommentResponse.builder() .commentId(comment.getCommentId()) + .authorId(comment.getAuthor().getUserId()) .authorName(comment.getAuthor().getName()) .authorName(comment.getAuthor().getName()) .content(comment.getContent()) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java index 083fe2a..2459ca3 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java @@ -3,6 +3,7 @@ import MathCaptain.weakness.domain.Group.enums.CategoryStatus; import MathCaptain.weakness.domain.Recruitment.entity.Recruitment; import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus; +import MathCaptain.weakness.domain.User.entity.Users; import lombok.*; import java.time.LocalDateTime; @@ -34,10 +35,12 @@ public class RecruitmentDetailResponse { private List comments; + private boolean isAuthor; + @Builder private RecruitmentDetailResponse(Long authorId, Long recruitGroupId, String authorName, String recruitGroupName, String title, CategoryStatus category, String content, RecruitmentStatus recruitmentStatus, - LocalDateTime createdAt, LocalDateTime updatedAt, List comments) { + LocalDateTime createdAt, LocalDateTime updatedAt, List comments, boolean isAuthor) { this.authorId = authorId; this.recruitGroupId = recruitGroupId; this.authorName = authorName; @@ -49,9 +52,10 @@ private RecruitmentDetailResponse(Long authorId, Long recruitGroupId, String aut this.createdAt = createdAt; this.updatedAt = updatedAt; this.comments = comments; + this.isAuthor = isAuthor; } - public static RecruitmentDetailResponse of(Recruitment recruitment, List comments) { + public static RecruitmentDetailResponse of(Recruitment recruitment, List comments, Users loginUser) { return RecruitmentDetailResponse.builder() .authorId(recruitment.getAuthor().getUserId()) .recruitGroupId(recruitment.getRecruitGroup().getId()) @@ -64,6 +68,7 @@ public static RecruitmentDetailResponse of(Recruitment recruitment, List getRecruitment(Long recruitmentId) { + public ApiResponse getRecruitment(Long recruitmentId, Users loginUser) { Recruitment recruitment = findRecruitmentBy(recruitmentId); List comments = commentService.getComments(recruitmentId); - return ApiResponse.ok(RecruitmentDetailResponse.of(recruitment, comments)); + return ApiResponse.ok(RecruitmentDetailResponse.of(recruitment, comments, loginUser)); } // 모집글 수정 From b78875c79463c55e81a3da2a006f9fd7a721a50a Mon Sep 17 00:00:00 2001 From: Jeyong Date: Mon, 21 Apr 2025 13:38:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[refactor]=20=EC=BB=AC=EB=9F=BC=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RecruitmentController.java | 7 ++-- .../domain/Recruitment/entity/Comment.java | 2 +- .../Recruitment/entity/Recruitment.java | 2 +- .../repository/RecruitmentRepository.java | 2 +- .../weakness/domain/User/enums/Tiers.java | 36 +++++++++++++++---- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java index 960cc5d..2b90c10 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java @@ -46,8 +46,11 @@ public ApiResponse createRecruitment( // 모집글 상세 조회 @GetMapping("/{recruitmentId}") - public ApiResponse recruitmentDetailInfo(@PathVariable Long recruitmentId) { - return recruitmentService.getRecruitment(recruitmentId); + public ApiResponse recruitmentDetailInfo( + @LoginUser Users loginUser, + @PathVariable Long recruitmentId + ) { + return recruitmentService.getRecruitment(recruitmentId, loginUser); } // 모집글 수정 diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java index 0145c9f..dd2c9c2 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java @@ -63,6 +63,6 @@ public void updateComment(UpdateCommentRequest updateRequest) { } public Boolean isBelongToPost(Long recruitmentId) { - return this.post.getPostId().equals(recruitmentId); + return this.post.getId().equals(recruitmentId); } } diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java index ba71d36..8f907b4 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java @@ -24,7 +24,7 @@ public class Recruitment { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long postId; + private Long id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author") diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/repository/RecruitmentRepository.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/repository/RecruitmentRepository.java index a664e5c..175665a 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/repository/RecruitmentRepository.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/repository/RecruitmentRepository.java @@ -10,6 +10,6 @@ @Repository public interface RecruitmentRepository extends JpaRepository { - @Query("SELECT r.author.userId FROM Recruitment r WHERE r.postId = :recruitmentId") + @Query("SELECT r.author.userId FROM Recruitment r WHERE r.id = :recruitmentId") Optional findAuthorIdByRecruitmentId(Long recruitmentId); } diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/User/enums/Tiers.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/User/enums/Tiers.java index e1c9421..da118c0 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/User/enums/Tiers.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/User/enums/Tiers.java @@ -1,10 +1,34 @@ package MathCaptain.weakness.domain.User.enums; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + public enum Tiers { - BRONZE, - SILVER, - GOLD, - PLATINUM, - DIAMOND, - MASTER + BRONZE("브론즈"), + SILVER("실버"), + GOLD("골드"), + PLATINUM("플레티넘"), + DIAMOND("다이아몬드"), + MASTER("마스터"); + + private final String value; + + Tiers(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @JsonCreator + public static Tiers fromValue(String value) { + for (Tiers tier : Tiers.values()) { + if (tier.value.equals(value) || tier.name().equals(value)) { + return tier; + } + } + throw new IllegalArgumentException("정의되지 않은 값 입니다 : " + value); + } }