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, refactor: ListEntity 관련 전체 리팩터링 및 관련도순 정렬 기능 추가 #126

Merged
merged 14 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -15,6 +15,7 @@ public class JwtManager {

private static final SecretKey key = Jwts.SIG.HS256.key().build();
private static final Long ACCESS_TOKEN_VALID_MILLISECOND = HOURS.toMillis(8);
private static final String PREFIX = "Bearer ";

public String createToken(Long userId) {
Date now = new Date();
Expand All @@ -30,10 +31,10 @@ public String createToken(Long userId) {
}

public Long read(String token) {
if (token.isBlank() || !token.startsWith("Bearer ")) {
if (token.isBlank() || !token.startsWith(PREFIX)) {
throw new CustomException(REQUIRED_ACCESS_TOKEN);
}
token = token.substring(7);
token = token.substring(PREFIX.length());
kdkdhoho marked this conversation as resolved.
Show resolved Hide resolved

String subject = Jwts.parser()
.verifyWith(key)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.listywave.collaborator.application.domain;

import com.listywave.list.application.domain.ListEntity;
import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import com.listywave.list.application.domain.list.ListEntity;
import com.listywave.user.application.domain.User;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -19,26 +20,23 @@
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = PROTECTED)
public class Collaborator {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "user_id")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "list_id")
private ListEntity list;

public static Collaborator createCollaborator(User user, ListEntity list) {
return Collaborator.builder()
.user(user)
.list(list)
.build();
public static Collaborator init(User user, ListEntity list) {
return new Collaborator(null, user, list);
}

public String getUserNickname() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.listywave.collaborator.application.domain;

import static com.listywave.common.exception.ErrorCode.DUPLICATE_USER;

import com.listywave.common.exception.CustomException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Collaborators {

private final List<Collaborator> collaborators;

public Collaborators(List<Collaborator> collaborators) {
this.collaborators = new ArrayList<>(collaborators);
}

public static void validateDuplicateCollaboratorIds(List<Long> collaboratorIds) {
Set<Long> uniqueIds = new HashSet<>(collaboratorIds);
if (collaboratorIds.size() != uniqueIds.size()) {
throw new CustomException(DUPLICATE_USER, "중복된 콜라보레이터를 선택할 수 없습니다.");
}
}

public List<Collaborator> getCollaborators() {
return new ArrayList<>(collaborators);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 방식이 일급컬렉션 방식이군요 확실히 Collaborator의 관련된 부분을 해당 레벨에서 처리할 수 있어 응집력도 좋아보이고 컬렉션의 불변성도 보장되어 보여 좋아보이네요
동호님 덕분에 좋은 방식 알아갑니다 ㅎㅎ

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 해당부분은 따로 양방향으로 되어 있는 부분이 없어서 별도의 일급컬렉션으로 관리하는거라 @embeddable이 지정이 안되있는게 맞죠!?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 맞습니다! List<Collaborator>을 의존하는 엔티티가 없어서 굳이 @Embeddable을 달아줄 필요가 없네용

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.listywave.collaborator.repository;

import com.listywave.collaborator.application.domain.Collaborator;
import com.listywave.list.application.domain.ListEntity;
import com.listywave.list.application.domain.list.ListEntity;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface CollaboratorRepository extends JpaRepository<Collaborator, Long> {

List<Collaborator> findAllByListId(Long listId);

List<Collaborator> findAllByList(ListEntity list);
@Query("select c from Collaborator c join fetch c.list l where c.user.id =:userId")
List<Collaborator> findAllByUserId(Long userId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.listywave.collection.application.domain;

import com.listywave.list.application.domain.ListEntity;
import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import com.listywave.list.application.domain.list.ListEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -19,15 +20,15 @@
@Getter
@AllArgsConstructor
@Table(name = "collection")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = PROTECTED)
public class Collect {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = IDENTITY)
private Long id;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "list_id")
@ManyToOne(fetch = FetchType.LAZY)
private ListEntity list;

@Column(name = "user_id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.listywave.collection.repository.CollectionRepository;
import com.listywave.common.exception.CustomException;
import com.listywave.common.exception.ErrorCode;
import com.listywave.list.application.domain.ListEntity;
import com.listywave.list.application.domain.list.ListEntity;
import com.listywave.list.repository.list.ListRepository;
import com.listywave.user.application.domain.User;
import com.listywave.user.repository.user.UserRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.listywave.collection.repository;

import com.listywave.collection.application.domain.Collect;
import com.listywave.list.application.domain.ListEntity;
import com.listywave.list.application.domain.list.ListEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CollectionRepository extends JpaRepository<Collect, Long> {
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/listywave/common/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.listywave.common;

import static jakarta.persistence.GenerationType.IDENTITY;
import static jakarta.persistence.TemporalType.TIMESTAMP;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Temporal;
import java.time.LocalDateTime;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
Expand All @@ -18,13 +21,15 @@
public class BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
@GeneratedValue(strategy = IDENTITY)
private Long id;

@CreatedDate
@Column(updatable = false)
protected LocalDateTime createdDate;
@Temporal(TIMESTAMP)
private LocalDateTime createdDate;

@LastModifiedDate
protected LocalDateTime updatedDate;
@Temporal(TIMESTAMP)
private LocalDateTime updatedDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.listywave.image.application.dto.ExtensionRanks;
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.ListEntity;
import com.listywave.list.application.domain.item.Item;
import com.listywave.list.application.domain.list.ListEntity;
import com.listywave.list.repository.ItemRepository;
import com.listywave.list.repository.list.ListRepository;
import com.listywave.user.application.domain.User;
Expand Down

This file was deleted.

101 changes: 0 additions & 101 deletions src/main/java/com/listywave/list/application/domain/Item.java

This file was deleted.

Loading
Loading