-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
8 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
src/main/java/com/listywave/list/application/dto/response/ListRecentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.listywave.list.application.dto.response; | ||
|
||
import com.listywave.list.application.domain.Item; | ||
import com.listywave.list.application.domain.Label; | ||
import com.listywave.list.application.domain.Lists; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ListRecentResponse( | ||
List<ListResponse> lists | ||
) { | ||
public static ListRecentResponse of(List<Lists> lists) { | ||
return ListRecentResponse.builder() | ||
.lists(ListResponse.toList(lists)) | ||
.build(); | ||
} | ||
} | ||
|
||
@Builder | ||
record ListResponse( | ||
Long id, | ||
String category, | ||
String backgroundColor, | ||
Long ownerId, | ||
String ownerNickname, | ||
String ownerProfileImage, | ||
List<LabelsResponse> labels, | ||
String title, | ||
String description, | ||
List<ItemsResponse> items | ||
) { | ||
|
||
public static List<ListResponse> toList(List<Lists> lists) { | ||
return lists.stream() | ||
.map(ListResponse::of) | ||
.toList(); | ||
} | ||
|
||
public static ListResponse of(Lists lists) { | ||
return ListResponse.builder() | ||
.id(lists.getId()) | ||
.category(lists.getCategory().getKorNameValue()) | ||
.backgroundColor(lists.getBackgroundColor()) | ||
.ownerId(lists.getUser().getId()) | ||
.ownerNickname(lists.getUser().getNickname()) | ||
.ownerProfileImage(lists.getUser().getProfileImageUrl()) | ||
.labels(LabelsResponse.toList(lists.getLabels())) | ||
.title(lists.getTitle()) | ||
.description(lists.getDescription()) | ||
.items(ItemsResponse.toList(lists.getItems())) | ||
.build(); | ||
} | ||
} | ||
|
||
@Builder | ||
record LabelsResponse( | ||
Long id, | ||
String name | ||
) { | ||
|
||
public static List<LabelsResponse> toList(List<Label> labels) { | ||
return labels.stream() | ||
.map(LabelsResponse::of) | ||
.toList(); | ||
} | ||
|
||
public static LabelsResponse of(Label label) { | ||
return LabelsResponse.builder() | ||
.id(label.getId()) | ||
.name(label.getLabelName()) | ||
.build(); | ||
} | ||
} | ||
|
||
@Builder | ||
record ItemsResponse( | ||
Long id, | ||
int ranking, | ||
String title, | ||
String imageUrl | ||
) { | ||
|
||
public static List<ItemsResponse> toList(List<Item> items) { | ||
return items.stream() | ||
.sorted(Comparator.comparing(Item::getRanking)) | ||
.map(ItemsResponse::of) | ||
.limit(3) | ||
.toList(); | ||
} | ||
|
||
public static ItemsResponse of(Item item) { | ||
return ItemsResponse.builder() | ||
.id(item.getId()) | ||
.ranking(item.getRanking()) | ||
.title(item.getTitle()) | ||
.imageUrl(item.getImageUrl()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/listywave/list/repository/list/custom/CustomListRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package com.listywave.list.repository.list.custom; | ||
|
||
import com.listywave.list.application.domain.Lists; | ||
import com.listywave.user.application.domain.User; | ||
import java.util.List; | ||
|
||
public interface CustomListRepository { | ||
|
||
List<Lists> findTrandingLists(); | ||
|
||
List<Lists> getRecentLists(); | ||
|
||
List<Lists> getRecentListsByFollowing(List<User> followingUsers); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters