spring-toy-project-2023 / karrot-market

당근마켓 클론코딩 토이 프로젝트
0 stars 0 forks source link

karrot-0015: 도메인 모듈별 엔티티 설계 #31

Open tae0y opened 1 year ago

tae0y commented 1 year ago

import javax.persistence.*; import java.time.LocalDateTime;

@Data @ToString //lazyloading과 tostring주의! @Entity @Table(schema = "goods") public class Product { @Id @GeneratedValue(strategy = GenerationType.AUTO) //TODO: ID 생성정책이 정해지면 정책에 따라 바꾸기 @Column(name = "id", nullable = false) private Long id;

//@Column(name = "seller_id", nullable = false)
//private Long sellerId;
//TODO: [순환참조] Product-Address는 양방향인가 단방향 매핑인가
//TODO: [N+1] 성능개선이 필요한경우 JPQL에서 fetch join으로 조회
//TODO: CASCADE 영속성전이 제약조건 정하기, User가 사라지면 Product는? 정하기나름임
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "seller_id")
private User user;

//@Column(name = "selling_area_id", nullable = false)
//private int sellingAreaId;
//TODO: [순환참조] Product-Address는 양방향인가 단방향 매핑인가
//TODO: [N+1] 성능개선이 필요한경우 JPQL에서 fetch join으로 조회
//TODO: CASCADE 영속성전이 제약조건 정하기, Address가 사라지면 Product는? 유지
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "selling_area_id")
private Address address;

@Column(name = "category_id", nullable = false)
private int categoryId;

@Column(name = "title", nullable = false)
private String title;

@Enumerated(EnumType.STRING)
@Column(name = "status", nullable = false)
private STATUS_TYPE status;

@Column(name = "sell_price", nullable = true)
private int sellPrice;

@Column(name = "price_get_offer", nullable = false)
private String priceGetOffer; //가격제안 받을지여부

@Column(name = "view_count", nullable = false)
private int viewCount;

@Column(name = "description", nullable = false)
private String description;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "refreshed_at", nullable = false)
private LocalDateTime refreshedAt;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;

//TODO: Enum타입 확인 판매중, 예약중, 거래완료, 나눔중, 나눔완료
enum STATUS_TYPE { SELLING, RESERVED, SELLED, SHARING, SHARED }

}

class User{ } class Address{ } class PriceOffer{ }

hello-yoochul commented 1 year ago

의논 할 것

1. 키워드 등록

NotificationKeyword

@Data
@Entity
@Table(schema = "notification_keywords")
public class NotificationKeyword {
        @Id
    @NotNull
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
        @ManyToOne
      @JoinColumn(name="users_id")
    private User registrants;

    @NotNull
        @Size(min = 1, max=10) 
        @Column(name = "keyword")
    private String keyword;

    @NotNull
        @CreatedDate
        @Column(name = "crated_at")
    private LocalDateTime cratedAt;
}

User

@Data
@Entity
@Table(schema = "users")
public class User {
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "users")
    private Set<NotificationKeyword> keywords;
}

2. 위시 리스트 등록

WishList

@Data
@Entity
@Table(schema = "wish_lists")
public class WishList {
        @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @OneToOne(mappedBy="wish_lists")
    private User registrant;

    @NotNull
      @ManyToMany
    @JoinTable(
      name = "wish_lists_goods",  
      joinColumns = @JoinColumn(name = "wish_lists_id"), 
      inverseJoinColumns = @JoinColumn(name = "goods_id"))
    private Set<Product> product;

    @NotNull
        @CreatedDate
        @Column(name = "crated_at")
    private LocalDateTime cratedAt;
}

User

@Data
@Entity
@Table(schema = "users")
public class User {
    @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "users")
    private WishList wishList;
}

Product

@Data
@Entity
@Table(schema = "goods")
public class Product {
        @ManyToMany
    @JoinTable(
      name = "wish_lists_goods",  
      joinColumns = @JoinColumn(name = "goods_id"), 
      inverseJoinColumns = @JoinColumn(name = "wish_lists_id"))
        private Set<WishList> wishList;
}

3. 가격 제안

price offer

@Data
@ToString
@Entity
@Table(schema = "price_offers")
public class PriceOffer {
    @Id
    @NotNull
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @ManyToOne
    @JoinColumn(name="users_id")
    private User offerer;

    @NotNull
    @ManyToOne
      @JoinColumn(name="goods_id")
    private Product product;

    @NotNull
    @Column(name = "offered_price")
    private BigDecimal price;

    @NotNull
    @Column(name = "accept_or_not")
    private boolean accepted;

    @NotNull
    @CreatedDate
    private LocalDateTime cratedAt;
}

User

@Data
@Entity
@Table(schema = "users")
public class User {
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "users")
    private Set<PriceOffer> priceOffers;
}

Product

@Data
@Entity
@Table(schema = "goods")
public class Product {
        @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "goods")
        private Set<PriceOffer> priceOffers;
}