80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package request
|
|
|
|
import (
|
|
"narasi-ahli-be/app/database/entity"
|
|
"narasi-ahli-be/utils/paginator"
|
|
"time"
|
|
)
|
|
|
|
type CustomStaticPagesGeneric interface {
|
|
ToEntity()
|
|
}
|
|
|
|
type CustomStaticPagesQueryRequest struct {
|
|
Title *string `json:"title"`
|
|
Description *string `json:"description"`
|
|
Slug *string `json:"slug"`
|
|
HtmlBody *string `json:"htmlBody"`
|
|
Pagination *paginator.Pagination `json:"pagination"`
|
|
}
|
|
|
|
type CustomStaticPagesCreateRequest struct {
|
|
Title string `json:"title" validate:"required"`
|
|
Description string `json:"description"`
|
|
Slug string `json:"slug" validate:"required"`
|
|
HtmlBody string `json:"htmlBody" validate:"required"`
|
|
}
|
|
|
|
func (req CustomStaticPagesCreateRequest) ToEntity() *entity.CustomStaticPages {
|
|
return &entity.CustomStaticPages{
|
|
Title: req.Title,
|
|
Description: req.Description,
|
|
Slug: req.Slug,
|
|
HtmlBody: req.HtmlBody,
|
|
IsActive: true,
|
|
}
|
|
}
|
|
|
|
type CustomStaticPagesUpdateRequest struct {
|
|
ID uint `json:"id" validate:"required"`
|
|
Title string `json:"title" validate:"required"`
|
|
Description string `json:"description"`
|
|
Slug string `json:"slug" validate:"required"`
|
|
HtmlBody string `json:"htmlBody" validate:"required"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (req CustomStaticPagesUpdateRequest) ToEntity() *entity.CustomStaticPages {
|
|
return &entity.CustomStaticPages{
|
|
ID: req.ID,
|
|
Title: req.Title,
|
|
Description: req.Description,
|
|
Slug: req.Slug,
|
|
HtmlBody: req.HtmlBody,
|
|
UpdatedAt: req.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
type CustomStaticPagesQueryRequestContext struct {
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Slug string `json:"slug"`
|
|
HtmlBody string `json:"htmlBody"`
|
|
}
|
|
|
|
func (req CustomStaticPagesQueryRequestContext) ToParamRequest() CustomStaticPagesQueryRequest {
|
|
var request CustomStaticPagesQueryRequest
|
|
|
|
if title := req.Title; title != "" {
|
|
request.Title = &title
|
|
}
|
|
if description := req.Description; description != "" {
|
|
request.Description = &description
|
|
}
|
|
if slug := req.Slug; slug != "" {
|
|
request.Slug = &slug
|
|
}
|
|
|
|
return request
|
|
}
|