diff --git a/src/main/java/com/listywave/list/application/dto/response/ListTrandingResponse.java b/src/main/java/com/listywave/list/application/dto/response/ListTrandingResponse.java index d61dfc1b..fdb12f1e 100644 --- a/src/main/java/com/listywave/list/application/dto/response/ListTrandingResponse.java +++ b/src/main/java/com/listywave/list/application/dto/response/ListTrandingResponse.java @@ -12,6 +12,7 @@ public record ListTrandingResponse( String itemImageUrl, String backgroundColor ) { + public static ListTrandingResponse of(Lists list, String imageUrlTopRankItem) { return ListTrandingResponse.builder() .id(list.getId()) diff --git a/src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java b/src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java index 5fea0142..909dc604 100644 --- a/src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java +++ b/src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java @@ -8,6 +8,7 @@ public record AllUserListsResponse( Boolean hasNext, List feedLists ) { + public static AllUserListsResponse of(boolean hasNext, Long cursorId, List feedLists) { return new AllUserListsResponse( cursorId, diff --git a/src/main/java/com/listywave/user/application/dto/FeedListsResponse.java b/src/main/java/com/listywave/user/application/dto/FeedListsResponse.java index 89a26ab5..5469ff6d 100644 --- a/src/main/java/com/listywave/user/application/dto/FeedListsResponse.java +++ b/src/main/java/com/listywave/user/application/dto/FeedListsResponse.java @@ -14,6 +14,7 @@ public record FeedListsResponse( String backgroundColor, List listItems ) { + public static FeedListsResponse of(Lists lists) { return FeedListsResponse.builder() .id(lists.getId()) @@ -32,6 +33,7 @@ record ListItemsResponse( String title, String imageUrl ) { + public static ListItemsResponse of(Item item) { return ListItemsResponse.builder() .id(item.getId()) diff --git a/src/main/java/com/listywave/user/application/dto/RecommendUsersResponse.java b/src/main/java/com/listywave/user/application/dto/RecommendUsersResponse.java new file mode 100644 index 00000000..259ac0f3 --- /dev/null +++ b/src/main/java/com/listywave/user/application/dto/RecommendUsersResponse.java @@ -0,0 +1,20 @@ +package com.listywave.user.application.dto; + +import com.listywave.user.application.domain.User; +import lombok.Builder; + +@Builder +public record RecommendUsersResponse( + Long id, + String nickname, + String profileImageUrl +) { + + public static RecommendUsersResponse of(User user) { + return RecommendUsersResponse.builder() + .id(user.getId()) + .nickname(user.getNickname()) + .profileImageUrl(user.getProfileImageUrl()) + .build(); + } +} diff --git a/src/main/java/com/listywave/user/application/service/UserService.java b/src/main/java/com/listywave/user/application/service/UserService.java index 8085e671..b763aea1 100644 --- a/src/main/java/com/listywave/user/application/service/UserService.java +++ b/src/main/java/com/listywave/user/application/service/UserService.java @@ -9,6 +9,7 @@ import com.listywave.user.application.dto.AllUserListsResponse; import com.listywave.user.application.dto.AllUserResponse; import com.listywave.user.application.dto.FollowingsResponse; +import com.listywave.user.application.dto.RecommendUsersResponse; import com.listywave.user.application.dto.UserInfoResponse; import com.listywave.user.repository.follow.FollowRepository; import com.listywave.user.repository.user.UserRepository; @@ -103,4 +104,12 @@ public void unfollow(Long followingUserId, String accessToken) { followRepository.deleteByFollowingUserAndFollowerUser(followingUser, followerUser); } + + @Transactional(readOnly = true) + public List getRecommendUsers() { + List recommendUsers = userRepository.getRecommendUsers(); + return recommendUsers.stream() + .map(RecommendUsersResponse::of) + .toList(); + } } diff --git a/src/main/java/com/listywave/user/presentation/UserController.java b/src/main/java/com/listywave/user/presentation/UserController.java index 5f3d3890..57caed33 100644 --- a/src/main/java/com/listywave/user/presentation/UserController.java +++ b/src/main/java/com/listywave/user/presentation/UserController.java @@ -6,8 +6,10 @@ import com.listywave.user.application.dto.AllUserListsResponse; import com.listywave.user.application.dto.AllUserResponse; import com.listywave.user.application.dto.FollowingsResponse; +import com.listywave.user.application.dto.RecommendUsersResponse; import com.listywave.user.application.dto.UserInfoResponse; import com.listywave.user.application.service.UserService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -74,4 +76,10 @@ ResponseEntity unfollow( userService.unfollow(followingUserId, accessToken); return ResponseEntity.noContent().build(); } + + @GetMapping("/users/recommend") + ResponseEntity> getRecommendUsers() { + List recommendUsers = userService.getRecommendUsers(); + return ResponseEntity.ok(recommendUsers); + } } diff --git a/src/main/java/com/listywave/user/repository/user/custom/CustomUserRepository.java b/src/main/java/com/listywave/user/repository/user/custom/CustomUserRepository.java index a91760bc..56b31d82 100644 --- a/src/main/java/com/listywave/user/repository/user/custom/CustomUserRepository.java +++ b/src/main/java/com/listywave/user/repository/user/custom/CustomUserRepository.java @@ -2,9 +2,12 @@ import com.listywave.list.application.domain.CategoryType; import com.listywave.list.application.domain.Lists; +import com.listywave.user.application.domain.User; import java.util.List; public interface CustomUserRepository { List findFeedLists(Long userId, String type, CategoryType category, Long cursorId, int size); + + List getRecommendUsers(); } diff --git a/src/main/java/com/listywave/user/repository/user/custom/impl/CustomUserRepositoryImpl.java b/src/main/java/com/listywave/user/repository/user/custom/impl/CustomUserRepositoryImpl.java index 625ae75a..3257c092 100644 --- a/src/main/java/com/listywave/user/repository/user/custom/impl/CustomUserRepositoryImpl.java +++ b/src/main/java/com/listywave/user/repository/user/custom/impl/CustomUserRepositoryImpl.java @@ -2,9 +2,11 @@ import static com.listywave.list.application.domain.QItem.item; import static com.listywave.list.application.domain.QLists.lists; +import static com.listywave.user.application.domain.QUser.user; import com.listywave.list.application.domain.CategoryType; import com.listywave.list.application.domain.Lists; +import com.listywave.user.application.domain.User; import com.listywave.user.repository.user.custom.CustomUserRepository; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -56,4 +58,17 @@ private BooleanExpression typeEq(String type) { private BooleanExpression userIdEq(Long userId) { return userId == null ? null : lists.user.id.eq(userId); } + + @Override + public List getRecommendUsers() { + List fetch = queryFactory + .select(user) + .from(lists) + .rightJoin(lists.user, user) + .groupBy(user) + .orderBy(lists.updatedDate.max().desc()) + .limit(10) + .fetch(); + return fetch; + } }