-
Notifications
You must be signed in to change notification settings - Fork 3
[#23] create Entity, schema about Item & Order #24
base: feature/19
Are you sure you want to change the base?
Conversation
jjeda
commented
Sep 28, 2019
- 아이템 도메인 생성 ( 카테고리, 아이템 다대다 매핑)
- 주문 도메인 생성 ( delivery <-> order 1:1 매핑 / Order <-> item n:m 매핑 / Account <-> order 1:n 매핑)
- 스키마 생성
- 아이템 도메인 생성 ( 카테고리, 아이템 다대다 매핑) - 주문 도메인 생성 ( delivery <-> order 1:1 매핑 / Order <-> item n:m 매핑 / Account <-> order 1:n 매핑) - 스키마 생성
@@ -1,13 +1,15 @@ | |||
package me.jjeda.mall.accounts.domain; | |||
package me.jjeda.mall.common; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
내부에 더 세밀한 패키지를 만들어주는게 좋을 것 같네요. model이니 common.model
로 해주어도 될 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[팁] common에 공통된 것들을 넣는 것을 잘못 관리하면 조금이라도 공통적으로 쓰이는 코드들이 common에 모두 몰리게 되어 common이 너무 방대해질 수 있습니다. (이를 common의 지옥이라고 합니다)
* DELIVERY : 배송 중 | ||
* COMP : 배송 완료 | ||
*/ | ||
public enum DeliveryStatus { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@Column(name = "order_id") | ||
private Long id; | ||
|
||
@ManyToOne |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ManyToOne
인 이유를 알 수 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우선 한 구매자가 여러개의 주문을 하는 상황이 있기 때문에 Account
: Order
는 일대다 매핑으로 설계 하였습니다. Account
에서 @OneToMany
로 설정하지 않고 Order
에서 @ManyToOne
으로 설계한 이유는
One
이 연관관계의 주인이라면One
에서 수정했을 때Many
Table에 쿼리가 날아가는 상황이 발생하고- 이는 직관적이지 못하기 때문에
Many
를 관계의 주인으로 설정하고 (@ManyToOne
단방향) - 만약 추후에
Account
에서Order
에 참조해야 한다면 양방향 매핑
위와 같은 이유 입니다!
private Delivery delivery; | ||
|
||
@OneToMany(mappedBy = "order") | ||
private List<OrderItem> orderItems = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메뉴가 없는 주문은 없을 것 같은데 기본값을 빼주고 NotNull로 해주시는게 좋을 것 같네요~
private Item item; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "order_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보통 Order에서 OrderItem을 join해서 가져올텐데 여기에 명시해주지 않아도 되지 않을까요?
주문메뉴로 주문데이터를 불러올 가능성이 있는지도 궁금합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분도 위에와 같은 이유입니다!
@OneToMany
단방향 관계보다@ManyToOne
@OneToMany
양방향 관계로 (관계의 주인Many
)- https://velog.io/@dpudpu/5
- https://homoefficio.github.io/2019/04/28/JPA-%EC%9D%BC%EB%8C%80%EB%8B%A4-%EB%8B%A8%EB%B0%A9%ED%96%A5-%EB%A7%A4%ED%95%91-%EC%9E%98%EB%AA%BB-%EC%82%AC%EC%9A%A9%ED%95%98%EB%A9%B4-%EB%B2%8C%EC%96%B4%EC%A7%80%EB%8A%94-%EC%9D%BC/
를 참고 하였습니다!
@Entity | ||
@Getter @Setter | ||
@Table(name = "orders") | ||
public class Order { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아직 안만드신것이겠지만 결제정보도 있으면 좋을 것 같네요~
src/main/resources/schema.sql
Outdated
create table category ( | ||
category_id bigint not null, | ||
name varchar(255), | ||
primary key (category_id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
관계있는 테이블에 외래키도 같이 걸어주면 좋을 것 같네요~
src/main/resources/schema.sql
Outdated
|
||
create table orders ( | ||
order_id bigint not null, | ||
order_at datetime, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
날짜로 검색할 필요성이 있을 것 같은데 인덱스를 걸어주면 좋을 것 같습니다
- Validation 추가 - schema 에 인덱스 및 외래 키 설정 추가
create table item_category ( | ||
item_category_id bigint not null, | ||
category_id bigint, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
들여쓰기가 조금씩 차이가 있는데 이를 맞춰주는것이 컨벤션상 좋을 것 같습니다~
primary key (item_category_id), | ||
foreign key (category_id) references category (category_id), | ||
foreign key (item_id) references item (item_id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
);
는 개행해주면 가독성면에서 더 좋을 것 같습니다~
create table order_item ( | ||
order_item_id bigint not null, | ||
count integer not null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
count
는 굳이 컬럼으로 넣지 않아도 count()연산으로 해결할 수 있을 것 같습니다
|
||
create table delivery ( | ||
delivery_id bigint not null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
담당 배달원이 누구인지도 명시해줘야할것같습니다~