order struct

This commit is contained in:
Daniel Goc
2026-04-10 11:06:43 +02:00
parent dfdf8b4db9
commit 4f4b32b131
2 changed files with 31 additions and 2 deletions

View File

@@ -39,7 +39,7 @@ func (h *OrdersHandler) ListOrders(c fiber.Ctx) error {
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody))) JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
} }
paging, filters, err := query_params.ParseFilters[model.Order](c, columnMappingListOrders) paging, filters, err := query_params.ParseFilters[model.CustomerOrder](c, columnMappingListOrders)
if err != nil { if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)). return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err))) JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
@@ -55,7 +55,10 @@ func (h *OrdersHandler) ListOrders(c fiber.Ctx) error {
} }
var columnMappingListOrders map[string]string = map[string]string{ var columnMappingListOrders map[string]string = map[string]string{
"order_id": "?", "order_id": "co.id",
"user_id": "co.user_id",
"country_id": "co.country_id",
"status": "co.status",
} }
func (h *OrdersHandler) PlaceNewOrder(c fiber.Ctx) error { func (h *OrdersHandler) PlaceNewOrder(c fiber.Ctx) error {

View File

@@ -0,0 +1,26 @@
package model
type CustomerOrder struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
UserID uint `gorm:"column:user_id;not null;index" json:"-"`
CountryID uint `gorm:"column:country_id;not null" json:"country_id"`
AddressJSON *string `gorm:"column:address_json" json:"address_json,omitempty"`
Status *string `gorm:"column:status;size:50" json:"status,omitempty"`
Products []OrderProduct `gorm:"foreignKey:OrderID;references:ID" json:"products,omitempty"`
}
func (CustomerOrder) TableName() string {
return "b2b_customer_orders"
}
type OrderProduct struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"-"`
OrderID uint `gorm:"column:order_id;not null;index" json:"-"`
ProductID uint `gorm:"column:product_id;not null" json:"product_id"`
ProductAttributeID *uint `gorm:"column:product_attribute_id" json:"product_attribute_id,omitempty"`
Amount uint `gorm:"column:amount;not null" json:"amount"`
}
func (OrderProduct) TableName() string {
return "b2b_orders_products"
}