- 
                Notifications
    You must be signed in to change notification settings 
- Fork 151
[4기 황준호]JPA : Mission 3 제출입니다. #303
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
          
     Open
      
      
            juno-junho
  wants to merge
  1
  commit into
  prgrms-be-devcourse:juno-junho
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
juno-junho:main
  
      
      
   
  
    
  
  
  
 
  
      
    base: juno-junho
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            17 changes: 17 additions & 0 deletions
          
          17 
        
  kdt-jpa/src/main/java/com/kdt/kdtjpa/domain/order/BaseEntity.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.kdt.kdtjpa.domain.order; | ||
|  | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.MappedSuperclass; | ||
| import lombok.Getter; | ||
|  | ||
| import java.time.LocalDateTime; | ||
|  | ||
| @Getter | ||
| @MappedSuperclass | ||
| public abstract class BaseEntity { | ||
| @Column(name = "created_by") | ||
| private String createdBy; | ||
|  | ||
| @Column(name = "created_at", columnDefinition = "TIMESTAMP") | ||
| private LocalDateTime createdAt; | ||
| } | ||
        
          
          
            34 changes: 34 additions & 0 deletions
          
          34 
        
  kdt-jpa/src/main/java/com/kdt/kdtjpa/domain/order/Item.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.kdt.kdtjpa.domain.order; | ||
|  | ||
| import jakarta.persistence.*; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|  | ||
| import java.util.Objects; | ||
|  | ||
| @Entity | ||
| @Table(name = "item") | ||
| @Getter | ||
| @Setter | ||
| @DiscriminatorColumn(name = "DTYPE") | ||
| @Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||
| public abstract class Item extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
| private Long id; | ||
|  | ||
| private int price; | ||
| private int stockQuantity; | ||
| 
      Comment on lines
    
      +20
     to 
      +21
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엔터가 빠져 있습니다! | ||
|  | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "order_item_id", referencedColumnName = "id") | ||
| private OrderItem orderItem; | ||
|  | ||
| public void setOrderItem(OrderItem orderItem) { | ||
| if (Objects.nonNull(this.orderItem)) { | ||
| this.orderItem.getItems().remove(this); | ||
| } | ||
| this.orderItem = orderItem; | ||
| orderItem.getItems().add(this); | ||
| } | ||
| } | ||
        
          
          
            38 changes: 38 additions & 0 deletions
          
          38 
        
  kdt-jpa/src/main/java/com/kdt/kdtjpa/domain/order/Member.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.kdt.kdtjpa.domain.order; | ||
|  | ||
| import jakarta.persistence.*; | ||
| import lombok.Getter; | ||
|  | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|  | ||
| @Entity | ||
| @Table(name = "member") | ||
| @Getter | ||
| public class Member extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
| private Long id; | ||
|  | ||
| @Column(name = "name", nullable = false, length = 30) | ||
| private String name; | ||
|  | ||
| @Column(name = "nick_name", nullable = false, length = 30, unique = true) | ||
| private String nickName; | ||
|  | ||
| @Column(name = "age", nullable = false) | ||
| private int age; | ||
|  | ||
| @Column(name = "address", nullable = false) | ||
| private String address; | ||
|  | ||
| @Column(name = "description") | ||
| private String description; | ||
|  | ||
| @OneToMany(mappedBy = "member") // 연관관계 주인 설정 | ||
| private List<Order> orders = new ArrayList<>(); | ||
|  | ||
| public void addOrder(Order order) { // 연관관계 편의 메서드 | ||
| order.setMember(this); | ||
| } | ||
| } | 
        
          
          
            45 changes: 45 additions & 0 deletions
          
          45 
        
  kdt-jpa/src/main/java/com/kdt/kdtjpa/domain/order/Order.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.kdt.kdtjpa.domain.order; | ||
|  | ||
| import jakarta.persistence.*; | ||
| import lombok.Getter; | ||
|  | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|  | ||
| @Entity | ||
| @Table(name = "orders") | ||
| @Getter | ||
| public class Order extends BaseEntity { | ||
| @Id | ||
| @Column(name = "id") | ||
| private String uuid; | ||
|  | ||
| @Lob | ||
| private String memo; | ||
|  | ||
| @Enumerated(value = EnumType.STRING) | ||
| private OrderStatus orderStatus; | ||
|  | ||
| @Column(name = "order_datetime", columnDefinition = "TIMESTAMP") | ||
| private LocalDateTime orderDateTime; | ||
|  | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "memeber_id", referencedColumnName = "id") | ||
| private Member member; | ||
|  | ||
| @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| List<OrderItem> orderItems; | ||
|  | ||
| public void setMember(Member member) { | ||
| if (Objects.nonNull(this.member)) { | ||
| member.getOrders().remove(this); | ||
| } | ||
| this.member = member; | ||
| member.getOrders().add(this); | ||
| } | ||
|  | ||
| public void addOrderItem(OrderItem orderItem) { | ||
| orderItem.setOrder(this); | ||
| } | ||
| } | 
        
          
          
            39 changes: 39 additions & 0 deletions
          
          39 
        
  kdt-jpa/src/main/java/com/kdt/kdtjpa/domain/order/OrderItem.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.kdt.kdtjpa.domain.order; | ||
|  | ||
| import jakarta.persistence.*; | ||
| import lombok.Getter; | ||
|  | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|  | ||
| @Entity | ||
| @Table(name = "order_item") | ||
| @Getter | ||
| public class OrderItem extends BaseEntity { | ||
|  | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
| private Long id; | ||
|  | ||
| private int price; | ||
| private int quantity; | ||
|  | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "order_id", referencedColumnName = "id") | ||
| private Order order; | ||
|  | ||
| @OneToMany(mappedBy = "orderItem", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<Item> items; | ||
|  | ||
| public void setOrder(Order order) { | ||
| if (Objects.nonNull(this.order)) { | ||
| this.order.getOrderItems().remove(this); | ||
| } | ||
| this.order = order; | ||
| order.getOrderItems().add(this); | ||
| } | ||
|  | ||
| public void addItem(Item item) { | ||
| item.setOrderItem(this); | ||
| } | ||
| } | 
        
          
          
            5 changes: 5 additions & 0 deletions
          
          5 
        
  kdt-jpa/src/main/java/com/kdt/kdtjpa/domain/order/OrderStatus.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.kdt.kdtjpa.domain.order; | ||
|  | ||
| public enum OrderStatus { | ||
| OPENED, CANCELLED | ||
| } | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.
@ Getter 따로 안쓰이고 있는 것 같은데 삭제하면 좋을 것 같습니다!