Skip to content

Commit

Permalink
refactor: Response DTO를 record로 변경한다
Browse files Browse the repository at this point in the history
  • Loading branch information
vectorch9 committed Nov 6, 2023
1 parent a579d0e commit d25b43f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class PageBadgesResponse {

private List<BadgeResponse> badges;

@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime lastTime;
public record PageBadgesResponse(List<BadgeResponse> badges,
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm") LocalDateTime lastTime) {

public PageBadgesResponse(final List<BadgeResponse> badges, final LocalDateTime lastTime) {
this.badges = badges;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,8 @@
import daybyquest.user.dto.response.ProfileResponse;
import daybyquest.user.query.Profile;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CommentResponse {

private ProfileResponse author;

private Long id;

private String content;

private LocalDateTime updatedAt;

public CommentResponse(final ProfileResponse author, final Long id, final String content,
final LocalDateTime updatedAt) {
this.author = author;
this.id = id;
this.content = content;
this.updatedAt = updatedAt;
}
public record CommentResponse(ProfileResponse author, Long id, String content, LocalDateTime updatedAt) {

public static CommentResponse of(final CommentData commentData, final Profile profile) {
return new CommentResponse(ProfileResponse.of(profile), commentData.getId(), commentData.getContent(),
Expand Down
32 changes: 2 additions & 30 deletions src/main/java/daybyquest/group/dto/response/GroupResponse.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
package daybyquest.group.dto.response;

import daybyquest.group.query.GroupData;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class GroupResponse {

private Long id;

private String name;

private String description;

private String interest;

private String imageIdentifier;

private Long userCount;

private boolean isGroupManager;

private GroupResponse(final Long id, final String name, final String description, final String interest,
final String imageIdentifier, final Long userCount, final boolean isGroupManager) {
this.id = id;
this.name = name;
this.description = description;
this.interest = interest;
this.imageIdentifier = imageIdentifier;
this.userCount = userCount;
this.isGroupManager = isGroupManager;
}
public record GroupResponse(Long id, String name, String description, String interest, String imageIdentifier,
Long userCount, boolean isGroupManager) {

public static GroupResponse of(final GroupData groupData) {
return new GroupResponse(groupData.getId(), groupData.getName(), groupData.getDescription(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
package daybyquest.interest.dto.response;

import daybyquest.interest.domain.Interest;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class InterestResponse {

private String name;

private String imageIdentifier;

private InterestResponse(final String name, final String imageIdentifier) {
this.name = name;
this.imageIdentifier = imageIdentifier;
}
public record InterestResponse(String name, String imageIdentifier) {

public static InterestResponse of(final Interest interest) {
return new InterestResponse(interest.getName(), interest.getImageIdentifier());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
package daybyquest.post.dto.response;

import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class PagePostsResponse {
public record PagePostsResponse(List<PostResponse> posts, Long lastId) {

private List<PostResponse> posts;

private Long lastId;

public PagePostsResponse(final List<PostResponse> posts, final Long lastId) {
this.posts = posts;
this.lastId = lastId;
}
}
21 changes: 3 additions & 18 deletions src/main/java/daybyquest/post/dto/response/PostResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,10 @@
import daybyquest.user.query.Profile;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class PostResponse {

private ProfileResponse author;

private Long id;

private String content;

@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime updatedAt;

private boolean liked;

private List<String> imageIdentifiers;
public record PostResponse(ProfileResponse author, Long id, String content,
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm") LocalDateTime updatedAt,
boolean liked, List<String> imageIdentifiers) {

public PostResponse(final ProfileResponse author, final Long id, final String content,
final LocalDateTime updatedAt, final boolean liked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,11 @@
import daybyquest.user.query.Profile;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class PostWithQuestResponse {

private ProfileResponse author;

private Long id;

private String content;

@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime updatedAt;

private boolean liked;

private List<String> imageIdentifiers;

private SimpleQuestResponse quest;
public record PostWithQuestResponse(ProfileResponse author, Long id, String content,
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm") LocalDateTime updatedAt,
boolean liked, List<String> imageIdentifiers,
daybyquest.post.dto.response.PostWithQuestResponse.SimpleQuestResponse quest) {

public PostWithQuestResponse(final ProfileResponse author, final Long id, final String content,
final LocalDateTime updatedAt, final boolean liked,
Expand All @@ -40,10 +24,11 @@ public PostWithQuestResponse(final ProfileResponse author, final Long id, final
this.updatedAt = updatedAt;
this.liked = liked;
this.imageIdentifiers = imageIdentifiers;
this.quest = quest;
if (quest.getQuestId() == null) {
if (quest.questId() == null) {
this.quest = null;
return;
}
this.quest = quest;
}

public static PostWithQuestResponse of(final PostData postData, final Profile profile) {
Expand All @@ -55,20 +40,7 @@ public static PostWithQuestResponse of(final PostData postData, final Profile pr
);
}

@Getter
@NoArgsConstructor
private static class SimpleQuestResponse {

private Long questId;
public record SimpleQuestResponse(Long questId, String title, PostState state) {

private String title;

private PostState state;

public SimpleQuestResponse(final Long questId, final String title, final PostState state) {
this.questId = questId;
this.title = title;
this.state = state;
}
}
}
34 changes: 5 additions & 29 deletions src/main/java/daybyquest/quest/dto/response/QuestResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,13 @@
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import daybyquest.quest.query.QuestData;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class QuestResponse {
public record QuestResponse(Long id, String category, String title, String content, String interest,
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm") LocalDateTime expiredAt,
String imageIdentifier, String state, Long rewardCount, Long currentCount,
String groupName) {

private Long id;

private String title;

private String content;

private String interest;

private String category;

private String state;

@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime expiredAt;

private String imageIdentifier;

private Long rewardCount;

private Long currentCount;

private String groupName;

private QuestResponse(final Long id, final String category, final String title, final String content,
public QuestResponse(final Long id, final String category, final String title, final String content,
final String interest, final LocalDateTime expiredAt, final String imageIdentifier,
final String state, final Long rewardCount, final Long currentCount, final String groupName) {
this.id = id;
Expand Down

0 comments on commit d25b43f

Please sign in to comment.