2024-03-05 19:15:53 +00:00
|
|
|
package request
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"go-humas-be/app/database/entity"
|
|
|
|
|
"go-humas-be/utils/paginator"
|
2024-04-16 02:08:00 +00:00
|
|
|
"strconv"
|
2024-03-05 19:15:53 +00:00
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PpidDatasGeneric interface {
|
|
|
|
|
ToEntity()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PpidDatasQueryRequest struct {
|
2024-04-28 18:39:43 +00:00
|
|
|
Title *string `json:"title"`
|
|
|
|
|
Description *string `json:"description"`
|
|
|
|
|
CategoryId *int `json:"categoryId"`
|
|
|
|
|
LevelGroupId *int `json:"levelGroupId"`
|
|
|
|
|
Group *string `json:"group"`
|
|
|
|
|
CreatedById *int `json:"createdById"`
|
|
|
|
|
StatusId *int `json:"statusId"`
|
|
|
|
|
IsPublish *bool `json:"isPublish"`
|
|
|
|
|
Pagination *paginator.Pagination `json:"pagination"`
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PpidDatasCreateRequest struct {
|
2024-04-28 18:39:43 +00:00
|
|
|
Title string `json:"title" validate:"required"`
|
|
|
|
|
Description string `json:"description" validate:"required"`
|
2024-04-30 03:53:50 +00:00
|
|
|
Slug string `json:"slug" validate:"required"`
|
2024-04-29 09:46:37 +00:00
|
|
|
CategoryId uint `json:"categoryId" validate:"required"`
|
2024-04-28 18:39:43 +00:00
|
|
|
StatusId int `json:"statusId" validate:"required"`
|
2024-04-29 09:46:37 +00:00
|
|
|
CreatedById *uint `json:"createdById"`
|
2024-04-28 18:39:43 +00:00
|
|
|
LevelGroupId *int `json:"levelGroupId"`
|
|
|
|
|
Group *string `json:"group"`
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req PpidDatasCreateRequest) ToEntity() *entity.PpidDatas {
|
|
|
|
|
return &entity.PpidDatas{
|
2024-04-28 18:39:43 +00:00
|
|
|
Title: req.Title,
|
|
|
|
|
Description: req.Description,
|
2024-04-30 03:53:50 +00:00
|
|
|
Slug: req.Slug,
|
2024-04-28 18:39:43 +00:00
|
|
|
CategoryId: req.CategoryId,
|
|
|
|
|
CreatedById: req.CreatedById,
|
|
|
|
|
StatusId: req.StatusId,
|
|
|
|
|
LevelGroupId: req.LevelGroupId,
|
|
|
|
|
Group: req.Group,
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PpidDatasUpdateRequest struct {
|
2024-04-28 18:39:43 +00:00
|
|
|
ID uint `json:"id" validate:"required"`
|
|
|
|
|
Title string `json:"title" validate:"required"`
|
|
|
|
|
Description string `json:"description" validate:"required"`
|
2024-04-30 03:53:50 +00:00
|
|
|
Slug string `json:"slug" validate:"required"`
|
2024-04-29 09:46:37 +00:00
|
|
|
CategoryId uint `json:"category_id" validate:"required"`
|
2024-04-28 18:39:43 +00:00
|
|
|
StatusId int `json:"status_id" validate:"required"`
|
2024-04-29 09:46:37 +00:00
|
|
|
CreatedById *uint `json:"created_by_id"`
|
2024-04-28 18:39:43 +00:00
|
|
|
IsPublish *bool `json:"is_publish"`
|
|
|
|
|
PublishedAt *time.Time `json:"published_at"`
|
|
|
|
|
LevelGroupId *int `json:"levelGroupId"`
|
|
|
|
|
Group *string `json:"group"`
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req PpidDatasUpdateRequest) ToEntity() *entity.PpidDatas {
|
|
|
|
|
return &entity.PpidDatas{
|
2024-04-28 18:39:43 +00:00
|
|
|
ID: req.ID,
|
|
|
|
|
Title: req.Title,
|
|
|
|
|
Description: req.Description,
|
2024-04-30 03:53:50 +00:00
|
|
|
Slug: req.Slug,
|
2024-04-28 18:39:43 +00:00
|
|
|
CategoryId: req.CategoryId,
|
|
|
|
|
CreatedById: req.CreatedById,
|
|
|
|
|
StatusId: req.StatusId,
|
|
|
|
|
IsPublish: req.IsPublish,
|
|
|
|
|
PublishedAt: req.PublishedAt,
|
|
|
|
|
LevelGroupId: req.LevelGroupId,
|
|
|
|
|
Group: req.Group,
|
|
|
|
|
UpdatedAt: time.Now(),
|
2024-04-16 02:08:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PpidDatasQueryRequestContext struct {
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
CategoryId string `json:"categoryId"`
|
2024-04-28 18:39:43 +00:00
|
|
|
Group string `json:"group"`
|
2024-04-16 02:08:00 +00:00
|
|
|
CreatedById string `json:"createdById"`
|
|
|
|
|
StatusId string `json:"statusId"`
|
|
|
|
|
IsPublish string `json:"isPublish"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req PpidDatasQueryRequestContext) ToParamRequest() PpidDatasQueryRequest {
|
|
|
|
|
var request PpidDatasQueryRequest
|
|
|
|
|
|
|
|
|
|
if title := req.Title; title != "" {
|
|
|
|
|
request.Title = &title
|
|
|
|
|
}
|
|
|
|
|
if description := req.Description; description != "" {
|
|
|
|
|
request.Description = &description
|
|
|
|
|
}
|
2024-04-28 18:39:43 +00:00
|
|
|
if group := req.Group; group != "" {
|
|
|
|
|
request.Group = &group
|
|
|
|
|
}
|
2024-04-16 02:08:00 +00:00
|
|
|
if categoryIdStr := req.CategoryId; categoryIdStr != "" {
|
|
|
|
|
categoryId, err := strconv.Atoi(categoryIdStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.CategoryId = &categoryId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if isPublishStr := req.IsPublish; isPublishStr != "" {
|
|
|
|
|
isPublish, err := strconv.ParseBool(isPublishStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.IsPublish = &isPublish
|
|
|
|
|
}
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
2024-04-16 02:08:00 +00:00
|
|
|
if statusIdStr := req.StatusId; statusIdStr != "" {
|
|
|
|
|
statusId, err := strconv.Atoi(statusIdStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.StatusId = &statusId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if createdByIdStr := req.CreatedById; createdByIdStr != "" {
|
|
|
|
|
createdById, err := strconv.Atoi(createdByIdStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.CreatedById = &createdById
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return request
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|