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"`
|
2024-05-12 05:15:13 +00:00
|
|
|
UserId *uint `json:"userId"`
|
|
|
|
|
UserRoleId *uint `json:"userRoleId"`
|
|
|
|
|
UserLevelId *uint `json:"userLevelId"`
|
2024-04-28 18:39:43 +00:00
|
|
|
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-05-12 05:15:13 +00:00
|
|
|
LevelGroupId *uint `json:"levelGroupId"`
|
2024-04-28 18:39:43 +00:00
|
|
|
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,
|
|
|
|
|
StatusId: req.StatusId,
|
|
|
|
|
LevelGroupId: req.LevelGroupId,
|
|
|
|
|
Group: req.Group,
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PpidDatasUpdateRequest struct {
|
2024-05-05 14:55:06 +00:00
|
|
|
ID uint `json:"id" validate:"required"`
|
|
|
|
|
Title string `json:"title" validate:"required"`
|
|
|
|
|
Description string `json:"description" validate:"required"`
|
|
|
|
|
Slug string `json:"slug" validate:"required"`
|
|
|
|
|
CategoryId uint `json:"categoryId" validate:"required"`
|
|
|
|
|
StatusId int `json:"statusId" validate:"required"`
|
|
|
|
|
NeedApprovalFromUserRole *string `json:"needApprovalFrom"`
|
|
|
|
|
NeedApprovalFromUserLevel *string `json:"needApprovalFromUserLevel"`
|
2024-05-12 05:15:13 +00:00
|
|
|
BackApprovalToUserRole *string `json:"backApprovalToUserRole"`
|
|
|
|
|
BackApprovalToUserLevel *string `json:"backApprovalToUserLevel"`
|
2024-05-05 14:55:06 +00:00
|
|
|
IsPublish *bool `json:"isPublish"`
|
|
|
|
|
PublishLevel *int `json:"publishLevel"`
|
|
|
|
|
PublishedAt *time.Time `json:"publishedAt"`
|
2024-05-12 05:15:13 +00:00
|
|
|
LevelGroupId *uint `json:"levelGroupId"`
|
2024-05-05 14:55:06 +00:00
|
|
|
Group *string `json:"group"`
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req PpidDatasUpdateRequest) ToEntity() *entity.PpidDatas {
|
|
|
|
|
return &entity.PpidDatas{
|
2024-05-05 14:55:06 +00:00
|
|
|
ID: req.ID,
|
|
|
|
|
Title: req.Title,
|
|
|
|
|
Description: req.Description,
|
|
|
|
|
Slug: req.Slug,
|
|
|
|
|
CategoryId: req.CategoryId,
|
|
|
|
|
StatusId: req.StatusId,
|
|
|
|
|
NeedApprovalFromUserRole: req.NeedApprovalFromUserRole,
|
|
|
|
|
NeedApprovalFromUserLevel: req.NeedApprovalFromUserLevel,
|
|
|
|
|
BackApprovalToUserRole: req.BackApprovalToUserRole,
|
|
|
|
|
BackApprovalToUserLevel: req.BackApprovalToUserLevel,
|
|
|
|
|
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"`
|
2024-05-12 05:15:13 +00:00
|
|
|
UserId string `json:"userId"`
|
|
|
|
|
UserRoleId string `json:"userRoleId"`
|
|
|
|
|
UserLevelId string `json:"userLevelId"`
|
2024-04-16 02:08:00 +00:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-12 05:15:13 +00:00
|
|
|
if userIdStr := req.UserId; userIdStr != "" {
|
|
|
|
|
userId, err := strconv.Atoi(userIdStr)
|
2024-04-16 02:08:00 +00:00
|
|
|
if err == nil {
|
2024-05-12 05:15:13 +00:00
|
|
|
userIdUint := uint(userId)
|
|
|
|
|
request.UserId = &userIdUint
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if userRoleIdStr := req.UserRoleId; userRoleIdStr != "" {
|
|
|
|
|
userRoleId, err := strconv.Atoi(userRoleIdStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
userRoleIdUint := uint(userRoleId)
|
|
|
|
|
request.UserRoleId = &userRoleIdUint
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if userLevelIdStr := req.UserLevelId; userLevelIdStr != "" {
|
|
|
|
|
userLevelId, err := strconv.Atoi(userLevelIdStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
userLevelIdUint := uint(userLevelId)
|
|
|
|
|
request.UserLevelId = &userLevelIdUint
|
2024-04-16 02:08:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return request
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|