feat: update ppid data
This commit is contained in:
parent
c973dadd73
commit
bfbea4a661
|
|
@ -7,9 +7,12 @@ type PpidDatas struct {
|
|||
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"`
|
||||
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"`
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -62,6 +62,8 @@ func (_i *ppidDatasController) All(c *fiber.Ctx) error {
|
|||
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"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,20 +19,38 @@ 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)
|
||||
//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 := ""
|
||||
if findUser != nil {
|
||||
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
|
||||
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{
|
||||
ID: ppidDatasReq.ID,
|
||||
Title: ppidDatasReq.Title,
|
||||
|
|
@ -63,6 +78,6 @@ func PpidDatasResponseMapper(
|
|||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ type PpidDatasQueryRequestContext struct {
|
|||
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"`
|
||||
|
|
@ -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