update order response
This commit is contained in:
parent
d0378b5ac4
commit
957c1ae53d
@ -98,6 +98,8 @@ type OrderItemResponse struct {
|
|||||||
ProductName string `json:"product_name"`
|
ProductName string `json:"product_name"`
|
||||||
ProductVariantID *uuid.UUID `json:"product_variant_id"`
|
ProductVariantID *uuid.UUID `json:"product_variant_id"`
|
||||||
ProductVariantName *string `json:"product_variant_name,omitempty"`
|
ProductVariantName *string `json:"product_variant_name,omitempty"`
|
||||||
|
CategoryID *uuid.UUID `json:"category_id,omitempty"`
|
||||||
|
CategoryName *string `json:"category_name,omitempty"`
|
||||||
Quantity int `json:"quantity"`
|
Quantity int `json:"quantity"`
|
||||||
UnitPrice float64 `json:"unit_price"`
|
UnitPrice float64 `json:"unit_price"`
|
||||||
TotalPrice float64 `json:"total_price"`
|
TotalPrice float64 `json:"total_price"`
|
||||||
|
|||||||
@ -134,6 +134,14 @@ func OrderItemEntityToResponse(item *entities.OrderItem) *models.OrderItemRespon
|
|||||||
|
|
||||||
if item.Product.ID != uuid.Nil {
|
if item.Product.ID != uuid.Nil {
|
||||||
response.ProductName = item.Product.Name
|
response.ProductName = item.Product.Name
|
||||||
|
if item.Product.CategoryID != uuid.Nil {
|
||||||
|
categoryID := item.Product.CategoryID
|
||||||
|
response.CategoryID = &categoryID
|
||||||
|
}
|
||||||
|
if item.Product.Category.ID != uuid.Nil {
|
||||||
|
categoryName := item.Product.Category.Name
|
||||||
|
response.CategoryName = &categoryName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.ProductVariant != nil {
|
if item.ProductVariant != nil {
|
||||||
|
|||||||
@ -188,6 +188,8 @@ type OrderItemResponse struct {
|
|||||||
ProductName string
|
ProductName string
|
||||||
ProductVariantID *uuid.UUID
|
ProductVariantID *uuid.UUID
|
||||||
ProductVariantName *string
|
ProductVariantName *string
|
||||||
|
CategoryID *uuid.UUID
|
||||||
|
CategoryName *string
|
||||||
Quantity int
|
Quantity int
|
||||||
UnitPrice float64
|
UnitPrice float64
|
||||||
TotalPrice float64
|
TotalPrice float64
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package processor
|
package processor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"apskel-pos-be/internal/constants"
|
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -388,31 +387,10 @@ 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 := models.OrderItemResponse{
|
itemResponse := mappers.OrderItemEntityToResponse(orderItem)
|
||||||
ID: orderItem.ID,
|
if itemResponse != nil {
|
||||||
OrderID: orderItem.OrderID,
|
addedItemResponses = append(addedItemResponses, *itemResponse)
|
||||||
ProductID: orderItem.ProductID,
|
|
||||||
ProductVariantID: orderItem.ProductVariantID,
|
|
||||||
Quantity: orderItem.Quantity,
|
|
||||||
UnitPrice: orderItem.UnitPrice,
|
|
||||||
TotalPrice: orderItem.TotalPrice,
|
|
||||||
UnitCost: orderItem.UnitCost,
|
|
||||||
TotalCost: orderItem.TotalCost,
|
|
||||||
RefundAmount: orderItem.RefundAmount,
|
|
||||||
RefundQuantity: orderItem.RefundQuantity,
|
|
||||||
IsPartiallyRefunded: orderItem.IsPartiallyRefunded,
|
|
||||||
IsFullyRefunded: orderItem.IsFullyRefunded,
|
|
||||||
RefundReason: orderItem.RefundReason,
|
|
||||||
RefundedAt: orderItem.RefundedAt,
|
|
||||||
RefundedBy: orderItem.RefundedBy,
|
|
||||||
Modifiers: []map[string]interface{}(orderItem.Modifiers),
|
|
||||||
Notes: orderItem.Notes,
|
|
||||||
Metadata: map[string]interface{}(orderItem.Metadata),
|
|
||||||
Status: constants.OrderItemStatus(orderItem.Status),
|
|
||||||
CreatedAt: orderItem.CreatedAt,
|
|
||||||
UpdatedAt: orderItem.UpdatedAt,
|
|
||||||
}
|
}
|
||||||
addedItemResponses = append(addedItemResponses, itemResponse)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
orderWithRelations, err := p.orderRepo.GetWithRelations(ctx, orderID)
|
orderWithRelations, err := p.orderRepo.GetWithRelations(ctx, orderID)
|
||||||
|
|||||||
@ -60,6 +60,7 @@ func (r *OrderRepositoryImpl) GetWithRelations(ctx context.Context, id uuid.UUID
|
|||||||
Preload("User").
|
Preload("User").
|
||||||
Preload("OrderItems").
|
Preload("OrderItems").
|
||||||
Preload("OrderItems.Product").
|
Preload("OrderItems.Product").
|
||||||
|
Preload("OrderItems.Product.Category").
|
||||||
Preload("OrderItems.ProductVariant").
|
Preload("OrderItems.ProductVariant").
|
||||||
Preload("Payments").
|
Preload("Payments").
|
||||||
Preload("Payments.PaymentMethod").
|
Preload("Payments.PaymentMethod").
|
||||||
@ -139,6 +140,7 @@ func (r *OrderRepositoryImpl) List(ctx context.Context, filters map[string]inter
|
|||||||
Preload("User").
|
Preload("User").
|
||||||
Preload("OrderItems").
|
Preload("OrderItems").
|
||||||
Preload("OrderItems.Product").
|
Preload("OrderItems.Product").
|
||||||
|
Preload("OrderItems.Product.Category").
|
||||||
Preload("OrderItems.ProductVariant").
|
Preload("OrderItems.ProductVariant").
|
||||||
Preload("Payments").
|
Preload("Payments").
|
||||||
Preload("Payments.PaymentMethod").
|
Preload("Payments.PaymentMethod").
|
||||||
@ -155,6 +157,7 @@ func (r *OrderRepositoryImpl) ListBySessionID(ctx context.Context, sessionID str
|
|||||||
Preload("User").
|
Preload("User").
|
||||||
Preload("OrderItems").
|
Preload("OrderItems").
|
||||||
Preload("OrderItems.Product").
|
Preload("OrderItems.Product").
|
||||||
|
Preload("OrderItems.Product.Category").
|
||||||
Preload("OrderItems.ProductVariant").
|
Preload("OrderItems.ProductVariant").
|
||||||
Preload("Payments").
|
Preload("Payments").
|
||||||
Preload("Payments.PaymentMethod").
|
Preload("Payments.PaymentMethod").
|
||||||
|
|||||||
@ -100,6 +100,8 @@ func OrderModelToContract(resp *models.OrderResponse) *contract.OrderResponse {
|
|||||||
ProductName: item.ProductName,
|
ProductName: item.ProductName,
|
||||||
ProductVariantID: item.ProductVariantID,
|
ProductVariantID: item.ProductVariantID,
|
||||||
ProductVariantName: item.ProductVariantName,
|
ProductVariantName: item.ProductVariantName,
|
||||||
|
CategoryID: item.CategoryID,
|
||||||
|
CategoryName: item.CategoryName,
|
||||||
Quantity: item.Quantity,
|
Quantity: item.Quantity,
|
||||||
UnitPrice: item.UnitPrice,
|
UnitPrice: item.UnitPrice,
|
||||||
TotalPrice: item.TotalPrice,
|
TotalPrice: item.TotalPrice,
|
||||||
@ -168,6 +170,8 @@ func AddToOrderModelToContract(resp *models.AddToOrderResponse) *contract.AddToO
|
|||||||
ProductName: item.ProductName,
|
ProductName: item.ProductName,
|
||||||
ProductVariantID: item.ProductVariantID,
|
ProductVariantID: item.ProductVariantID,
|
||||||
ProductVariantName: item.ProductVariantName,
|
ProductVariantName: item.ProductVariantName,
|
||||||
|
CategoryID: item.CategoryID,
|
||||||
|
CategoryName: item.CategoryName,
|
||||||
Quantity: item.Quantity,
|
Quantity: item.Quantity,
|
||||||
UnitPrice: item.UnitPrice,
|
UnitPrice: item.UnitPrice,
|
||||||
TotalPrice: item.TotalPrice,
|
TotalPrice: item.TotalPrice,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user