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

69 lines
1.5 KiB
Go

package request
import (
"jaecoo-be/app/database/entity"
"jaecoo-be/utils/paginator"
)
type GalleriesQueryRequest struct {
Title *string `json:"title"`
Pagination *paginator.Pagination `json:"pagination"`
}
type GalleriesQueryRequestContext struct {
Title string `json:"title"`
}
type CommentRequest struct {
Message string `json:"message"`
}
func (req GalleriesQueryRequestContext) ToParamRequest() GalleriesQueryRequest {
var request GalleriesQueryRequest
if title := req.Title; title != "" {
request.Title = &title
}
return request
}
type GalleriesCreateRequest struct {
Title string `json:"title" validate:"required"`
Description *string `json:"description"`
ThumbnailPath *string `json:"thumbnail_path"`
}
func (req GalleriesCreateRequest) ToEntity() *entity.Galleries {
return &entity.Galleries{
Title: req.Title,
Description: req.Description,
ThumbnailPath: req.ThumbnailPath,
}
}
type GalleriesUpdateRequest struct {
Title *string `json:"title"`
Description *string `json:"description"`
ThumbnailPath *string `json:"thumbnail_path"`
IsActive *bool `json:"is_active"`
}
func (req GalleriesUpdateRequest) ToEntity() *entity.Galleries {
return &entity.Galleries{
Title: getStringValue(req.Title),
Description: req.Description,
ThumbnailPath: req.ThumbnailPath,
IsActive: req.IsActive,
}
}
func getStringValue(s *string) string {
if s == nil {
return ""
}
return *s
}