Skip to content

Commit

Permalink
feat: 탐색페이지 사용자 추천 리스트 API 구현 (#81)
Browse files Browse the repository at this point in the history
* refactor: 코딩 컨벤션 적용 안된 부분 수정 (#75)

* feat: 탐색페이지 사용자 추천 리스트 API 구현 (#75)

* refactor: api uri 변경 (#75)
  • Loading branch information
pparkjs authored Feb 8, 2024
1 parent 41fbe2d commit ac1bb89
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
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 @@ -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;
Expand Down Expand Up @@ -103,4 +104,12 @@ public void unfollow(Long followingUserId, String accessToken) {

followRepository.deleteByFollowingUserAndFollowerUser(followingUser, followerUser);
}

@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.DeleteMapping;
Expand Down Expand Up @@ -74,4 +76,10 @@ ResponseEntity<Void> unfollow(
userService.unfollow(followingUserId, accessToken);
return ResponseEntity.noContent().build();
}

@GetMapping("/users/recommend")
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
.select(user)
.from(lists)
.rightJoin(lists.user, user)
.groupBy(user)
.orderBy(lists.updatedDate.max().desc())
.limit(10)
.fetch();
return fetch;
}
}

0 comments on commit ac1bb89

Please sign in to comment.