2025-11-15 17:43:23 +00:00
|
|
|
package request
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"jaecoo-be/app/database/entity"
|
|
|
|
|
"jaecoo-be/utils/paginator"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ProductsQueryRequest struct {
|
|
|
|
|
Title *string `json:"title"`
|
|
|
|
|
Variant *string `json:"variant"`
|
2026-01-19 15:35:19 +00:00
|
|
|
Status *string `json:"status"`
|
2025-11-15 17:43:23 +00:00
|
|
|
Pagination *paginator.Pagination `json:"pagination"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ProductsQueryRequestContext struct {
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Variant string `json:"variant"`
|
2026-01-19 15:35:19 +00:00
|
|
|
Status string `json:"status"`
|
2025-11-15 17:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-26 06:57:05 +00:00
|
|
|
type CommentRequest struct {
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-15 17:43:23 +00:00
|
|
|
func (req ProductsQueryRequestContext) ToParamRequest() ProductsQueryRequest {
|
|
|
|
|
var request ProductsQueryRequest
|
|
|
|
|
|
|
|
|
|
if title := req.Title; title != "" {
|
|
|
|
|
request.Title = &title
|
|
|
|
|
}
|
|
|
|
|
if variant := req.Variant; variant != "" {
|
|
|
|
|
request.Variant = &variant
|
|
|
|
|
}
|
2026-01-19 15:35:19 +00:00
|
|
|
if status := req.Status; status != "" {
|
|
|
|
|
request.Status = &status
|
|
|
|
|
}
|
2025-11-15 17:43:23 +00:00
|
|
|
|
|
|
|
|
return request
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-26 06:57:05 +00:00
|
|
|
// type ProductsCreateRequest struct {
|
|
|
|
|
// Title string `json:"title" validate:"required"`
|
|
|
|
|
// Variant *string `json:"variant"`
|
|
|
|
|
// Price *string `json:"price"`
|
|
|
|
|
// ThumbnailPath *string `json:"thumbnail_path"`
|
|
|
|
|
// Colors []string `json:"colors"`
|
|
|
|
|
// Status *string `json:"status"`
|
|
|
|
|
// }
|
|
|
|
|
|
2025-11-15 17:43:23 +00:00
|
|
|
type ProductsCreateRequest struct {
|
2026-01-26 06:57:05 +00:00
|
|
|
Title string `json:"title" validate:"required"`
|
|
|
|
|
Variant *string `json:"variant"`
|
|
|
|
|
Price *string `json:"price"`
|
|
|
|
|
ThumbnailPath *string `json:"thumbnail_path"`
|
|
|
|
|
Colors []ProductColorRequest `json:"colors"`
|
|
|
|
|
Status *string `json:"status"`
|
2025-11-15 17:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-26 06:57:05 +00:00
|
|
|
|
|
|
|
|
// func (req ProductsCreateRequest) ToEntity() *entity.Products {
|
|
|
|
|
// colorsJSON, _ := json.Marshal(req.Colors)
|
|
|
|
|
// colorsStr := string(colorsJSON)
|
|
|
|
|
// if colorsStr == "null" {
|
|
|
|
|
// colorsStr = ""
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return &entity.Products{
|
|
|
|
|
// Title: req.Title,
|
|
|
|
|
// Variant: req.Variant,
|
|
|
|
|
// Price: req.Price,
|
|
|
|
|
// ThumbnailPath: req.ThumbnailPath,
|
|
|
|
|
// Colors: &colorsStr,
|
|
|
|
|
// Status: req.Status,
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2025-11-15 17:43:23 +00:00
|
|
|
func (req ProductsCreateRequest) ToEntity() *entity.Products {
|
|
|
|
|
colorsJSON, _ := json.Marshal(req.Colors)
|
|
|
|
|
colorsStr := string(colorsJSON)
|
2026-01-26 06:57:05 +00:00
|
|
|
|
2025-11-15 17:43:23 +00:00
|
|
|
if colorsStr == "null" {
|
|
|
|
|
colorsStr = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &entity.Products{
|
|
|
|
|
Title: req.Title,
|
|
|
|
|
Variant: req.Variant,
|
|
|
|
|
Price: req.Price,
|
|
|
|
|
ThumbnailPath: req.ThumbnailPath,
|
|
|
|
|
Colors: &colorsStr,
|
2026-01-19 15:35:19 +00:00
|
|
|
Status: req.Status,
|
2025-11-15 17:43:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-26 06:57:05 +00:00
|
|
|
|
2025-11-15 17:43:23 +00:00
|
|
|
type ProductsUpdateRequest struct {
|
2026-01-28 01:39:11 +00:00
|
|
|
Title *string `json:"title"`
|
|
|
|
|
Variant *string `json:"variant"`
|
|
|
|
|
Price *string `json:"price"`
|
|
|
|
|
ThumbnailPath *string `json:"thumbnail_path"`
|
|
|
|
|
Colors []ProductColorRequest `json:"colors"`
|
|
|
|
|
Status *string `json:"status"`
|
|
|
|
|
IsActive *bool `json:"is_active"`
|
2025-11-15 17:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req ProductsUpdateRequest) ToEntity() *entity.Products {
|
|
|
|
|
colorsJSON, _ := json.Marshal(req.Colors)
|
|
|
|
|
colorsStr := string(colorsJSON)
|
|
|
|
|
if colorsStr == "null" {
|
|
|
|
|
colorsStr = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &entity.Products{
|
|
|
|
|
Title: getStringValue(req.Title),
|
|
|
|
|
Variant: req.Variant,
|
|
|
|
|
Price: req.Price,
|
|
|
|
|
ThumbnailPath: req.ThumbnailPath,
|
|
|
|
|
Colors: &colorsStr,
|
2026-01-19 15:35:19 +00:00
|
|
|
Status: req.Status,
|
2025-11-15 17:43:23 +00:00
|
|
|
IsActive: req.IsActive,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getStringValue(s *string) string {
|
|
|
|
|
if s == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return *s
|
|
|
|
|
}
|
2026-01-26 06:57:05 +00:00
|
|
|
|
|
|
|
|
type ProductColorRequest struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
ImagePath *string `json:"image_path"`
|
|
|
|
|
}
|
|
|
|
|
|