diff --git a/src/main/java/com/listywave/auth/application/service/AuthService.java b/src/main/java/com/listywave/auth/application/service/AuthService.java index a66956d9..6605380c 100644 --- a/src/main/java/com/listywave/auth/application/service/AuthService.java +++ b/src/main/java/com/listywave/auth/application/service/AuthService.java @@ -7,7 +7,7 @@ import com.listywave.auth.infra.kakao.response.KakaoTokenResponse; import com.listywave.auth.presentation.dto.LoginResponse; import com.listywave.user.application.domain.User; -import com.listywave.user.repository.UserRepository; +import com.listywave.user.repository.user.UserRepository; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/listywave/common/util/UserUtil.java b/src/main/java/com/listywave/common/util/UserUtil.java index 603761bb..ab2ca11f 100644 --- a/src/main/java/com/listywave/common/util/UserUtil.java +++ b/src/main/java/com/listywave/common/util/UserUtil.java @@ -3,7 +3,7 @@ import com.listywave.common.exception.CustomException; import com.listywave.common.exception.ErrorCode; import com.listywave.user.application.domain.User; -import com.listywave.user.repository.UserRepository; +import com.listywave.user.repository.user.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/listywave/list/application/service/CommentService.java b/src/main/java/com/listywave/list/application/service/CommentService.java index 740987ab..eaaaea39 100644 --- a/src/main/java/com/listywave/list/application/service/CommentService.java +++ b/src/main/java/com/listywave/list/application/service/CommentService.java @@ -13,7 +13,7 @@ import com.listywave.list.repository.ListRepository; import com.listywave.list.repository.ReplyRepository; import com.listywave.user.application.domain.User; -import com.listywave.user.repository.UserRepository; +import com.listywave.user.repository.user.UserRepository; import jakarta.transaction.Transactional; import java.util.LinkedHashMap; import java.util.List; @@ -46,7 +46,7 @@ public CommentCreateResponse create(Long listId, String accessToken, String cont public CommentFindResponse getComments(Long listId, int size, Long cursorId) { Lists list = listRepository.getById(listId); Long totalCount = commentRepository.countByList(list); - + List comments = commentRepository.getComments(listId, size, cursorId); boolean hasNext = false; diff --git a/src/main/java/com/listywave/list/application/service/ListService.java b/src/main/java/com/listywave/list/application/service/ListService.java index 3b039d71..ba181d63 100644 --- a/src/main/java/com/listywave/list/application/service/ListService.java +++ b/src/main/java/com/listywave/list/application/service/ListService.java @@ -12,7 +12,7 @@ import com.listywave.list.presentation.dto.response.ListCreateResponse; import com.listywave.list.repository.ListRepository; import com.listywave.user.application.domain.User; -import com.listywave.user.repository.UserRepository; +import com.listywave.user.repository.user.UserRepository; import jakarta.transaction.Transactional; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/com/listywave/list/application/service/ReplyService.java b/src/main/java/com/listywave/list/application/service/ReplyService.java index ee5bd271..4aac6bb0 100644 --- a/src/main/java/com/listywave/list/application/service/ReplyService.java +++ b/src/main/java/com/listywave/list/application/service/ReplyService.java @@ -10,7 +10,7 @@ import com.listywave.list.repository.ListRepository; import com.listywave.list.repository.ReplyRepository; import com.listywave.user.application.domain.User; -import com.listywave.user.repository.UserRepository; +import com.listywave.user.repository.user.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/listywave/user/application/domain/Follow.java b/src/main/java/com/listywave/user/application/domain/Follow.java new file mode 100644 index 00000000..af5eb874 --- /dev/null +++ b/src/main/java/com/listywave/user/application/domain/Follow.java @@ -0,0 +1,28 @@ +package com.listywave.user.application.domain; + +import com.listywave.common.BaseEntity; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Follow extends BaseEntity { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "following_user_id") + private User followingUser; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "follower_user_id") + private User followerUser; +} diff --git a/src/main/java/com/listywave/user/presentation/dto/response/AllUserListsResponse.java b/src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java similarity index 84% rename from src/main/java/com/listywave/user/presentation/dto/response/AllUserListsResponse.java rename to src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java index 33323c21..5fea0142 100644 --- a/src/main/java/com/listywave/user/presentation/dto/response/AllUserListsResponse.java +++ b/src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java @@ -1,7 +1,6 @@ -package com.listywave.user.presentation.dto.response; +package com.listywave.user.application.dto; import com.listywave.list.application.domain.Lists; -import com.listywave.user.application.dto.FeedListsResponse; import java.util.List; public record AllUserListsResponse( diff --git a/src/main/java/com/listywave/user/application/dto/FollowingsResponse.java b/src/main/java/com/listywave/user/application/dto/FollowingsResponse.java new file mode 100644 index 00000000..771515fc --- /dev/null +++ b/src/main/java/com/listywave/user/application/dto/FollowingsResponse.java @@ -0,0 +1,37 @@ +package com.listywave.user.application.dto; + +import com.listywave.user.application.domain.User; +import java.util.List; +import lombok.Builder; + +public record FollowingsResponse( + List followings +) { + + public static FollowingsResponse of(List users) { + return new FollowingsResponse(FollowingUserInfo.toList(users)); + } +} + +@Builder +record FollowingUserInfo( + Long id, + String nickname, + String profileImageUrl +) { + + public static List toList(List users) { + return users.stream() + .map(FollowingUserInfo::of) + .toList(); + } + + public static FollowingUserInfo of(User user) { + return FollowingUserInfo.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 b08e0318..ed5b214f 100644 --- a/src/main/java/com/listywave/user/application/service/UserService.java +++ b/src/main/java/com/listywave/user/application/service/UserService.java @@ -7,11 +7,14 @@ import com.listywave.common.util.UserUtil; import com.listywave.list.application.domain.CategoryType; import com.listywave.list.application.domain.Lists; +import com.listywave.user.application.domain.Follow; import com.listywave.user.application.domain.User; +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.UserInfoResponse; -import com.listywave.user.presentation.dto.response.AllUserListsResponse; -import com.listywave.user.repository.UserRepository; +import com.listywave.user.repository.follow.FollowRepository; +import com.listywave.user.repository.user.UserRepository; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -22,9 +25,10 @@ @RequiredArgsConstructor public class UserService { - private final JwtManager jwtManager; private final UserUtil userUtil; + private final JwtManager jwtManager; private final UserRepository userRepository; + private final FollowRepository followRepository; @Transactional(readOnly = true) public UserInfoResponse getUserInfo(Long userId, String accessToken) { @@ -42,7 +46,6 @@ public UserInfoResponse getUserInfo(Long userId, String accessToken) { return UserInfoResponse.of(foundUser, false, false); } - private boolean isSignedIn(String accessToken) { return accessToken.isBlank(); } @@ -75,4 +78,15 @@ public AllUserResponse getAllUser() { List allUser = userRepository.findAll(); return AllUserResponse.of(allUser); } + + public FollowingsResponse getFollowings(String accessToken) { + Long loginUserId = jwtManager.read(accessToken); + User user = userRepository.getById(loginUserId); + List follows = followRepository.getAllByFollowerUser(user); + + List followingUsers = follows.stream() + .map(Follow::getFollowingUser) + .toList(); + return FollowingsResponse.of(followingUsers); + } } diff --git a/src/main/java/com/listywave/user/presentation/UserController.java b/src/main/java/com/listywave/user/presentation/UserController.java index 6321d67e..6b4aaf24 100644 --- a/src/main/java/com/listywave/user/presentation/UserController.java +++ b/src/main/java/com/listywave/user/presentation/UserController.java @@ -1,10 +1,13 @@ package com.listywave.user.presentation; +import static org.springframework.http.HttpHeaders.AUTHORIZATION; + import com.listywave.list.application.domain.CategoryType; +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.UserInfoResponse; import com.listywave.user.application.service.UserService; -import com.listywave.user.presentation.dto.response.AllUserListsResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -22,7 +25,7 @@ public class UserController { @GetMapping("/users/{userId}") ResponseEntity getUserInfo( @PathVariable(value = "userId") Long userId, - @RequestHeader(value = "Authorization", defaultValue = "") String accessToken + @RequestHeader(value = AUTHORIZATION, defaultValue = "") String accessToken ) { UserInfoResponse userInfoResponse = userService.getUserInfo(userId, accessToken); return ResponseEntity.ok(userInfoResponse); @@ -45,4 +48,10 @@ ResponseEntity getAllUserLists( AllUserListsResponse allUserListsResponse = userService.getAllListOfUser(userId, type, category, cursorId, size); return ResponseEntity.ok(allUserListsResponse); } + + @GetMapping("/followings") + ResponseEntity getFollowings(@RequestHeader(value = AUTHORIZATION) String accessToken) { + FollowingsResponse response = userService.getFollowings(accessToken); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/listywave/user/repository/follow/FollowRepository.java b/src/main/java/com/listywave/user/repository/follow/FollowRepository.java new file mode 100644 index 00000000..6d4e9225 --- /dev/null +++ b/src/main/java/com/listywave/user/repository/follow/FollowRepository.java @@ -0,0 +1,11 @@ +package com.listywave.user.repository.follow; + +import com.listywave.user.application.domain.Follow; +import com.listywave.user.application.domain.User; +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FollowRepository extends JpaRepository { + + List getAllByFollowerUser(User user); +} diff --git a/src/main/java/com/listywave/user/repository/UserRepository.java b/src/main/java/com/listywave/user/repository/user/UserRepository.java similarity index 78% rename from src/main/java/com/listywave/user/repository/UserRepository.java rename to src/main/java/com/listywave/user/repository/user/UserRepository.java index c3dd0226..2d3fb766 100644 --- a/src/main/java/com/listywave/user/repository/UserRepository.java +++ b/src/main/java/com/listywave/user/repository/user/UserRepository.java @@ -1,14 +1,14 @@ -package com.listywave.user.repository; +package com.listywave.user.repository.user; import static com.listywave.common.exception.ErrorCode.NOT_FOUND; import com.listywave.common.exception.CustomException; import com.listywave.user.application.domain.User; -import com.listywave.user.repository.custom.UserRepositoryCustom; +import com.listywave.user.repository.user.custom.CustomUserRepository; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -public interface UserRepository extends JpaRepository, UserRepositoryCustom { +public interface UserRepository extends JpaRepository, CustomUserRepository { Optional findByOauthId(Long oauthId); diff --git a/src/main/java/com/listywave/user/repository/custom/UserRepositoryCustom.java b/src/main/java/com/listywave/user/repository/user/custom/CustomUserRepository.java similarity index 72% rename from src/main/java/com/listywave/user/repository/custom/UserRepositoryCustom.java rename to src/main/java/com/listywave/user/repository/user/custom/CustomUserRepository.java index c27d43e8..a91760bc 100644 --- a/src/main/java/com/listywave/user/repository/custom/UserRepositoryCustom.java +++ b/src/main/java/com/listywave/user/repository/user/custom/CustomUserRepository.java @@ -1,10 +1,10 @@ -package com.listywave.user.repository.custom; +package com.listywave.user.repository.user.custom; import com.listywave.list.application.domain.CategoryType; import com.listywave.list.application.domain.Lists; import java.util.List; -public interface UserRepositoryCustom { +public interface CustomUserRepository { List findFeedLists(Long userId, String type, CategoryType category, Long cursorId, int size); } diff --git a/src/main/java/com/listywave/user/repository/custom/impl/UserRepositoryImpl.java b/src/main/java/com/listywave/user/repository/user/custom/impl/CustomUserRepositoryImpl.java similarity index 90% rename from src/main/java/com/listywave/user/repository/custom/impl/UserRepositoryImpl.java rename to src/main/java/com/listywave/user/repository/user/custom/impl/CustomUserRepositoryImpl.java index 8066fbc1..625ae75a 100644 --- a/src/main/java/com/listywave/user/repository/custom/impl/UserRepositoryImpl.java +++ b/src/main/java/com/listywave/user/repository/user/custom/impl/CustomUserRepositoryImpl.java @@ -1,18 +1,18 @@ -package com.listywave.user.repository.custom.impl; +package com.listywave.user.repository.user.custom.impl; import static com.listywave.list.application.domain.QItem.item; import static com.listywave.list.application.domain.QLists.lists; import com.listywave.list.application.domain.CategoryType; import com.listywave.list.application.domain.Lists; -import com.listywave.user.repository.custom.UserRepositoryCustom; +import com.listywave.user.repository.user.custom.CustomUserRepository; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor -public class UserRepositoryImpl implements UserRepositoryCustom { +public class CustomUserRepositoryImpl implements CustomUserRepository { private final JPAQueryFactory queryFactory;