Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

[#23] create Entity, schema about Item & Order #24

Open
wants to merge 2 commits into
base: feature/19
Choose a base branch
from

Conversation

jjeda
Copy link
Collaborator

@jjeda 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 매핑)
- 스키마 생성
@jjeda jjeda requested a review from f-lab-dev September 28, 2019 20:01
@jjeda jjeda self-assigned this Sep 28, 2019
@@ -1,13 +1,15 @@
package me.jjeda.mall.accounts.domain;
package me.jjeda.mall.common;
Copy link
Member

Choose a reason for hiding this comment

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

내부에 더 세밀한 패키지를 만들어주는게 좋을 것 같네요. model이니 common.model로 해주어도 될 것 같습니다.

Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

ManyToOne인 이유를 알 수 있을까요?

Copy link
Collaborator Author

@jjeda jjeda Sep 29, 2019

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<>();
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

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

보통 Order에서 OrderItem을 join해서 가져올텐데 여기에 명시해주지 않아도 되지 않을까요?
주문메뉴로 주문데이터를 불러올 가능성이 있는지도 궁금합니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이 부분도 위에와 같은 이유입니다!

를 참고 하였습니다!

@Entity
@Getter @Setter
@Table(name = "orders")
public class Order {
Copy link
Member

Choose a reason for hiding this comment

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

아직 안만드신것이겠지만 결제정보도 있으면 좋을 것 같네요~

create table category (
category_id bigint not null,
name varchar(255),
primary key (category_id));
Copy link
Member

Choose a reason for hiding this comment

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

관계있는 테이블에 외래키도 같이 걸어주면 좋을 것 같네요~


create table orders (
order_id bigint not null,
order_at datetime,
Copy link
Member

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,
Copy link
Member

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));
Copy link
Member

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,
Copy link
Member

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,
Copy link
Member

Choose a reason for hiding this comment

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

담당 배달원이 누구인지도 명시해줘야할것같습니다~

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants