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

feat: 탐색페이지 사용자 추천 리스트 API 구현 #81

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record AllUserListsResponse(
Boolean hasNext,
List<FeedListsResponse> feedLists
) {

public static AllUserListsResponse of(boolean hasNext, Long cursorId, List<Lists> feedLists) {
return new AllUserListsResponse(
cursorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record FeedListsResponse(
String backgroundColor,
List<ListItemsResponse> listItems
) {

public static FeedListsResponse of(Lists lists) {
return FeedListsResponse.builder()
.id(lists.getId())
Expand All @@ -32,6 +33,7 @@ record ListItemsResponse(
String title,
String imageUrl
) {

public static ListItemsResponse of(Item item) {
return ListItemsResponse.builder()
.id(item.getId())
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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;
Expand Down Expand Up @@ -89,4 +90,12 @@ public FollowingsResponse getFollowings(String accessToken) {
.toList();
return FollowingsResponse.of(followingUsers);
}

@Transactional(readOnly = true)
public List<RecommendUsersResponse> getRecommendUsers() {
List<User> recommendUsers = userRepository.getRecommendUsers();
return recommendUsers.stream()
.map(RecommendUsersResponse::of)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetMapping;
Expand Down Expand Up @@ -54,4 +56,10 @@ ResponseEntity<FollowingsResponse> getFollowings(@RequestHeader(value = AUTHORIZ
FollowingsResponse response = userService.getFollowings(accessToken);
return ResponseEntity.ok(response);
}

@GetMapping("/users/explore")
pparkjs marked this conversation as resolved.
Show resolved Hide resolved
ResponseEntity<List<RecommendUsersResponse>> getRecommendUsers() {
List<RecommendUsersResponse> recommendUsers = userService.getRecommendUsers();
return ResponseEntity.ok(recommendUsers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lists> findFeedLists(Long userId, String type, CategoryType category, Long cursorId, int size);

List<User> getRecommendUsers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<User> getRecommendUsers() {
List<User> fetch = queryFactory
kdkdhoho marked this conversation as resolved.
Show resolved Hide resolved
.select(user)
.from(lists)
.rightJoin(lists.user, user)
.groupBy(user)
.orderBy(lists.updatedDate.max().desc())
pparkjs marked this conversation as resolved.
Show resolved Hide resolved
.limit(10)
.fetch();
return fetch;
}
}
Loading