| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- namespace Domain.Entities.Store;
- /// <summary>
- /// 주문 라인. Order N:1 + Product N:1.
- /// Digital 상품인 경우 IssuedCouponCodeID 로 발급된 쿠폰 코드 추적.
- /// </summary>
- public class OrderItem
- {
- [ForeignKey(nameof(OrderID))]
- public virtual Order? Order { get; private set; }
- [ForeignKey(nameof(ProductID))]
- public virtual Product? Product { get; private set; }
- [ForeignKey(nameof(IssuedCouponCodeID))]
- public virtual CouponCode? IssuedCouponCode { get; private set; }
- [Key]
- public int ID { get; private set; }
- public int OrderID { get; private set; }
- public int ProductID { get; private set; }
- public int Quantity { get; private set; }
- /// <summary>주문 시점 상품 단가 (KRW). Product.Price 변경되어도 보존.</summary>
- public int UnitPrice { get; private set; }
- /// <summary>Digital 상품 발급 쿠폰 코드 (Physical 상품은 null).</summary>
- public int? IssuedCouponCodeID { get; private set; }
- public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
- private OrderItem() { }
- public static OrderItem Create(int productID, int quantity, int unitPrice)
- {
- if (productID <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(productID));
- }
- if (quantity <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(quantity), "Quantity must be positive.");
- }
- if (unitPrice < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(unitPrice), "UnitPrice must be non-negative.");
- }
- return new OrderItem
- {
- ProductID = productID,
- Quantity = quantity,
- UnitPrice = unitPrice
- };
- }
- public void AssignCouponCode(int couponCodeID)
- {
- if (couponCodeID <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(couponCodeID));
- }
- IssuedCouponCodeID = couponCodeID;
- }
- }
|