60 lines
2.0 KiB
Go
Raw Normal View History

2023-10-08 15:59:42 +07:00
package request
import (
2025-03-04 20:36:17 +07:00
"enaklo-pos-be/internal/constants/product"
"enaklo-pos-be/internal/entity"
2023-10-08 15:59:42 +07:00
)
type ProductParam struct {
2025-06-14 21:17:13 +07:00
Search string `form:"search" json:"search" example:"Nasi Goreng"`
Name string `form:"name" json:"name" example:"Nasi Goreng"`
Type product.ProductType `form:"type" json:"type" example:"FOOD/BEVERAGE"`
BranchID int64 `form:"branch_id" json:"branch_id" example:"1"`
Available product.ProductStock `form:"available" json:"available" example:"1" example:"AVAILABLE/UNAVAILABLE"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
CategoryID int64 `form:"category_id" json:"category_id" example:"1"`
2023-10-08 15:59:42 +07:00
}
2025-06-14 21:17:13 +07:00
func (p *ProductParam) ToEntity(partnerID int64) entity.ProductSearch {
2023-10-08 15:59:42 +07:00
return entity.ProductSearch{
2025-06-14 21:17:13 +07:00
Search: p.Search,
Name: p.Name,
Type: p.Type,
PartnerID: partnerID,
Available: p.Available,
Limit: p.Limit,
Offset: p.Offset,
CategoryID: p.CategoryID,
2023-10-08 15:59:42 +07:00
}
}
type Product struct {
2024-06-03 14:40:50 +07:00
ID int64 `json:"id,omitempty"`
PartnerID int64 `json:"partner_id"`
2024-12-20 16:52:48 +07:00
SiteID int64 `json:"site_id"`
2024-06-03 14:40:50 +07:00
Name string `json:"name" validate:"required"`
Type string `json:"type"`
Price float64 `json:"price" validate:"required"`
IsWeekendTicket bool `json:"is_weekend_ticket"`
IsSeasonTicket bool `json:"is_season_ticket"`
Status string `json:"status"`
2025-03-08 00:35:23 +07:00
Description string `json:"description"`
2024-08-24 01:49:14 +07:00
Stock int64 `json:"stock"`
2024-12-20 16:52:48 +07:00
Image string `json:"image"`
2025-06-14 21:17:13 +07:00
CategoryID int64 `json:"category_id"`
2023-10-08 15:59:42 +07:00
}
func (e *Product) ToEntity() *entity.Product {
return &entity.Product{
Name: e.Name,
Type: e.Type,
Price: e.Price,
Status: e.Status,
Description: e.Description,
2024-12-20 16:52:48 +07:00
PartnerID: e.PartnerID,
Image: e.Image,
2025-06-14 21:17:13 +07:00
CategoryID: &e.CategoryID,
2023-10-08 15:59:42 +07:00
}
}