aditya.siregar 67f1dbc850 init project
2024-05-28 14:14:55 +07:00

117 lines
3.8 KiB
Go

package request
import (
"furtuna-be/internal/constants/order"
"furtuna-be/internal/constants/transaction"
"furtuna-be/internal/entity"
"time"
)
type Order struct {
BranchID int64 `json:"branch_id" validate:"required"`
Amount float64 `json:"amount" validate:"required"`
CustomerName string `json:"customer_name" validate:"required"`
CustomerPhone string `json:"customer_phone" validate:"required"`
Pax int `json:"pax" validate:"required"`
PaymentMethod transaction.PaymentMethod `json:"payment_method" validate:"required"`
OrderItem []OrderItem `json:"order_items" validate:"required"`
}
type OrderItem struct {
ItemID int64 `json:"item_id" validate:"required"`
ItemType order.ItemType `json:"item_type" validate:"required"`
Price float64 `json:"price" validate:"required"`
Qty int64 `json:"qty" validate:"required"`
}
type OrderParam struct {
Search string `form:"search" json:"search" example:"name,branch_name,item_name"`
StatusActive order.OrderSearchStatus `form:"status_active" json:"status_active" example:"active,inactive"`
Status order.OrderStatus `form:"status" json:"status" example:"NEW,PAID,CANCEL"`
BranchID int64 `form:"branch_id" json:"branch_id" example:"1"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (p *OrderParam) ToEntity() entity.OrderSearch {
return entity.OrderSearch{
Search: p.Search,
StatusActive: p.StatusActive,
Status: p.Status,
BranchID: p.BranchID,
Limit: p.Limit,
Offset: p.Offset,
}
}
func (o *Order) ToEntity() *entity.Order {
var ordItems []entity.OrderItem
if len(o.OrderItem) > 0 {
for _, i := range o.OrderItem {
ordItems = append(ordItems, entity.OrderItem{
ItemID: i.ItemID,
ItemType: i.ItemType,
Price: i.Price,
Qty: i.Qty,
})
}
}
transaction := entity.Transaction{
BranchID: o.BranchID,
CustomerName: o.CustomerName,
CustomerPhone: o.CustomerPhone,
PaymentMethod: o.PaymentMethod,
}
return &entity.Order{
BranchID: o.BranchID,
Amount: o.Amount,
CustomerName: o.CustomerName,
CustomerPhone: o.CustomerPhone,
Pax: o.Pax,
Transaction: transaction,
OrderItem: ordItems,
}
}
type OrderTotalRevenueParam struct {
Year int `form:"year" json:"year" example:"1,2,3"`
Month int `form:"month" json:"month" example:"1,2,3"`
BranchID int64 `form:"branch_id" json:"branch_id" example:"1"`
DateStart *time.Time `form:"date_start" json:"date_start" example:"2024-01-01" time_format:"2006-1-2"`
DateEnd *time.Time `form:"date_end" json:"date_end" example:"2024-01-01" time_format:"2006-1-2"`
}
func (p *OrderTotalRevenueParam) ToEntity() entity.OrderTotalRevenueSearch {
return entity.OrderTotalRevenueSearch{
Year: p.Year,
Month: p.Month,
BranchID: p.BranchID,
DateStart: p.DateStart,
DateEnd: p.DateEnd,
}
}
type OrderBranchRevenueParam struct {
DateStart *time.Time `form:"date_start" json:"date_start" example:"2024-01-01" time_format:"2006-1-2"`
DateEnd *time.Time `form:"date_end" json:"date_end" example:"2024-01-01" time_format:"2006-1-2"`
}
func (p *OrderBranchRevenueParam) ToEntity() entity.OrderBranchRevenueSearch {
return entity.OrderBranchRevenueSearch{
DateStart: p.DateStart,
DateEnd: p.DateEnd,
}
}
type UpdateStatus struct {
Status order.OrderStatus `form:"status" json:"status" example:"NEW,PAID,CANCEL"`
}
func (o *UpdateStatus) ToEntity() *entity.Order {
return &entity.Order{
Status: o.Status,
}
}