jaecoo-be/app/module/gallery_files/request/gallery_files.request.go

74 lines
1.7 KiB
Go

package request
import (
"jaecoo-be/app/database/entity"
"jaecoo-be/utils/paginator"
"strconv"
)
type GalleryFilesQueryRequest struct {
GalleryID *uint `json:"gallery_id"`
Title *string `json:"title"`
Pagination *paginator.Pagination `json:"pagination"`
}
type GalleryFilesQueryRequestContext struct {
GalleryID string `json:"gallery_id"`
Title string `json:"title"`
}
func (req GalleryFilesQueryRequestContext) ToParamRequest() GalleryFilesQueryRequest {
var request GalleryFilesQueryRequest
if galleryIDStr := req.GalleryID; galleryIDStr != "" {
galleryID, err := strconv.Atoi(galleryIDStr)
if err == nil {
galleryIDUint := uint(galleryID)
request.GalleryID = &galleryIDUint
}
}
if title := req.Title; title != "" {
request.Title = &title
}
return request
}
type GalleryFilesCreateRequest struct {
GalleryID uint `json:"gallery_id" validate:"required"`
Title *string `json:"title"`
ImagePath *string `json:"image_path"`
}
func (req GalleryFilesCreateRequest) ToEntity() *entity.GalleryFiles {
return &entity.GalleryFiles{
GalleryID: req.GalleryID,
Title: req.Title,
ImagePath: req.ImagePath,
}
}
type GalleryFilesUpdateRequest struct {
GalleryID *uint `json:"gallery_id"`
Title *string `json:"title"`
ImagePath *string `json:"image_path"`
IsActive *bool `json:"is_active"`
}
func (req GalleryFilesUpdateRequest) ToEntity() *entity.GalleryFiles {
return &entity.GalleryFiles{
GalleryID: getUintValue(req.GalleryID),
Title: req.Title,
ImagePath: req.ImagePath,
IsActive: req.IsActive,
}
}
func getUintValue(u *uint) uint {
if u == nil {
return 0
}
return *u
}