From 74ff4a12a2ffe5834aec29c403033fe7d1699a47 Mon Sep 17 00:00:00 2001 From: kdkdhoho Date: Tue, 13 Feb 2024 21:14:16 +0900 Subject: [PATCH] =?UTF-8?q?=20refactor:=20List=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20(#105)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/domain/Collaborator.java | 6 +-- .../repository/CollaboratorRepository.java | 4 +- .../application/service/ImageService.java | 16 ++++---- .../list/application/domain/Comment.java | 4 +- .../list/application/domain/Item.java | 6 +-- .../list/application/domain/Label.java | 2 +- .../domain/{Lists.java => ListEntity.java} | 33 ++++++++-------- .../dto/response/ListDetailResponse.java | 4 +- .../dto/response/ListRecentResponse.java | 28 +++++++------- .../dto/response/ListSearchResponse.java | 26 ++++++------- .../dto/response/ListTrandingResponse.java | 4 +- .../application/service/CommentService.java | 6 +-- .../list/application/service/ListService.java | 26 ++++++------- .../list/repository/CommentRepository.java | 6 +-- .../repository/CustomCommentRepository.java | 4 +- .../CustomCommentRepositoryImpl.java | 11 +++--- .../list/repository/list/ListRepository.java | 6 +-- .../list/custom/CustomListRepository.java | 8 ++-- .../custom/impl/CustomListRepositoryImpl.java | 38 +++++++++---------- .../reply/CustomReplyRepository.java | 4 +- .../reply/CustomReplyRepositoryImpl.java | 9 +++-- .../application/dto/AllUserListsResponse.java | 6 +-- .../application/dto/FeedListsResponse.java | 18 ++++----- .../user/application/service/UserService.java | 4 +- .../user/custom/CustomUserRepository.java | 4 +- .../custom/impl/CustomUserRepositoryImpl.java | 30 +++++++-------- 26 files changed, 158 insertions(+), 155 deletions(-) rename src/main/java/com/listywave/list/application/domain/{Lists.java => ListEntity.java} (89%) diff --git a/src/main/java/com/listywave/collaborator/application/domain/Collaborator.java b/src/main/java/com/listywave/collaborator/application/domain/Collaborator.java index 5b541e8d..95ffa89d 100644 --- a/src/main/java/com/listywave/collaborator/application/domain/Collaborator.java +++ b/src/main/java/com/listywave/collaborator/application/domain/Collaborator.java @@ -1,6 +1,6 @@ package com.listywave.collaborator.application.domain; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.user.application.domain.User; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -32,9 +32,9 @@ public class Collaborator { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "list_id") - private Lists list; + private ListEntity list; - public static Collaborator createCollaborator(User user, Lists list) { + public static Collaborator createCollaborator(User user, ListEntity list) { return Collaborator.builder() .user(user) .list(list) diff --git a/src/main/java/com/listywave/collaborator/repository/CollaboratorRepository.java b/src/main/java/com/listywave/collaborator/repository/CollaboratorRepository.java index 7272cc79..8aa1165a 100644 --- a/src/main/java/com/listywave/collaborator/repository/CollaboratorRepository.java +++ b/src/main/java/com/listywave/collaborator/repository/CollaboratorRepository.java @@ -1,7 +1,7 @@ package com.listywave.collaborator.repository; import com.listywave.collaborator.application.domain.Collaborator; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; @@ -9,5 +9,5 @@ public interface CollaboratorRepository extends JpaRepository findAllByListId(Long listId); - void deleteAllByList(Lists lists); + void deleteAllByList(ListEntity list); } diff --git a/src/main/java/com/listywave/image/application/service/ImageService.java b/src/main/java/com/listywave/image/application/service/ImageService.java index ddd7fe37..6642c050 100644 --- a/src/main/java/com/listywave/image/application/service/ImageService.java +++ b/src/main/java/com/listywave/image/application/service/ImageService.java @@ -21,7 +21,7 @@ import com.listywave.image.application.dto.response.ItemPresignedUrlResponse; import com.listywave.image.application.dto.response.UserPresignedUrlResponse; import com.listywave.list.application.domain.Item; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.list.repository.ItemRepository; import com.listywave.list.repository.list.ListRepository; import com.listywave.user.application.domain.User; @@ -61,8 +61,8 @@ public List createListsPresignedUrl(Long ownerId, Long //TODO: 회원이 존재하는지 않하는지 검증 (security) final User user = userUtil.getUserByUserid(ownerId); - Lists lists = findListById(listId); - validateListUserMismatch(lists, user); + ListEntity list = findListById(listId); + validateListUserMismatch(list, user); return extensionRanks.stream() .map((extensionRank) -> { @@ -88,8 +88,8 @@ public void uploadCompleteItemImages(Long ownerId, Long listId, List { @@ -417,13 +417,13 @@ private String generatedUUID() { return UUID.randomUUID().toString(); } - private void validateListUserMismatch(Lists lists, User user) { - if (!lists.getUser().getId().equals(user.getId())) { + private void validateListUserMismatch(ListEntity list, User user) { + if (!list.getUser().getId().equals(user.getId())) { throw new CustomException(ErrorCode.INVALID_ACCESS, "리스트를 생성한 유저와 로그인한 계정이 일치하지 않습니다."); } } - private Lists findListById(Long listId) { + private ListEntity findListById(Long listId) { return listRepository .findById(listId) .orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND, "존재하지 않는 리스트입니다.")); diff --git a/src/main/java/com/listywave/list/application/domain/Comment.java b/src/main/java/com/listywave/list/application/domain/Comment.java index 47aa9600..98c4764a 100644 --- a/src/main/java/com/listywave/list/application/domain/Comment.java +++ b/src/main/java/com/listywave/list/application/domain/Comment.java @@ -22,7 +22,7 @@ public class Comment extends BaseEntity { @JoinColumn(name = "list_id") @ManyToOne(fetch = FetchType.LAZY) - private Lists list; + private ListEntity list; @JoinColumn(name = "user_id") @ManyToOne(fetch = FetchType.LAZY) @@ -34,7 +34,7 @@ public class Comment extends BaseEntity { @Column(nullable = false, length = 5) private Boolean isDeleted; - public static Comment create(Lists list, User user, String content) { + public static Comment create(ListEntity list, User user, String content) { return new Comment(list, user, new Content(content), false); } diff --git a/src/main/java/com/listywave/list/application/domain/Item.java b/src/main/java/com/listywave/list/application/domain/Item.java index 71ffe57e..48da6bb3 100644 --- a/src/main/java/com/listywave/list/application/domain/Item.java +++ b/src/main/java/com/listywave/list/application/domain/Item.java @@ -27,7 +27,7 @@ public class Item extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "list_id") - private Lists list; + private ListEntity list; @Column(nullable = false) private int ranking; @@ -46,9 +46,9 @@ public class Item extends BaseEntity { private String imageKey; - public static Item createItem(ItemCreateRequest items, Lists lists) { + public static Item createItem(ItemCreateRequest items, ListEntity list) { return Item.builder() - .list(lists) + .list(list) .ranking(items.rank()) .title( ItemTitle.builder() diff --git a/src/main/java/com/listywave/list/application/domain/Label.java b/src/main/java/com/listywave/list/application/domain/Label.java index 2c6b18c1..50535928 100644 --- a/src/main/java/com/listywave/list/application/domain/Label.java +++ b/src/main/java/com/listywave/list/application/domain/Label.java @@ -27,7 +27,7 @@ public class Label { @ManyToOne @JoinColumn(name = "list_Id") - private Lists list; + private ListEntity list; @Embedded private LabelName labelName; diff --git a/src/main/java/com/listywave/list/application/domain/Lists.java b/src/main/java/com/listywave/list/application/domain/ListEntity.java similarity index 89% rename from src/main/java/com/listywave/list/application/domain/Lists.java rename to src/main/java/com/listywave/list/application/domain/ListEntity.java index 7c816da2..0df0c038 100644 --- a/src/main/java/com/listywave/list/application/domain/Lists.java +++ b/src/main/java/com/listywave/list/application/domain/ListEntity.java @@ -43,10 +43,10 @@ @Entity @Builder @AllArgsConstructor -@Table(name = "LIST") +@Table(name = "list") @EntityListeners(AuditingEntityListener.class) @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Lists { +public class ListEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -95,7 +95,7 @@ public class Lists { @LastModifiedDate private LocalDateTime updatedDate; - public static void addLabelToList(Lists list, List labels) { + public static void addLabelToList(ListEntity list, List labels) { for (String label : labels) { list.getLabels().add( Label.builder() @@ -110,7 +110,7 @@ public static void addLabelToList(Lists list, List labels) { } } - private static void addItemToList(Lists list, List items) { + private static void addItemToList(ListEntity list, List items) { for (ItemCreateRequest item : items) { list.getItems().add( Item.builder() @@ -141,28 +141,29 @@ private static void addItemToList(Lists list, List items) { } } - public static Lists createList( + public static ListEntity createList( User user, - ListCreateCommand list, + ListCreateCommand command, List labels, List items, Boolean isLabels, - Boolean hasCollaboratorId) { - Lists lists = Lists.builder() + Boolean hasCollaboratorId + ) { + ListEntity list = ListEntity.builder() .user(user) - .category(list.category()) + .category(command.category()) .hasCollaboration(hasCollaboratorId) - .title(list.title()) - .isPublic(list.isPublic()) - .backgroundColor(list.backgroundColor()) - .description(list.description()) + .title(command.title()) + .isPublic(command.isPublic()) + .backgroundColor(command.backgroundColor()) + .description(command.description()) .build(); if (isLabels) { - addLabelToList(lists, labels); + addLabelToList(list, labels); } - addItemToList(lists, items); - return lists; + addItemToList(list, items); + return list; } public boolean isRelatedWith(String keyword) { diff --git a/src/main/java/com/listywave/list/application/dto/response/ListDetailResponse.java b/src/main/java/com/listywave/list/application/dto/response/ListDetailResponse.java index ab97396b..d54c7da1 100644 --- a/src/main/java/com/listywave/list/application/dto/response/ListDetailResponse.java +++ b/src/main/java/com/listywave/list/application/dto/response/ListDetailResponse.java @@ -3,7 +3,7 @@ import com.listywave.collaborator.application.domain.Collaborator; import com.listywave.list.application.domain.Item; import com.listywave.list.application.domain.Label; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.user.application.domain.User; import java.time.LocalDateTime; import java.util.List; @@ -29,7 +29,7 @@ public record ListDetailResponse( int viewCount ) { - public static ListDetailResponse of(Lists list, User user, boolean isCollected, List collaborators) { + public static ListDetailResponse of(ListEntity list, User user, boolean isCollected, List collaborators) { return ListDetailResponse.builder() .category(list.getCategoryName()) .labels(LabelResponse.toList(list.getLabels())) diff --git a/src/main/java/com/listywave/list/application/dto/response/ListRecentResponse.java b/src/main/java/com/listywave/list/application/dto/response/ListRecentResponse.java index afc7c7a4..34c07dcc 100644 --- a/src/main/java/com/listywave/list/application/dto/response/ListRecentResponse.java +++ b/src/main/java/com/listywave/list/application/dto/response/ListRecentResponse.java @@ -2,7 +2,7 @@ import com.listywave.list.application.domain.Item; import com.listywave.list.application.domain.Label; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import java.util.Comparator; import java.util.List; import lombok.Builder; @@ -11,7 +11,7 @@ public record ListRecentResponse( List lists ) { - public static ListRecentResponse of(List lists) { + public static ListRecentResponse of(List lists) { return ListRecentResponse.builder() .lists(ListResponse.toList(lists)) .build(); @@ -32,24 +32,24 @@ record ListResponse( List items ) { - public static List toList(List lists) { + public static List toList(List lists) { return lists.stream() .map(ListResponse::of) .toList(); } - public static ListResponse of(Lists lists) { + public static ListResponse of(ListEntity list) { 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())) + .id(list.getId()) + .category(list.getCategory().getKorNameValue()) + .backgroundColor(list.getBackgroundColor()) + .ownerId(list.getUser().getId()) + .ownerNickname(list.getUser().getNickname()) + .ownerProfileImage(list.getUser().getProfileImageUrl()) + .labels(LabelsResponse.toList(list.getLabels())) + .title(list.getTitle()) + .description(list.getDescription()) + .items(ItemsResponse.toList(list.getItems())) .build(); } } diff --git a/src/main/java/com/listywave/list/application/dto/response/ListSearchResponse.java b/src/main/java/com/listywave/list/application/dto/response/ListSearchResponse.java index d58ca97b..043233c3 100644 --- a/src/main/java/com/listywave/list/application/dto/response/ListSearchResponse.java +++ b/src/main/java/com/listywave/list/application/dto/response/ListSearchResponse.java @@ -1,7 +1,7 @@ package com.listywave.list.application.dto.response; import com.listywave.list.application.domain.Item; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import java.time.LocalDateTime; import java.util.List; import lombok.Builder; @@ -14,7 +14,7 @@ public record ListSearchResponse( boolean hasNext ) { - public static ListSearchResponse of(java.util.List lists, Long totalCount, Long cursorId, boolean hasNext) { + public static ListSearchResponse of(List lists, Long totalCount, Long cursorId, boolean hasNext) { return ListSearchResponse.builder() .resultLists(ListInfo.toList(lists)) .totalCount(totalCount) @@ -37,23 +37,23 @@ record ListInfo( String ownerProfileImageUrl ) { - public static List toList(java.util.List lists) { + public static List toList(List lists) { return lists.stream() .map(ListInfo::of) .toList(); } - private static ListInfo of(Lists lists) { + private static ListInfo of(ListEntity list) { return ListInfo.builder() - .id(lists.getId()) - .title(lists.getTitle()) - .items(ItemInfo.toList(lists.getItems())) - .isPublic(lists.isPublic()) - .backgroundColor(lists.getBackgroundColor()) - .updatedDate(lists.getUpdatedDate()) - .ownerId(lists.getUser().getId()) - .ownerNickname(lists.getUser().getNickname()) - .ownerProfileImageUrl(lists.getUser().getProfileImageUrl()) + .id(list.getId()) + .title(list.getTitle()) + .items(ItemInfo.toList(list.getItems())) + .isPublic(list.isPublic()) + .backgroundColor(list.getBackgroundColor()) + .updatedDate(list.getUpdatedDate()) + .ownerId(list.getUser().getId()) + .ownerNickname(list.getUser().getNickname()) + .ownerProfileImageUrl(list.getUser().getProfileImageUrl()) .build(); } } 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 fdb12f1e..703b8fc9 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 @@ -1,6 +1,6 @@ package com.listywave.list.application.dto.response; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import lombok.Builder; @Builder @@ -13,7 +13,7 @@ public record ListTrandingResponse( String backgroundColor ) { - public static ListTrandingResponse of(Lists list, String imageUrlTopRankItem) { + public static ListTrandingResponse of(ListEntity list, String imageUrlTopRankItem) { return ListTrandingResponse.builder() .id(list.getId()) .ownerId(list.getUser().getId()) 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 7bc0ea10..bc4d4fb9 100644 --- a/src/main/java/com/listywave/list/application/service/CommentService.java +++ b/src/main/java/com/listywave/list/application/service/CommentService.java @@ -5,7 +5,7 @@ import com.listywave.auth.application.domain.JwtManager; import com.listywave.list.application.domain.Comment; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.list.application.domain.Reply; import com.listywave.list.application.dto.response.CommentCreateResponse; import com.listywave.list.application.dto.response.CommentFindResponse; @@ -36,7 +36,7 @@ public CommentCreateResponse create(Long listId, String content) { // TODO: 프론트 단에서 댓글 생성 테스트 끝나면 원래대로 복구 // Long userId = jwtManager.read(accessToken); User user = userRepository.getById(1L); - Lists list = listRepository.getById(listId); + ListEntity list = listRepository.getById(listId); Comment comment = Comment.create(list, user, content); Comment saved = commentRepository.save(comment); @@ -45,7 +45,7 @@ public CommentCreateResponse create(Long listId, String content) { } public CommentFindResponse getComments(Long listId, int size, Long cursorId) { - Lists list = listRepository.getById(listId); + ListEntity list = listRepository.getById(listId); List comments = commentRepository.getComments(list, size, cursorId); if (comments.isEmpty()) { 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 a7b7403d..08a6359c 100644 --- a/src/main/java/com/listywave/list/application/service/ListService.java +++ b/src/main/java/com/listywave/list/application/service/ListService.java @@ -13,7 +13,7 @@ import com.listywave.list.application.domain.CategoryType; import com.listywave.list.application.domain.Comment; import com.listywave.list.application.domain.Item; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.list.application.domain.SortType; import com.listywave.list.application.dto.ListCreateCommand; import com.listywave.list.application.dto.response.ListCreateResponse; @@ -66,7 +66,7 @@ public ListCreateResponse listCreate( Boolean hasCollaboratorId = isExistCollaborator(collaboratorIds); validateDuplicateCollaborators(collaboratorIds); - Lists list = Lists.createList( + ListEntity list = ListEntity.createList( user, listCreateCommand, labels, @@ -138,7 +138,7 @@ private Boolean isLabelCountValid(List labels) { } public ListDetailResponse getListDetail(Long listId, String accessToken) { - Lists list = listRepository.getById(listId); + ListEntity list = listRepository.getById(listId); List collaborators = collaboratorRepository.findAllByListId(listId); if (accessToken.isBlank()) { @@ -149,8 +149,8 @@ public ListDetailResponse getListDetail(Long listId, String accessToken) { @Transactional(readOnly = true) public List getTrandingList() { - List lists = listRepository.findTrandingLists(); - lists.forEach(Lists::sortItems); + List lists = listRepository.findTrandingLists(); + lists.forEach(ListEntity::sortItems); return lists.stream() .map(list -> ListTrandingResponse.of(list, getImageUrlTopRankItem(list.getItems()))) .toList(); @@ -167,7 +167,7 @@ private String getImageUrlTopRankItem(List items) { public void deleteList(Long listId) { imageService.deleteAllOfListImages(listId); - Lists list = listRepository.getById(listId); + ListEntity list = listRepository.getById(listId); collaboratorRepository.deleteAllByList(list); List comments = commentRepository.findAllByList(list); @@ -187,10 +187,10 @@ public ListRecentResponse getRecentLists(String accessToken) { List followingUsers = follows.stream() .map(Follow::getFollowingUser) .toList(); - List recentListsByFollowing = listRepository.getRecentListsByFollowing(followingUsers); - return ListRecentResponse.of(recentListsByFollowing); + List recentListByFollowing = listRepository.getRecentListsByFollowing(followingUsers); + return ListRecentResponse.of(recentListByFollowing); } - List recentLists = listRepository.getRecentLists(); + List recentLists = listRepository.getRecentLists(); return ListRecentResponse.of(recentLists); } @@ -202,9 +202,9 @@ private boolean isSignedIn(String accessToken) { // TODO: 관련도 순 추가 (List 일급 컬렉션 만들어서 Scoring 하는 방식) // TODO: 리팩터링 public ListSearchResponse search(String keyword, SortType sortType, CategoryType category, int size, Long cursorId) { - List all = listRepository.findAll(); + List all = listRepository.findAll(); - List filtered = all.stream() + List filtered = all.stream() .filter(list -> list.isIncluded(category)) .filter(list -> list.isRelatedWith(keyword)) .sorted((list, other) -> { @@ -218,14 +218,14 @@ public ListSearchResponse search(String keyword, SortType sortType, CategoryType }) .toList(); - List result; + List result; if (cursorId == 0L) { if (filtered.size() >= size) { return ListSearchResponse.of(filtered.subList(0, size), (long) filtered.size(), filtered.get(size - 1).getId(), true); } return ListSearchResponse.of(filtered, (long) filtered.size(), filtered.get(filtered.size() - 1).getId(), false); } else { - Lists cursorList = listRepository.getById(cursorId); + ListEntity cursorList = listRepository.getById(cursorId); int cursorIndex = filtered.indexOf(cursorList); int startIndex = cursorIndex + 1; diff --git a/src/main/java/com/listywave/list/repository/CommentRepository.java b/src/main/java/com/listywave/list/repository/CommentRepository.java index 4976184a..e4e6d614 100644 --- a/src/main/java/com/listywave/list/repository/CommentRepository.java +++ b/src/main/java/com/listywave/list/repository/CommentRepository.java @@ -4,7 +4,7 @@ import com.listywave.common.exception.CustomException; import com.listywave.list.application.domain.Comment; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; @@ -14,7 +14,7 @@ default Comment getById(Long id) { return findById(id).orElseThrow(() -> new CustomException(NOT_FOUND)); } - List findAllByList(Lists list); + List findAllByList(ListEntity list); - Long countByList(Lists list); + Long countByList(ListEntity list); } diff --git a/src/main/java/com/listywave/list/repository/CustomCommentRepository.java b/src/main/java/com/listywave/list/repository/CustomCommentRepository.java index edd2f51f..cd835d51 100644 --- a/src/main/java/com/listywave/list/repository/CustomCommentRepository.java +++ b/src/main/java/com/listywave/list/repository/CustomCommentRepository.java @@ -1,10 +1,10 @@ package com.listywave.list.repository; import com.listywave.list.application.domain.Comment; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import java.util.List; public interface CustomCommentRepository { - List getComments(Lists list, int size, Long cursorId); + List getComments(ListEntity list, int size, Long cursorId); } diff --git a/src/main/java/com/listywave/list/repository/CustomCommentRepositoryImpl.java b/src/main/java/com/listywave/list/repository/CustomCommentRepositoryImpl.java index 53028cc8..c92bcc21 100644 --- a/src/main/java/com/listywave/list/repository/CustomCommentRepositoryImpl.java +++ b/src/main/java/com/listywave/list/repository/CustomCommentRepositoryImpl.java @@ -1,10 +1,10 @@ package com.listywave.list.repository; import static com.listywave.list.application.domain.QComment.comment; -import static com.listywave.list.application.domain.QLists.lists; +import static com.listywave.list.application.domain.QListEntity.listEntity; import com.listywave.list.application.domain.Comment; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; import lombok.RequiredArgsConstructor; @@ -15,11 +15,12 @@ public class CustomCommentRepositoryImpl implements CustomCommentRepository { private final JPAQueryFactory queryFactory; @Override - public List getComments(Lists list, int size, Long cursorId) { + public List getComments(ListEntity list, int size, Long cursorId) { return queryFactory.selectFrom(comment) - .join(lists).fetchJoin() - .on(lists.id.eq(comment.list.id)) + .join(listEntity).fetchJoin() + .on(listEntity.id.eq(comment.list.id)) .where( + listEntity.id.eq(list.getId()), comment.id.gt(cursorId) ) .orderBy(comment.id.asc()) diff --git a/src/main/java/com/listywave/list/repository/list/ListRepository.java b/src/main/java/com/listywave/list/repository/list/ListRepository.java index d1492b66..73c6d28b 100644 --- a/src/main/java/com/listywave/list/repository/list/ListRepository.java +++ b/src/main/java/com/listywave/list/repository/list/ListRepository.java @@ -3,13 +3,13 @@ import static com.listywave.common.exception.ErrorCode.NOT_FOUND; import com.listywave.common.exception.CustomException; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.list.repository.list.custom.CustomListRepository; import org.springframework.data.jpa.repository.JpaRepository; -public interface ListRepository extends JpaRepository, CustomListRepository { +public interface ListRepository extends JpaRepository, CustomListRepository { - default Lists getById(Long listId) { + default ListEntity getById(Long listId) { return findById(listId).orElseThrow(() -> new CustomException(NOT_FOUND)); } } diff --git a/src/main/java/com/listywave/list/repository/list/custom/CustomListRepository.java b/src/main/java/com/listywave/list/repository/list/custom/CustomListRepository.java index 6069f6a5..7261bd36 100644 --- a/src/main/java/com/listywave/list/repository/list/custom/CustomListRepository.java +++ b/src/main/java/com/listywave/list/repository/list/custom/CustomListRepository.java @@ -1,14 +1,14 @@ package com.listywave.list.repository.list.custom; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.user.application.domain.User; import java.util.List; public interface CustomListRepository { - List findTrandingLists(); + List findTrandingLists(); - List getRecentLists(); + List getRecentLists(); - List getRecentListsByFollowing(List followingUsers); + List getRecentListsByFollowing(List followingUsers); } diff --git a/src/main/java/com/listywave/list/repository/list/custom/impl/CustomListRepositoryImpl.java b/src/main/java/com/listywave/list/repository/list/custom/impl/CustomListRepositoryImpl.java index 38ea0a4d..0c80727d 100644 --- a/src/main/java/com/listywave/list/repository/list/custom/impl/CustomListRepositoryImpl.java +++ b/src/main/java/com/listywave/list/repository/list/custom/impl/CustomListRepositoryImpl.java @@ -2,10 +2,10 @@ import static com.listywave.list.application.domain.QItem.item; import static com.listywave.list.application.domain.QLabel.label; -import static com.listywave.list.application.domain.QLists.lists; +import static com.listywave.list.application.domain.QListEntity.listEntity; import static com.listywave.user.application.domain.QUser.user; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.list.repository.list.custom.CustomListRepository; import com.listywave.user.application.domain.User; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -19,44 +19,44 @@ public class CustomListRepositoryImpl implements CustomListRepository { private final JPAQueryFactory queryFactory; @Override - public List findTrandingLists() { + public List findTrandingLists() { return queryFactory - .selectFrom(lists) - .leftJoin(lists.items, item) + .selectFrom(listEntity) + .leftJoin(listEntity.items, item) .distinct() .limit(10) - .orderBy(lists.collectCount.desc(), lists.viewCount.desc()) + .orderBy(listEntity.collectCount.desc(), listEntity.viewCount.desc()) .fetch(); } @Override - public List getRecentLists() { + public List getRecentLists() { return queryFactory - .selectFrom(lists) - .join(lists.user, user).fetchJoin() - .leftJoin(lists.labels, label) - .leftJoin(lists.items, item) + .selectFrom(listEntity) + .join(listEntity.user, user).fetchJoin() + .leftJoin(listEntity.labels, label) + .leftJoin(listEntity.items, item) .distinct() .limit(10) - .orderBy(lists.updatedDate.desc()) + .orderBy(listEntity.updatedDate.desc()) .fetch(); } @Override - public List getRecentListsByFollowing(List followingUsers) { + public List getRecentListsByFollowing(List followingUsers) { return queryFactory - .selectFrom(lists) - .join(lists.user, user).fetchJoin() - .leftJoin(lists.labels, label) - .leftJoin(lists.items, item) - .where(lists.user.id.in( + .selectFrom(listEntity) + .join(listEntity.user, user).fetchJoin() + .leftJoin(listEntity.labels, label) + .leftJoin(listEntity.items, item) + .where(listEntity.user.id.in( followingUsers.stream() .map(User::getId) .collect(Collectors.toList()) )) .distinct() .limit(10) - .orderBy(lists.updatedDate.desc()) + .orderBy(listEntity.updatedDate.desc()) .fetch(); } } diff --git a/src/main/java/com/listywave/list/repository/reply/CustomReplyRepository.java b/src/main/java/com/listywave/list/repository/reply/CustomReplyRepository.java index eb24ac2b..0b603173 100644 --- a/src/main/java/com/listywave/list/repository/reply/CustomReplyRepository.java +++ b/src/main/java/com/listywave/list/repository/reply/CustomReplyRepository.java @@ -1,8 +1,8 @@ package com.listywave.list.repository.reply; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; public interface CustomReplyRepository { - Long countByList(Lists list); + Long countByList(ListEntity list); } diff --git a/src/main/java/com/listywave/list/repository/reply/CustomReplyRepositoryImpl.java b/src/main/java/com/listywave/list/repository/reply/CustomReplyRepositoryImpl.java index c0bcda24..4757046b 100644 --- a/src/main/java/com/listywave/list/repository/reply/CustomReplyRepositoryImpl.java +++ b/src/main/java/com/listywave/list/repository/reply/CustomReplyRepositoryImpl.java @@ -1,10 +1,10 @@ package com.listywave.list.repository.reply; import static com.listywave.list.application.domain.QComment.comment; -import static com.listywave.list.application.domain.QLists.lists; +import static com.listywave.list.application.domain.QListEntity.listEntity; import static com.listywave.list.application.domain.QReply.reply; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -13,11 +13,12 @@ public class CustomReplyRepositoryImpl implements CustomReplyRepository { private final JPAQueryFactory queryFactory; - public Long countByList(Lists list) { + public Long countByList(ListEntity list) { return queryFactory.select(reply.count()) .from(reply) .leftJoin(comment).on(comment.id.eq(reply.id)) - .leftJoin(lists).on(lists.id.eq(comment.list.id)) + .leftJoin(listEntity).on(listEntity.id.eq(comment.list.id)) + .where(listEntity.id.eq(list.getId())) .fetchOne(); } } 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 909dc604..a14bd9f2 100644 --- a/src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java +++ b/src/main/java/com/listywave/user/application/dto/AllUserListsResponse.java @@ -1,6 +1,6 @@ package com.listywave.user.application.dto; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import java.util.List; public record AllUserListsResponse( @@ -9,7 +9,7 @@ public record AllUserListsResponse( List feedLists ) { - public static AllUserListsResponse of(boolean hasNext, Long cursorId, List feedLists) { + public static AllUserListsResponse of(boolean hasNext, Long cursorId, List feedLists) { return new AllUserListsResponse( cursorId, hasNext, @@ -17,7 +17,7 @@ public static AllUserListsResponse of(boolean hasNext, Long cursorId, List toList(List feedLists) { + public static List toList(List feedLists) { return feedLists.stream() .map(FeedListsResponse::of) .toList(); 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 0d028240..5be08d4d 100644 --- a/src/main/java/com/listywave/user/application/dto/FeedListsResponse.java +++ b/src/main/java/com/listywave/user/application/dto/FeedListsResponse.java @@ -1,7 +1,7 @@ package com.listywave.user.application.dto; import com.listywave.list.application.domain.Item; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import java.util.List; import java.util.stream.Collectors; import lombok.Builder; @@ -15,13 +15,13 @@ public record FeedListsResponse( List listItems ) { - public static FeedListsResponse of(Lists lists) { + public static FeedListsResponse of(ListEntity list) { return FeedListsResponse.builder() - .id(lists.getId()) - .title(lists.getTitle()) - .isPublic(lists.isPublic()) - .backgroundColor(lists.getBackgroundColor()) - .listItems(ListItemsResponse.toList(lists)) + .id(list.getId()) + .title(list.getTitle()) + .isPublic(list.isPublic()) + .backgroundColor(list.getBackgroundColor()) + .listItems(ListItemsResponse.toList(list)) .build(); } } @@ -43,8 +43,8 @@ public static ListItemsResponse of(Item item) { .build(); } - public static List toList(Lists lists) { - return lists.getItems().stream() + public static List toList(ListEntity list) { + return list.getItems().stream() .map(ListItemsResponse::of) .collect(Collectors.toList()); } 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 8ccd4dcf..86e407e0 100644 --- a/src/main/java/com/listywave/user/application/service/UserService.java +++ b/src/main/java/com/listywave/user/application/service/UserService.java @@ -3,7 +3,7 @@ import com.listywave.auth.application.domain.JwtManager; import com.listywave.common.util.UserUtil; import com.listywave.list.application.domain.CategoryType; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.user.application.domain.Follow; import com.listywave.user.application.domain.User; import com.listywave.user.application.dto.AllUserListsResponse; @@ -61,7 +61,7 @@ public AllUserListsResponse getAllListOfUser( ) { userUtil.getUserByUserid(userId); - List feedList = userRepository.findFeedLists(userId, type, category, cursorId, size); + List feedList = userRepository.findFeedLists(userId, type, category, cursorId, size); boolean hasNext = false; cursorId = null; 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 56e8cc60..afe29ff8 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,7 +2,7 @@ import com.listywave.collaborator.application.dto.CollaboratorResponse; import com.listywave.list.application.domain.CategoryType; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.user.application.domain.User; import java.util.List; import org.springframework.data.domain.Pageable; @@ -10,7 +10,7 @@ public interface CustomUserRepository { - List findFeedLists(Long userId, String type, CategoryType category, Long cursorId, int size); + 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 f53d064b..53a1188e 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 @@ -1,12 +1,12 @@ 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 static com.listywave.list.application.domain.QListEntity.listEntity; import static com.listywave.user.application.domain.QUser.user; import com.listywave.collaborator.application.dto.CollaboratorResponse; import com.listywave.list.application.domain.CategoryType; -import com.listywave.list.application.domain.Lists; +import com.listywave.list.application.domain.ListEntity; import com.listywave.user.application.domain.User; import com.listywave.user.repository.user.custom.CustomUserRepository; import com.querydsl.core.types.Projections; @@ -25,11 +25,11 @@ public class CustomUserRepositoryImpl implements CustomUserRepository { private final JPAQueryFactory queryFactory; @Override - public List findFeedLists(Long userId, String type, CategoryType category, Long cursorId, int size) { + public List findFeedLists(Long userId, String type, CategoryType category, Long cursorId, int size) { return queryFactory - .select(lists) - .from(lists) - .leftJoin(lists.items, item) + .select(listEntity) + .from(listEntity) + .leftJoin(listEntity.items, item) .where( userIdEq(userId), typeEq(type), @@ -38,40 +38,40 @@ public List findFeedLists(Long userId, String type, CategoryType category ) .distinct() .limit(size + 1) - .orderBy(lists.updatedDate.desc()) + .orderBy(listEntity.updatedDate.desc()) .fetch(); } private BooleanExpression listIdLt(Long cursorId) { - return cursorId == null ? null : lists.id.lt(cursorId); + return cursorId == null ? null : listEntity.id.lt(cursorId); } private BooleanExpression categoryEq(CategoryType categoryCode) { if ("0".equals(categoryCode.getCodeValue())) { return null; } - return lists.category.eq(categoryCode); + return listEntity.category.eq(categoryCode); } private BooleanExpression typeEq(String type) { if (type.equals("my")) { - return lists.hasCollaboration.eq(false); + return listEntity.hasCollaboration.eq(false); } - return lists.hasCollaboration.eq(true); + return listEntity.hasCollaboration.eq(true); } private BooleanExpression userIdEq(Long userId) { - return userId == null ? null : lists.user.id.eq(userId); + return userId == null ? null : listEntity.user.id.eq(userId); } @Override public List getRecommendUsers() { return queryFactory .select(user) - .from(lists) - .rightJoin(lists.user, user) + .from(listEntity) + .rightJoin(listEntity.user, user) .groupBy(user) - .orderBy(lists.updatedDate.max().desc()) + .orderBy(listEntity.updatedDate.max().desc()) .limit(10) .fetch(); }