feat: update ppid data
This commit is contained in:
parent
73fa0254e0
commit
f035d024cd
|
|
@ -3,25 +3,28 @@ package entity
|
|||
import "time"
|
||||
|
||||
type PpidDatas struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
Title string `json:"title" gorm:"type:varchar"`
|
||||
Description string `json:"description" gorm:"type:varchar"`
|
||||
Slug string `json:"slug" gorm:"type:varchar"`
|
||||
CategoryId uint `json:"category_id" gorm:"type:int4"`
|
||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||
LevelGroupId *uint `json:"level_group_id" gorm:"type:int4"`
|
||||
Group *string `json:"group" gorm:"type:varchar"`
|
||||
Position *int `json:"position" gorm:"type:int4"`
|
||||
NeedApprovalFromUserRole *string `json:"need_approval_from_user_role" gorm:"type:varchar"`
|
||||
NeedApprovalFromUserLevel *string `json:"need_approval_from_user_level" gorm:"type:varchar"`
|
||||
BackApprovalToUserRole *string `json:"back_approval_to_user_role" gorm:"type:varchar"`
|
||||
BackApprovalToUserLevel *string `json:"back_approval_to_user_level" gorm:"type:varchar"`
|
||||
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
||||
PublishLevel *int `json:"publish_level" gorm:"type:int4"`
|
||||
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
|
||||
ApprovalStatusId int `json:"approval_status_id" gorm:"type:int4"`
|
||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
Title string `json:"title" gorm:"type:varchar"`
|
||||
Description string `json:"description" gorm:"type:varchar"`
|
||||
Slug string `json:"slug" gorm:"type:varchar"`
|
||||
CategoryId uint `json:"category_id" gorm:"index"`
|
||||
Category PpidDataCategories `json:"category" gorm:"foreignKey:CategoryId;references:ID"`
|
||||
CreatedById *uint `json:"created_by_id" gorm:"index"`
|
||||
CreatedBy Users `json:"created_by" gorm:"foreignKey:CreatedById;references:ID"`
|
||||
LevelGroupId *uint `json:"level_group_id" gorm:"index"`
|
||||
LevelGroup UserLevels `json:"level_group" gorm:"foreignKey:LevelGroupId;references:ID"`
|
||||
Group *string `json:"group" gorm:"type:varchar"`
|
||||
Position *int `json:"position" gorm:"type:int4"`
|
||||
NeedApprovalFromUserRole *string `json:"need_approval_from_user_role" gorm:"type:varchar"`
|
||||
NeedApprovalFromUserLevel *string `json:"need_approval_from_user_level" gorm:"type:varchar"`
|
||||
BackApprovalToUserRole *string `json:"back_approval_to_user_role" gorm:"type:varchar"`
|
||||
BackApprovalToUserLevel *string `json:"back_approval_to_user_level" gorm:"type:varchar"`
|
||||
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
||||
PublishLevel *int `json:"publish_level" gorm:"type:int4"`
|
||||
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
|
||||
ApprovalStatusId int `json:"approval_status_id" gorm:"type:int4"`
|
||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func NewPpidDatasController(ppidDatasService service.PpidDatasService) PpidDatas
|
|||
// @Description API for getting all PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param req query request.PpidDatasQueryRequest false "query parameters"
|
||||
// @Param req query paginator.Pagination false "pagination parameters"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -56,14 +56,16 @@ func (_i *ppidDatasController) All(c *fiber.Ctx) error {
|
|||
authToken := c.Get("Authorization")
|
||||
|
||||
reqContext := request.PpidDatasQueryRequestContext{
|
||||
Title: c.Query("title"),
|
||||
Description: c.Query("description"),
|
||||
CategoryId: c.Query("categoryId"),
|
||||
UserId: c.Query("userId"),
|
||||
UserRoleId: c.Query("userRoleId"),
|
||||
UserLevelId: c.Query("userLevelId"),
|
||||
StatusId: c.Query("statusId"),
|
||||
IsPublish: c.Query("isPublish"),
|
||||
Title: c.Query("title"),
|
||||
Description: c.Query("description"),
|
||||
CategoryId: c.Query("categoryId"),
|
||||
UserId: c.Query("userId"),
|
||||
UserRoleId: c.Query("userRoleId"),
|
||||
UserLevelId: c.Query("userLevelId"),
|
||||
Group: c.Query("group"),
|
||||
LevelGroupId: c.Query("levelGroupId"),
|
||||
StatusId: c.Query("statusId"),
|
||||
IsPublish: c.Query("isPublish"),
|
||||
}
|
||||
|
||||
req := reqContext.ToParamRequest()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
ppidDataFilesResponse "go-humas-be/app/module/ppid_data_files/response"
|
||||
res "go-humas-be/app/module/ppid_datas/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
func PpidDatasResponseMapper(
|
||||
|
|
@ -18,51 +19,65 @@ func PpidDatasResponseMapper(
|
|||
usersRepo usersRepository.UsersRepository,
|
||||
ppidDatasReq *entity.PpidDatas,
|
||||
) (ppidDatasRes *res.PpidDatasResponse) {
|
||||
if ppidDatasReq != nil {
|
||||
findCategory, _ := ppidDataCategoriesRepo.FindOne(ppidDatasReq.CategoryId)
|
||||
categoryName := ""
|
||||
if findCategory != nil {
|
||||
categoryName = findCategory.Title
|
||||
}
|
||||
if ppidDatasReq == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
findUser, _ := usersRepo.FindOne(*ppidDatasReq.CreatedById)
|
||||
createdByName := ""
|
||||
if findUser != nil {
|
||||
createdByName = findUser.Fullname
|
||||
}
|
||||
//log.Info().Str("timestamp", time.Now().
|
||||
// Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "PpidData:Category").
|
||||
// Interface("Category", ppidDatasReq.Category).Msg("")
|
||||
|
||||
ppidDataFiles, _ := ppidDataFilesRepo.FindByPpidData(ppidDatasReq.ID)
|
||||
log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "PpidData:Category").
|
||||
Interface("CreatedBy", ppidDatasReq.CreatedBy).Msg("")
|
||||
|
||||
var ppidDataFilesArr []*ppidDataFilesResponse.PpidDataFilesResponse
|
||||
if len(ppidDataFiles) > 0 {
|
||||
for _, result := range ppidDataFiles {
|
||||
ppidDataFilesArr = append(ppidDataFilesArr, ppidDataFilesMapper.PpidDataFilesResponseMapper(result))
|
||||
}
|
||||
}
|
||||
categoryName := ""
|
||||
if ppidDatasReq.Category.ID != 0 {
|
||||
categoryName = ppidDatasReq.Category.Title
|
||||
}
|
||||
|
||||
//log.Info().Str("timestamp", time.Now().
|
||||
// Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "UserInfo:PpidData").
|
||||
// Interface("payload", ppidDataFiles).Msg("")
|
||||
findUser, err := usersRepo.FindOne(*ppidDatasReq.CreatedById)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error fetching user")
|
||||
return nil
|
||||
}
|
||||
createdByName := ""
|
||||
if findUser != nil {
|
||||
createdByName = findUser.Fullname
|
||||
}
|
||||
|
||||
ppidDatasRes = &res.PpidDatasResponse{
|
||||
ID: ppidDatasReq.ID,
|
||||
Title: ppidDatasReq.Title,
|
||||
Description: ppidDatasReq.Description,
|
||||
Slug: ppidDatasReq.Slug,
|
||||
CategoryId: ppidDatasReq.CategoryId,
|
||||
CategoryName: &categoryName,
|
||||
CreatedById: ppidDatasReq.CreatedById,
|
||||
CreatedByName: &createdByName,
|
||||
Position: ppidDatasReq.Position,
|
||||
StatusId: ppidDatasReq.StatusId,
|
||||
IsPublish: ppidDatasReq.IsPublish,
|
||||
PublishedAt: ppidDatasReq.PublishedAt,
|
||||
IsActive: ppidDatasReq.IsActive,
|
||||
CreatedAt: ppidDatasReq.CreatedAt,
|
||||
UpdatedAt: ppidDatasReq.UpdatedAt,
|
||||
ppidDataFiles, err := ppidDataFilesRepo.FindByPpidData(ppidDatasReq.ID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error fetching files")
|
||||
return nil
|
||||
}
|
||||
|
||||
PpidDataFiles: ppidDataFilesArr,
|
||||
var ppidDataFilesArr []*ppidDataFilesResponse.PpidDataFilesResponse
|
||||
if len(ppidDataFiles) > 0 {
|
||||
for _, result := range ppidDataFiles {
|
||||
ppidDataFilesArr = append(ppidDataFilesArr, ppidDataFilesMapper.PpidDataFilesResponseMapper(result))
|
||||
}
|
||||
}
|
||||
|
||||
ppidDatasRes = &res.PpidDatasResponse{
|
||||
ID: ppidDatasReq.ID,
|
||||
Title: ppidDatasReq.Title,
|
||||
Description: ppidDatasReq.Description,
|
||||
Slug: ppidDatasReq.Slug,
|
||||
CategoryId: ppidDatasReq.CategoryId,
|
||||
CategoryName: &categoryName,
|
||||
CreatedById: ppidDatasReq.CreatedById,
|
||||
CreatedByName: &createdByName,
|
||||
Position: ppidDatasReq.Position,
|
||||
StatusId: ppidDatasReq.StatusId,
|
||||
IsPublish: ppidDatasReq.IsPublish,
|
||||
PublishedAt: ppidDatasReq.PublishedAt,
|
||||
IsActive: ppidDatasReq.IsActive,
|
||||
CreatedAt: ppidDatasReq.CreatedAt,
|
||||
UpdatedAt: ppidDatasReq.UpdatedAt,
|
||||
|
||||
PpidDataFiles: ppidDataFilesArr,
|
||||
}
|
||||
|
||||
return ppidDatasRes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func NewPpidDatasRepository(db *database.Database, logger zerolog.Logger) PpidDa
|
|||
func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDatass []*entity.PpidDatas, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.PpidDatas{})
|
||||
query := _i.DB.DB.Model(&entity.PpidDatas{}).Preload("CreatedBy").Preload("Category").Preload("LevelGroup")
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.Title != nil && *req.Title != "" {
|
||||
|
|
@ -54,9 +54,11 @@ func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDa
|
|||
if req.CategoryId != nil {
|
||||
query = query.Where("category_id = ?", req.CategoryId)
|
||||
}
|
||||
if req.Group != nil && *req.Group != "" {
|
||||
title := strings.ToLower(*req.Title)
|
||||
query = query.Where("LOWER(title) LIKE ?", "%"+strings.ToLower(title)+"%")
|
||||
if req.LevelGroupId != nil {
|
||||
query = query.Where("level_group_id = ?", req.LevelGroupId)
|
||||
}
|
||||
if req.LevelGroupId != nil {
|
||||
query = query.Where("level_group_id = ?", req.LevelGroupId)
|
||||
}
|
||||
if req.IsPublish != nil {
|
||||
query = query.Where("is_publish = ?", req.IsPublish)
|
||||
|
|
@ -76,6 +78,10 @@ func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDa
|
|||
}
|
||||
query.Count(&count)
|
||||
|
||||
//_i.Log.Info().Str("timestamp", time.Now().
|
||||
// Format(time.RFC3339)).Str("ppidDatasRepository:GetAll", "PpidData:CreatedBy").
|
||||
// Interface("Query", query.ToSQL).Msg("")
|
||||
|
||||
if req.Pagination.SortBy != "" {
|
||||
direction := "ASC"
|
||||
if req.Pagination.Sort == "desc" {
|
||||
|
|
@ -87,7 +93,7 @@ func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDa
|
|||
req.Pagination.Count = count
|
||||
req.Pagination = paginator.Paging(req.Pagination)
|
||||
|
||||
if req.Pagination.Limit == -1 {
|
||||
if req.Pagination.Limit != -1 {
|
||||
query.Limit(req.Pagination.Limit)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,16 +103,17 @@ func (req PpidDatasUpdatePositionRequest) ToEntity() *entity.PpidDatas {
|
|||
}
|
||||
|
||||
type PpidDatasQueryRequestContext struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
CategoryId string `json:"categoryId"`
|
||||
Group string `json:"group"`
|
||||
CreatedById string `json:"createdById"`
|
||||
UserId string `json:"userId"`
|
||||
UserRoleId string `json:"userRoleId"`
|
||||
UserLevelId string `json:"userLevelId"`
|
||||
StatusId string `json:"statusId"`
|
||||
IsPublish string `json:"isPublish"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
CategoryId string `json:"categoryId"`
|
||||
LevelGroupId string `json:"levelGroupId"`
|
||||
Group string `json:"group"`
|
||||
CreatedById string `json:"createdById"`
|
||||
UserId string `json:"userId"`
|
||||
UserRoleId string `json:"userRoleId"`
|
||||
UserLevelId string `json:"userLevelId"`
|
||||
StatusId string `json:"statusId"`
|
||||
IsPublish string `json:"isPublish"`
|
||||
}
|
||||
|
||||
func (req PpidDatasQueryRequestContext) ToParamRequest() PpidDatasQueryRequest {
|
||||
|
|
@ -124,6 +125,12 @@ func (req PpidDatasQueryRequestContext) ToParamRequest() PpidDatasQueryRequest {
|
|||
if description := req.Description; description != "" {
|
||||
request.Description = &description
|
||||
}
|
||||
if levelGroupIdStr := req.LevelGroupId; levelGroupIdStr != "" {
|
||||
levelGroupId, err := strconv.Atoi(levelGroupIdStr)
|
||||
if err == nil {
|
||||
request.LevelGroupId = &levelGroupId
|
||||
}
|
||||
}
|
||||
if group := req.Group; group != "" {
|
||||
request.Group = &group
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4610,8 +4610,7 @@ const docTemplate = `{
|
|||
"default": "Bearer \u003cAdd access token here\u003e",
|
||||
"description": "Insert your access token",
|
||||
"name": "Authorization",
|
||||
"in": "header",
|
||||
"required": true
|
||||
"in": "header"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
|
|
|
|||
|
|
@ -4599,8 +4599,7 @@
|
|||
"default": "Bearer \u003cAdd access token here\u003e",
|
||||
"description": "Insert your access token",
|
||||
"name": "Authorization",
|
||||
"in": "header",
|
||||
"required": true
|
||||
"in": "header"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
|
|
|
|||
|
|
@ -3776,7 +3776,6 @@ paths:
|
|||
description: Insert your access token
|
||||
in: header
|
||||
name: Authorization
|
||||
required: true
|
||||
type: string
|
||||
- in: query
|
||||
name: categoryId
|
||||
|
|
|
|||
Loading…
Reference in New Issue