-
Notifications
You must be signed in to change notification settings - Fork 0
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
update: Updated basic domains #18
Merged
koreanMike513
merged 2 commits into
fix/fix-base-time-entity
from
update/update-base-entities
Dec 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,16 +1,32 @@ | ||
package com.f_lab.la_planete.domain; | ||
|
||
import com.f_lab.la_planete.domain.base.BaseEntity; | ||
import jakarta.persistence.*; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.OneToOne; | ||
import jakarta.persistence.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static jakarta.persistence.FetchType.LAZY; | ||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Table(name = "orders") | ||
public class Order extends BaseEntity { | ||
|
@@ -19,10 +35,28 @@ public class Order extends BaseEntity { | |
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "food_id") | ||
private Food food; | ||
|
||
private BigDecimal totalCost; | ||
|
||
private int quantity; | ||
|
||
// 화폐 추가 | ||
|
||
@Enumerated(EnumType.STRING) | ||
private OrderStatus status; | ||
|
||
@OneToOne(fetch = LAZY) | ||
@JoinColumn(name = "payment_id") | ||
private Payment payment; | ||
|
||
public void updateTotalCost(BigDecimal totalCost) { | ||
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. totalCost, updateTotalCost, calculateTotalCost 중 필요한 것만 노출 고려 |
||
this.totalCost = totalCost; | ||
} | ||
|
||
public BigDecimal calculateTotalCost() { | ||
return food.calculateCost(quantity); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,30 +1,46 @@ | ||
package com.f_lab.la_planete.domain; | ||
|
||
import com.f_lab.la_planete.domain.base.BaseEntity; | ||
import jakarta.persistence.*; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static jakarta.persistence.FetchType.LAZY; | ||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PRIVATE; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Entity | ||
@Getter | ||
@Getter @Setter(PRIVATE) | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Table(name = "payments") | ||
public class Payment extends BaseEntity { | ||
|
||
@Id @GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
private BigDecimal amount; | ||
private BigDecimal totalCost; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private PaymentStatus status; | ||
|
||
@OneToOne(mappedBy = "payment", fetch = LAZY) | ||
private Order order; | ||
|
||
public static Payment of(BigDecimal totalCost, Order order) { | ||
Payment payment = new Payment(); | ||
payment.setTotalCost(totalCost); | ||
payment.setOrder(order); | ||
payment.setStatus(PaymentStatus.READY); | ||
return payment; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
price.intValue()가 의도하신게 맞는지 확인 부탁드립니다.
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.
찾아보니 BigDecimal 에 multiply() 메서드가 있는것을 확인하였습니다 수정하겠습니다.