Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨feature: Add isLike and itemLikeCount on Items Detail API #83

Merged
merged 6 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ void findNearItemsTestSuccess1() throws Exception {
new MusicResponseDto("title", "artist", "/albumImage.jpg", List.of("genre")),
"사용자 코멘트",
LocalDateTime.of(2023, 5, 26, 12, 0),
false,
1
)
)
Expand Down Expand Up @@ -466,6 +467,7 @@ void findNearItemsTestSuccess2() throws Exception {
new MusicResponseDto("title", "artist", "/albumImage.jpg", List.of("genre")),
"사용자 코멘트",
LocalDateTime.of(2023, 5, 26, 12, 0),
false,
1
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public record ItemDetailDto(
)
LocalDateTime createdAt,

@Schema(description = "아이템 좋아요 여부", example = "true")
boolean isLiked,

@Schema(description = "아이템 좋아요 개수", example = "100")
int itemLikeCount
) {
Expand All @@ -45,6 +48,7 @@ public ItemDetailDto(Item item) {
new MusicResponseDto(item),
item.getContent(),
item.getCreatedAt(),
item.isLiked(item.getUser()),
item.getItemLikeCount()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ public void setItemLocation(ItemLocation itemLocation) {
public int getItemLikeCount() {
return likes != null ? likes.size() : 0;
}

public boolean isLiked(User user) {
return likes != null && likes.stream().anyMatch(like -> like.isLiked(user));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public ItemLike(Item item, User user) {
this.item = item;
this.user = user;
}

public boolean isLiked(User user) {
return user.equals(user);
}

}