Skip to content

Commit 0505166

Browse files
authored
[fix] DTO 데이터 필드 추가 및 리팩토링 (#55)
2 parents 06285c8 + b78875c commit 0505166

9 files changed

Lines changed: 58 additions & 19 deletions

File tree

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ public ApiResponse<RecruitmentDetailResponse> createRecruitment(
4646

4747
// 모집글 상세 조회
4848
@GetMapping("/{recruitmentId}")
49-
public ApiResponse<RecruitmentDetailResponse> recruitmentDetailInfo(@PathVariable Long recruitmentId) {
50-
return recruitmentService.getRecruitment(recruitmentId);
49+
public ApiResponse<RecruitmentDetailResponse> recruitmentDetailInfo(
50+
@LoginUser Users loginUser,
51+
@PathVariable Long recruitmentId
52+
) {
53+
return recruitmentService.getRecruitment(recruitmentId, loginUser);
5154
}
5255

5356
// 모집글 수정

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class CommentResponse {
1111

1212
private Long commentId;
1313

14+
private Long authorId;
15+
1416
private String authorName;
1517

1618
private String content;
@@ -20,8 +22,9 @@ public class CommentResponse {
2022
private LocalDateTime updatedAt;
2123

2224
@Builder
23-
private CommentResponse(Long commentId, String authorName, String content, LocalDateTime createdAt, LocalDateTime updatedAt) {
25+
private CommentResponse(Long commentId, Long authorId, String authorName, String content, LocalDateTime createdAt, LocalDateTime updatedAt) {
2426
this.commentId = commentId;
27+
this.authorId = authorId;
2528
this.authorName = authorName;
2629
this.content = content;
2730
this.createdAt = createdAt;
@@ -31,6 +34,7 @@ private CommentResponse(Long commentId, String authorName, String content, Local
3134
public static CommentResponse of(Comment comment) {
3235
return CommentResponse.builder()
3336
.commentId(comment.getCommentId())
37+
.authorId(comment.getAuthor().getUserId())
3438
.authorName(comment.getAuthor().getName())
3539
.authorName(comment.getAuthor().getName())
3640
.content(comment.getContent())

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import MathCaptain.weakness.domain.Group.enums.CategoryStatus;
44
import MathCaptain.weakness.domain.Recruitment.entity.Recruitment;
55
import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus;
6+
import MathCaptain.weakness.domain.User.entity.Users;
67
import lombok.*;
78

89
import java.time.LocalDateTime;
@@ -34,10 +35,12 @@ public class RecruitmentDetailResponse {
3435

3536
private List<CommentResponse> comments;
3637

38+
private boolean isAuthor;
39+
3740
@Builder
3841
private RecruitmentDetailResponse(Long authorId, Long recruitGroupId, String authorName, String recruitGroupName, String title,
3942
CategoryStatus category, String content, RecruitmentStatus recruitmentStatus,
40-
LocalDateTime createdAt, LocalDateTime updatedAt, List<CommentResponse> comments) {
43+
LocalDateTime createdAt, LocalDateTime updatedAt, List<CommentResponse> comments, boolean isAuthor) {
4144
this.authorId = authorId;
4245
this.recruitGroupId = recruitGroupId;
4346
this.authorName = authorName;
@@ -49,9 +52,10 @@ private RecruitmentDetailResponse(Long authorId, Long recruitGroupId, String aut
4952
this.createdAt = createdAt;
5053
this.updatedAt = updatedAt;
5154
this.comments = comments;
55+
this.isAuthor = isAuthor;
5256
}
5357

54-
public static RecruitmentDetailResponse of(Recruitment recruitment, List<CommentResponse> comments) {
58+
public static RecruitmentDetailResponse of(Recruitment recruitment, List<CommentResponse> comments, Users loginUser) {
5559
return RecruitmentDetailResponse.builder()
5660
.authorId(recruitment.getAuthor().getUserId())
5761
.recruitGroupId(recruitment.getRecruitGroup().getId())
@@ -64,6 +68,7 @@ public static RecruitmentDetailResponse of(Recruitment recruitment, List<Comment
6468
.createdAt(recruitment.getPostTime())
6569
.updatedAt(recruitment.getLastModifiedTime())
6670
.comments(comments)
71+
.isAuthor(recruitment.getAuthor().getUserId().equals(loginUser.getUserId()))
6772
.build();
6873
}
6974
}

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponse.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
@NoArgsConstructor(access = AccessLevel.PROTECTED)
1212
public class RecruitmentResponse {
1313

14+
private Long recruitmentId;
15+
1416
private String authorName;
1517

1618
private String recruitGroupName;
@@ -28,9 +30,10 @@ public class RecruitmentResponse {
2830
private LocalDateTime updatedAt;
2931

3032
@Builder
31-
private RecruitmentResponse(String authorName, String recruitGroupName, String title,
33+
private RecruitmentResponse(Long recruitmentId, String authorName, String recruitGroupName, String title,
3234
CategoryStatus category, String content, RecruitmentStatus recruitmentStatus,
3335
LocalDateTime createdAt, LocalDateTime updatedAt) {
36+
this.recruitmentId = recruitmentId;
3437
this.authorName = authorName;
3538
this.recruitGroupName = recruitGroupName;
3639
this.title = title;
@@ -43,6 +46,7 @@ private RecruitmentResponse(String authorName, String recruitGroupName, String t
4346

4447
public static RecruitmentResponse of(Recruitment recruitment) {
4548
return RecruitmentResponse.builder()
49+
.recruitmentId(recruitment.getId())
4650
.authorName(recruitment.getAuthor().getName())
4751
.recruitGroupName(recruitment.getRecruitGroup().getName())
4852
.title(recruitment.getTitle())

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public void updateComment(UpdateCommentRequest updateRequest) {
6363
}
6464

6565
public Boolean isBelongToPost(Long recruitmentId) {
66-
return this.post.getPostId().equals(recruitmentId);
66+
return this.post.getId().equals(recruitmentId);
6767
}
6868
}

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Recruitment {
2424

2525
@Id
2626
@GeneratedValue(strategy = GenerationType.IDENTITY)
27-
private Long postId;
27+
private Long id;
2828

2929
@ManyToOne(fetch = FetchType.LAZY)
3030
@JoinColumn(name = "author")

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/repository/RecruitmentRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
@Repository
1111
public interface RecruitmentRepository extends JpaRepository<Recruitment, Long> {
1212

13-
@Query("SELECT r.author.userId FROM Recruitment r WHERE r.postId = :recruitmentId")
13+
@Query("SELECT r.author.userId FROM Recruitment r WHERE r.id = :recruitmentId")
1414
Optional<Long> findAuthorIdByRecruitmentId(Long recruitmentId);
1515
}

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/RecruitmentService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ public class RecruitmentService {
3939
Group group = findLeaderGroupByUser(author);
4040
Recruitment recruitment = Recruitment.of(author, group, createRecruitmentRequest);
4141
recruitmentRepository.save(recruitment);
42-
RecruitmentDetailResponse recruitmentResponse = RecruitmentDetailResponse.of(recruitment, List.of());
42+
RecruitmentDetailResponse recruitmentResponse = RecruitmentDetailResponse.of(recruitment, List.of(), author);
4343
return ApiResponse.ok(recruitmentResponse);
4444
}
4545

46-
4746
// 모집글 조회
48-
public ApiResponse<RecruitmentDetailResponse> getRecruitment(Long recruitmentId) {
47+
public ApiResponse<RecruitmentDetailResponse> getRecruitment(Long recruitmentId, Users loginUser) {
4948
Recruitment recruitment = findRecruitmentBy(recruitmentId);
5049
List<CommentResponse> comments = commentService.getComments(recruitmentId);
51-
return ApiResponse.ok(RecruitmentDetailResponse.of(recruitment, comments));
50+
return ApiResponse.ok(RecruitmentDetailResponse.of(recruitment, comments, loginUser));
5251
}
5352

5453
// 모집글 수정
Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
package MathCaptain.weakness.domain.User.enums;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
36
public enum Tiers {
4-
BRONZE,
5-
SILVER,
6-
GOLD,
7-
PLATINUM,
8-
DIAMOND,
9-
MASTER
7+
BRONZE("브론즈"),
8+
SILVER("실버"),
9+
GOLD("골드"),
10+
PLATINUM("플레티넘"),
11+
DIAMOND("다이아몬드"),
12+
MASTER("마스터");
13+
14+
private final String value;
15+
16+
Tiers(String value) {
17+
this.value = value;
18+
}
19+
20+
@JsonValue
21+
public String getValue() {
22+
return value;
23+
}
24+
25+
@JsonCreator
26+
public static Tiers fromValue(String value) {
27+
for (Tiers tier : Tiers.values()) {
28+
if (tier.value.equals(value) || tier.name().equals(value)) {
29+
return tier;
30+
}
31+
}
32+
throw new IllegalArgumentException("정의되지 않은 값 입니다 : " + value);
33+
}
1034
}

0 commit comments

Comments
 (0)