update
This commit is contained in:
parent
23ac572e3f
commit
84222fc7f4
@ -110,6 +110,7 @@ type OrderItemResponse struct {
|
|||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
PrinterType string `json:"printer_type"`
|
PrinterType string `json:"printer_type"`
|
||||||
|
PrintToChecker bool `json:"print_to_checker"`
|
||||||
PaidQuantity int `json:"paid_quantity"`
|
PaidQuantity int `json:"paid_quantity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,13 +26,14 @@ type Product struct {
|
|||||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||||
|
|
||||||
Organization Organization `gorm:"foreignKey:OrganizationID" json:"organization,omitempty"`
|
Organization Organization `gorm:"foreignKey:OrganizationID" json:"organization,omitempty"`
|
||||||
Category Category `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
|
Category Category `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
|
||||||
Unit *Unit `gorm:"foreignKey:UnitID" json:"unit,omitempty"`
|
Unit *Unit `gorm:"foreignKey:UnitID" json:"unit,omitempty"`
|
||||||
ProductVariants []ProductVariant `gorm:"foreignKey:ProductID" json:"variants,omitempty"`
|
ProductVariants []ProductVariant `gorm:"foreignKey:ProductID" json:"variants,omitempty"`
|
||||||
ProductRecipes []ProductRecipe `gorm:"foreignKey:ProductID" json:"product_recipes,omitempty"`
|
ProductRecipes []ProductRecipe `gorm:"foreignKey:ProductID" json:"product_recipes,omitempty"`
|
||||||
Inventory []Inventory `gorm:"foreignKey:ProductID" json:"inventory,omitempty"`
|
Inventory []Inventory `gorm:"foreignKey:ProductID" json:"inventory,omitempty"`
|
||||||
OrderItems []OrderItem `gorm:"foreignKey:ProductID" json:"order_items,omitempty"`
|
OrderItems []OrderItem `gorm:"foreignKey:ProductID" json:"order_items,omitempty"`
|
||||||
|
ProductOutletPrices []ProductOutletPrice `gorm:"foreignKey:ProductID" json:"product_outlet_prices,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Product) BeforeCreate(tx *gorm.DB) error {
|
func (p *Product) BeforeCreate(tx *gorm.DB) error {
|
||||||
|
|||||||
@ -82,7 +82,7 @@ func OrderEntityToResponse(order *entities.Order) *models.OrderResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, item := range order.OrderItems {
|
for i, item := range order.OrderItems {
|
||||||
resp := OrderItemEntityToResponse(&item)
|
resp := OrderItemEntityToResponse(&item, order.OutletID)
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
resp.PaidQuantity = paidQtyByOrderItem[item.ID]
|
resp.PaidQuantity = paidQtyByOrderItem[item.ID]
|
||||||
response.OrderItems[i] = *resp
|
response.OrderItems[i] = *resp
|
||||||
@ -101,11 +101,20 @@ func OrderEntityToResponse(order *entities.Order) *models.OrderResponse {
|
|||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
func OrderItemEntityToResponse(item *entities.OrderItem) *models.OrderItemResponse {
|
func OrderItemEntityToResponse(item *entities.OrderItem, outletID uuid.UUID) *models.OrderItemResponse {
|
||||||
if item == nil {
|
if item == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve print_to_checker from preloaded outlet prices
|
||||||
|
printToChecker := true // default
|
||||||
|
for _, op := range item.Product.ProductOutletPrices {
|
||||||
|
if op.OutletID == outletID {
|
||||||
|
printToChecker = op.PrintToChecker
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response := &models.OrderItemResponse{
|
response := &models.OrderItemResponse{
|
||||||
ID: item.ID,
|
ID: item.ID,
|
||||||
OrderID: item.OrderID,
|
OrderID: item.OrderID,
|
||||||
@ -130,6 +139,7 @@ func OrderItemEntityToResponse(item *entities.OrderItem) *models.OrderItemRespon
|
|||||||
CreatedAt: item.CreatedAt,
|
CreatedAt: item.CreatedAt,
|
||||||
UpdatedAt: item.UpdatedAt,
|
UpdatedAt: item.UpdatedAt,
|
||||||
PrinterType: item.Product.PrinterType,
|
PrinterType: item.Product.PrinterType,
|
||||||
|
PrintToChecker: printToChecker,
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.Product.ID != uuid.Nil {
|
if item.Product.ID != uuid.Nil {
|
||||||
@ -324,14 +334,14 @@ func OrderEntitiesToResponses(orders []*entities.Order) []models.OrderResponse {
|
|||||||
return responses
|
return responses
|
||||||
}
|
}
|
||||||
|
|
||||||
func OrderItemEntitiesToResponses(items []*entities.OrderItem) []models.OrderItemResponse {
|
func OrderItemEntitiesToResponses(items []*entities.OrderItem, outletID uuid.UUID) []models.OrderItemResponse {
|
||||||
if items == nil {
|
if items == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
responses := make([]models.OrderItemResponse, len(items))
|
responses := make([]models.OrderItemResponse, len(items))
|
||||||
for i, item := range items {
|
for i, item := range items {
|
||||||
response := OrderItemEntityToResponse(item)
|
response := OrderItemEntityToResponse(item, outletID)
|
||||||
if response != nil {
|
if response != nil {
|
||||||
responses[i] = *response
|
responses[i] = *response
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ func TestOrderItemEntityToResponse_WithProductNames(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
result := OrderItemEntityToResponse(orderItem)
|
result := OrderItemEntityToResponse(orderItem, uuid.Nil)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
@ -89,7 +89,7 @@ func TestOrderItemEntityToResponse_WithoutProductVariant(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
result := OrderItemEntityToResponse(orderItem)
|
result := OrderItemEntityToResponse(orderItem, uuid.Nil)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
@ -129,7 +129,7 @@ func TestOrderItemEntityToResponse_WithoutProductPreload(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
result := OrderItemEntityToResponse(orderItem)
|
result := OrderItemEntityToResponse(orderItem, uuid.Nil)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
|
|||||||
@ -209,6 +209,7 @@ type OrderItemResponse struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
PrinterType string
|
PrinterType string
|
||||||
|
PrintToChecker bool
|
||||||
PaidQuantity int
|
PaidQuantity int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -387,7 +387,7 @@ func (p *OrderProcessorImpl) AddToOrder(ctx context.Context, orderID uuid.UUID,
|
|||||||
return nil, fmt.Errorf("failed to create order item: %w", err)
|
return nil, fmt.Errorf("failed to create order item: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
itemResponse := mappers.OrderItemEntityToResponse(orderItem)
|
itemResponse := mappers.OrderItemEntityToResponse(orderItem, order.OutletID)
|
||||||
if itemResponse != nil {
|
if itemResponse != nil {
|
||||||
addedItemResponses = append(addedItemResponses, *itemResponse)
|
addedItemResponses = append(addedItemResponses, *itemResponse)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,6 +61,7 @@ func (r *OrderRepositoryImpl) GetWithRelations(ctx context.Context, id uuid.UUID
|
|||||||
Preload("OrderItems").
|
Preload("OrderItems").
|
||||||
Preload("OrderItems.Product").
|
Preload("OrderItems.Product").
|
||||||
Preload("OrderItems.Product.Category").
|
Preload("OrderItems.Product.Category").
|
||||||
|
Preload("OrderItems.Product.ProductOutletPrices").
|
||||||
Preload("OrderItems.ProductVariant").
|
Preload("OrderItems.ProductVariant").
|
||||||
Preload("Payments").
|
Preload("Payments").
|
||||||
Preload("Payments.PaymentMethod").
|
Preload("Payments.PaymentMethod").
|
||||||
@ -141,6 +142,7 @@ func (r *OrderRepositoryImpl) List(ctx context.Context, filters map[string]inter
|
|||||||
Preload("OrderItems").
|
Preload("OrderItems").
|
||||||
Preload("OrderItems.Product").
|
Preload("OrderItems.Product").
|
||||||
Preload("OrderItems.Product.Category").
|
Preload("OrderItems.Product.Category").
|
||||||
|
Preload("OrderItems.Product.ProductOutletPrices").
|
||||||
Preload("OrderItems.ProductVariant").
|
Preload("OrderItems.ProductVariant").
|
||||||
Preload("Payments").
|
Preload("Payments").
|
||||||
Preload("Payments.PaymentMethod").
|
Preload("Payments.PaymentMethod").
|
||||||
@ -158,6 +160,7 @@ func (r *OrderRepositoryImpl) ListBySessionID(ctx context.Context, sessionID str
|
|||||||
Preload("OrderItems").
|
Preload("OrderItems").
|
||||||
Preload("OrderItems.Product").
|
Preload("OrderItems.Product").
|
||||||
Preload("OrderItems.Product.Category").
|
Preload("OrderItems.Product.Category").
|
||||||
|
Preload("OrderItems.Product.ProductOutletPrices").
|
||||||
Preload("OrderItems.ProductVariant").
|
Preload("OrderItems.ProductVariant").
|
||||||
Preload("Payments").
|
Preload("Payments").
|
||||||
Preload("Payments.PaymentMethod").
|
Preload("Payments.PaymentMethod").
|
||||||
|
|||||||
@ -112,6 +112,7 @@ func OrderModelToContract(resp *models.OrderResponse) *contract.OrderResponse {
|
|||||||
CreatedAt: item.CreatedAt,
|
CreatedAt: item.CreatedAt,
|
||||||
UpdatedAt: item.UpdatedAt,
|
UpdatedAt: item.UpdatedAt,
|
||||||
PrinterType: item.PrinterType,
|
PrinterType: item.PrinterType,
|
||||||
|
PrintToChecker: item.PrintToChecker,
|
||||||
PaidQuantity: item.PaidQuantity,
|
PaidQuantity: item.PaidQuantity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,6 +182,7 @@ func AddToOrderModelToContract(resp *models.AddToOrderResponse) *contract.AddToO
|
|||||||
Status: string(item.Status),
|
Status: string(item.Status),
|
||||||
CreatedAt: item.CreatedAt,
|
CreatedAt: item.CreatedAt,
|
||||||
UpdatedAt: item.UpdatedAt,
|
UpdatedAt: item.UpdatedAt,
|
||||||
|
PrintToChecker: item.PrintToChecker,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &contract.AddToOrderResponse{
|
return &contract.AddToOrderResponse{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user