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

refactor: List 엔티티 이름 변경 #109

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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;

public interface CollaboratorRepository extends JpaRepository<Collaborator, Long> {

List<Collaborator> findAllByListId(Long listId);

void deleteAllByList(Lists lists);
void deleteAllByList(ListEntity list);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,8 +61,8 @@ public List<ItemPresignedUrlResponse> 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) -> {
Expand All @@ -88,8 +88,8 @@ public void uploadCompleteItemImages(Long ownerId, Long listId, List<ExtensionRa
//TODO: 보내는 회원이 존재하는지 검증 (security)
final User user = userUtil.getUserByUserid(ownerId);

Lists lists = findListById(listId);
validateListUserMismatch(lists, user);
ListEntity list = findListById(listId);
validateListUserMismatch(list, user);

extensionRanks.forEach(
extensionRank -> {
Expand Down Expand Up @@ -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, "존재하지 않는 리스트입니다."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Label {

@ManyToOne
@JoinColumn(name = "list_Id")
private Lists list;
private ListEntity list;

@Embedded
private LabelName labelName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -95,7 +95,7 @@ public class Lists {
@LastModifiedDate
private LocalDateTime updatedDate;

public static void addLabelToList(Lists list, List<String> labels) {
public static void addLabelToList(ListEntity list, List<String> labels) {
for (String label : labels) {
list.getLabels().add(
Label.builder()
Expand All @@ -110,7 +110,7 @@ public static void addLabelToList(Lists list, List<String> labels) {
}
}

private static void addItemToList(Lists list, List<ItemCreateRequest> items) {
private static void addItemToList(ListEntity list, List<ItemCreateRequest> items) {
for (ItemCreateRequest item : items) {
list.getItems().add(
Item.builder()
Expand Down Expand Up @@ -141,28 +141,29 @@ private static void addItemToList(Lists list, List<ItemCreateRequest> items) {
}
}

public static Lists createList(
public static ListEntity createList(
User user,
ListCreateCommand list,
ListCreateCommand command,
List<String> labels,
List<ItemCreateRequest> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +29,7 @@ public record ListDetailResponse(
int viewCount
) {

public static ListDetailResponse of(Lists list, User user, boolean isCollected, List<Collaborator> collaborators) {
public static ListDetailResponse of(ListEntity list, User user, boolean isCollected, List<Collaborator> collaborators) {
return ListDetailResponse.builder()
.category(list.getCategoryName())
.labels(LabelResponse.toList(list.getLabels()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,7 +11,7 @@
public record ListRecentResponse(
List<ListResponse> lists
) {
public static ListRecentResponse of(List<Lists> lists) {
public static ListRecentResponse of(List<ListEntity> lists) {
return ListRecentResponse.builder()
.lists(ListResponse.toList(lists))
.build();
Expand All @@ -32,24 +32,24 @@ record ListResponse(
List<ItemsResponse> items
) {

public static List<ListResponse> toList(List<Lists> lists) {
public static List<ListResponse> toList(List<ListEntity> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +14,7 @@ public record ListSearchResponse(
boolean hasNext
) {

public static ListSearchResponse of(java.util.List<Lists> lists, Long totalCount, Long cursorId, boolean hasNext) {
public static ListSearchResponse of(List<ListEntity> lists, Long totalCount, Long cursorId, boolean hasNext) {
return ListSearchResponse.builder()
.resultLists(ListInfo.toList(lists))
.totalCount(totalCount)
Expand All @@ -37,23 +37,23 @@ record ListInfo(
String ownerProfileImageUrl
) {

public static List<ListInfo> toList(java.util.List<Lists> lists) {
public static List<ListInfo> toList(List<ListEntity> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<Comment> comments = commentRepository.getComments(list, size, cursorId);
if (comments.isEmpty()) {
Expand Down
Loading
Loading