feat: update ppid data
This commit is contained in:
parent
73fa0254e0
commit
f035d024cd
|
|
@ -7,9 +7,12 @@ type PpidDatas struct {
|
||||||
Title string `json:"title" gorm:"type:varchar"`
|
Title string `json:"title" gorm:"type:varchar"`
|
||||||
Description string `json:"description" gorm:"type:varchar"`
|
Description string `json:"description" gorm:"type:varchar"`
|
||||||
Slug string `json:"slug" gorm:"type:varchar"`
|
Slug string `json:"slug" gorm:"type:varchar"`
|
||||||
CategoryId uint `json:"category_id" gorm:"type:int4"`
|
CategoryId uint `json:"category_id" gorm:"index"`
|
||||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
Category PpidDataCategories `json:"category" gorm:"foreignKey:CategoryId;references:ID"`
|
||||||
LevelGroupId *uint `json:"level_group_id" gorm:"type:int4"`
|
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"`
|
Group *string `json:"group" gorm:"type:varchar"`
|
||||||
Position *int `json:"position" gorm:"type:int4"`
|
Position *int `json:"position" gorm:"type:int4"`
|
||||||
NeedApprovalFromUserRole *string `json:"need_approval_from_user_role" gorm:"type:varchar"`
|
NeedApprovalFromUserRole *string `json:"need_approval_from_user_role" gorm:"type:varchar"`
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func NewPpidDatasController(ppidDatasService service.PpidDatasService) PpidDatas
|
||||||
// @Description API for getting all PpidDatas
|
// @Description API for getting all PpidDatas
|
||||||
// @Tags PPID Data
|
// @Tags PPID Data
|
||||||
// @Security Bearer
|
// @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 request.PpidDatasQueryRequest false "query parameters"
|
||||||
// @Param req query paginator.Pagination false "pagination parameters"
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
|
|
@ -62,6 +62,8 @@ func (_i *ppidDatasController) All(c *fiber.Ctx) error {
|
||||||
UserId: c.Query("userId"),
|
UserId: c.Query("userId"),
|
||||||
UserRoleId: c.Query("userRoleId"),
|
UserRoleId: c.Query("userRoleId"),
|
||||||
UserLevelId: c.Query("userLevelId"),
|
UserLevelId: c.Query("userLevelId"),
|
||||||
|
Group: c.Query("group"),
|
||||||
|
LevelGroupId: c.Query("levelGroupId"),
|
||||||
StatusId: c.Query("statusId"),
|
StatusId: c.Query("statusId"),
|
||||||
IsPublish: c.Query("isPublish"),
|
IsPublish: c.Query("isPublish"),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
ppidDataFilesResponse "go-humas-be/app/module/ppid_data_files/response"
|
ppidDataFilesResponse "go-humas-be/app/module/ppid_data_files/response"
|
||||||
res "go-humas-be/app/module/ppid_datas/response"
|
res "go-humas-be/app/module/ppid_datas/response"
|
||||||
usersRepository "go-humas-be/app/module/users/repository"
|
usersRepository "go-humas-be/app/module/users/repository"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PpidDatasResponseMapper(
|
func PpidDatasResponseMapper(
|
||||||
|
|
@ -18,20 +19,38 @@ func PpidDatasResponseMapper(
|
||||||
usersRepo usersRepository.UsersRepository,
|
usersRepo usersRepository.UsersRepository,
|
||||||
ppidDatasReq *entity.PpidDatas,
|
ppidDatasReq *entity.PpidDatas,
|
||||||
) (ppidDatasRes *res.PpidDatasResponse) {
|
) (ppidDatasRes *res.PpidDatasResponse) {
|
||||||
if ppidDatasReq != nil {
|
if ppidDatasReq == nil {
|
||||||
findCategory, _ := ppidDataCategoriesRepo.FindOne(ppidDatasReq.CategoryId)
|
return nil
|
||||||
categoryName := ""
|
|
||||||
if findCategory != nil {
|
|
||||||
categoryName = findCategory.Title
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findUser, _ := usersRepo.FindOne(*ppidDatasReq.CreatedById)
|
//log.Info().Str("timestamp", time.Now().
|
||||||
|
// Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "PpidData:Category").
|
||||||
|
// Interface("Category", ppidDatasReq.Category).Msg("")
|
||||||
|
|
||||||
|
log.Info().Str("timestamp", time.Now().
|
||||||
|
Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "PpidData:Category").
|
||||||
|
Interface("CreatedBy", ppidDatasReq.CreatedBy).Msg("")
|
||||||
|
|
||||||
|
categoryName := ""
|
||||||
|
if ppidDatasReq.Category.ID != 0 {
|
||||||
|
categoryName = ppidDatasReq.Category.Title
|
||||||
|
}
|
||||||
|
|
||||||
|
findUser, err := usersRepo.FindOne(*ppidDatasReq.CreatedById)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Error fetching user")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
createdByName := ""
|
createdByName := ""
|
||||||
if findUser != nil {
|
if findUser != nil {
|
||||||
createdByName = findUser.Fullname
|
createdByName = findUser.Fullname
|
||||||
}
|
}
|
||||||
|
|
||||||
ppidDataFiles, _ := ppidDataFilesRepo.FindByPpidData(ppidDatasReq.ID)
|
ppidDataFiles, err := ppidDataFilesRepo.FindByPpidData(ppidDatasReq.ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Error fetching files")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var ppidDataFilesArr []*ppidDataFilesResponse.PpidDataFilesResponse
|
var ppidDataFilesArr []*ppidDataFilesResponse.PpidDataFilesResponse
|
||||||
if len(ppidDataFiles) > 0 {
|
if len(ppidDataFiles) > 0 {
|
||||||
|
|
@ -40,10 +59,6 @@ func PpidDatasResponseMapper(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Info().Str("timestamp", time.Now().
|
|
||||||
// Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "UserInfo:PpidData").
|
|
||||||
// Interface("payload", ppidDataFiles).Msg("")
|
|
||||||
|
|
||||||
ppidDatasRes = &res.PpidDatasResponse{
|
ppidDatasRes = &res.PpidDatasResponse{
|
||||||
ID: ppidDatasReq.ID,
|
ID: ppidDatasReq.ID,
|
||||||
Title: ppidDatasReq.Title,
|
Title: ppidDatasReq.Title,
|
||||||
|
|
@ -63,6 +78,6 @@ func PpidDatasResponseMapper(
|
||||||
|
|
||||||
PpidDataFiles: ppidDataFilesArr,
|
PpidDataFiles: ppidDataFilesArr,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ppidDatasRes
|
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) {
|
func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDatass []*entity.PpidDatas, paging paginator.Pagination, err error) {
|
||||||
var count int64
|
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)
|
query = query.Where("is_active = ?", true)
|
||||||
|
|
||||||
if req.Title != nil && *req.Title != "" {
|
if req.Title != nil && *req.Title != "" {
|
||||||
|
|
@ -54,9 +54,11 @@ func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDa
|
||||||
if req.CategoryId != nil {
|
if req.CategoryId != nil {
|
||||||
query = query.Where("category_id = ?", req.CategoryId)
|
query = query.Where("category_id = ?", req.CategoryId)
|
||||||
}
|
}
|
||||||
if req.Group != nil && *req.Group != "" {
|
if req.LevelGroupId != nil {
|
||||||
title := strings.ToLower(*req.Title)
|
query = query.Where("level_group_id = ?", req.LevelGroupId)
|
||||||
query = query.Where("LOWER(title) LIKE ?", "%"+strings.ToLower(title)+"%")
|
}
|
||||||
|
if req.LevelGroupId != nil {
|
||||||
|
query = query.Where("level_group_id = ?", req.LevelGroupId)
|
||||||
}
|
}
|
||||||
if req.IsPublish != nil {
|
if req.IsPublish != nil {
|
||||||
query = query.Where("is_publish = ?", req.IsPublish)
|
query = query.Where("is_publish = ?", req.IsPublish)
|
||||||
|
|
@ -76,6 +78,10 @@ func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDa
|
||||||
}
|
}
|
||||||
query.Count(&count)
|
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 != "" {
|
if req.Pagination.SortBy != "" {
|
||||||
direction := "ASC"
|
direction := "ASC"
|
||||||
if req.Pagination.Sort == "desc" {
|
if req.Pagination.Sort == "desc" {
|
||||||
|
|
@ -87,7 +93,7 @@ func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDa
|
||||||
req.Pagination.Count = count
|
req.Pagination.Count = count
|
||||||
req.Pagination = paginator.Paging(req.Pagination)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
||||||
if req.Pagination.Limit == -1 {
|
if req.Pagination.Limit != -1 {
|
||||||
query.Limit(req.Pagination.Limit)
|
query.Limit(req.Pagination.Limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ type PpidDatasQueryRequestContext struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
CategoryId string `json:"categoryId"`
|
CategoryId string `json:"categoryId"`
|
||||||
|
LevelGroupId string `json:"levelGroupId"`
|
||||||
Group string `json:"group"`
|
Group string `json:"group"`
|
||||||
CreatedById string `json:"createdById"`
|
CreatedById string `json:"createdById"`
|
||||||
UserId string `json:"userId"`
|
UserId string `json:"userId"`
|
||||||
|
|
@ -124,6 +125,12 @@ func (req PpidDatasQueryRequestContext) ToParamRequest() PpidDatasQueryRequest {
|
||||||
if description := req.Description; description != "" {
|
if description := req.Description; description != "" {
|
||||||
request.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 != "" {
|
if group := req.Group; group != "" {
|
||||||
request.Group = &group
|
request.Group = &group
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4610,8 +4610,7 @@ const docTemplate = `{
|
||||||
"default": "Bearer \u003cAdd access token here\u003e",
|
"default": "Bearer \u003cAdd access token here\u003e",
|
||||||
"description": "Insert your access token",
|
"description": "Insert your access token",
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header",
|
"in": "header"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
|
||||||
|
|
@ -4599,8 +4599,7 @@
|
||||||
"default": "Bearer \u003cAdd access token here\u003e",
|
"default": "Bearer \u003cAdd access token here\u003e",
|
||||||
"description": "Insert your access token",
|
"description": "Insert your access token",
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header",
|
"in": "header"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
|
||||||
|
|
@ -3776,7 +3776,6 @@ paths:
|
||||||
description: Insert your access token
|
description: Insert your access token
|
||||||
in: header
|
in: header
|
||||||
name: Authorization
|
name: Authorization
|
||||||
required: true
|
|
||||||
type: string
|
type: string
|
||||||
- in: query
|
- in: query
|
||||||
name: categoryId
|
name: categoryId
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue