feat: update ppid data categories
This commit is contained in:
parent
cf2201426d
commit
65c6125649
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/ppid_data_categories/request"
|
||||
"go-humas-be/app/module/ppid_data_categories/response"
|
||||
"go-humas-be/app/module/ppid_data_categories/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
|
|
@ -54,10 +55,11 @@ func (_i *ppidDataCategoriesController) All(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
reqContext := request.PpidDataCategoriesQueryRequestContext{
|
||||
Title: c.Query("title"),
|
||||
Description: c.Query("description"),
|
||||
ParentId: c.Query("parentId"),
|
||||
IsOnlyTop: c.Query("isOnlyTop"),
|
||||
Title: c.Query("title"),
|
||||
Description: c.Query("description"),
|
||||
ParentId: c.Query("parentId"),
|
||||
IsOnlyTop: c.Query("isOnlyTop"),
|
||||
IsPpidDataIncluded: c.Query("isPpidDataIncluded"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
|
||||
|
|
@ -66,16 +68,32 @@ func (_i *ppidDataCategoriesController) All(c *fiber.Ctx) error {
|
|||
Interface("req", req).Msg("")
|
||||
|
||||
req.Pagination = paginate
|
||||
var ppidDataCategoriesData []*response.PpidDataCategoriesResponse
|
||||
var ppidDataCategoriesWithPpidDataResponse []*response.PpidDataCategoriesWithPpidDataResponse
|
||||
var paging paginator.Pagination
|
||||
|
||||
isPpidDataIncluded := req.IsPpidDataIncluded
|
||||
if isPpidDataIncluded != nil && *isPpidDataIncluded == true {
|
||||
ppidDataCategoriesWithPpidDataResponse, paging, err = _i.ppidDataCategoriesService.AllInPpidData(req)
|
||||
} else {
|
||||
ppidDataCategoriesData, paging, err = _i.ppidDataCategoriesService.All(req)
|
||||
}
|
||||
|
||||
ppidDataCategoriesData, paging, err := _i.ppidDataCategoriesService.All(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var dataResponse any
|
||||
if ppidDataCategoriesData != nil {
|
||||
dataResponse = ppidDataCategoriesData
|
||||
} else {
|
||||
dataResponse = ppidDataCategoriesWithPpidDataResponse
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories list successfully retrieved"},
|
||||
Data: ppidDataCategoriesData,
|
||||
Data: dataResponse,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,17 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_data_categories/repository"
|
||||
res "go-humas-be/app/module/ppid_data_categories/response"
|
||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||
"go-humas-be/app/module/ppid_datas/mapper"
|
||||
ppidDatasRepository "go-humas-be/app/module/ppid_datas/repository"
|
||||
"go-humas-be/app/module/ppid_datas/request"
|
||||
"go-humas-be/app/module/ppid_datas/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
@ -31,3 +40,47 @@ func PpidDataCategoriesResponseMapper(ppidDataCategoriesReq *entity.PpidDataCate
|
|||
}
|
||||
return ppidDataCategoriesRes
|
||||
}
|
||||
|
||||
func PpidDataCategoriesWithPpidDataResponseMapper(
|
||||
log zerolog.Logger,
|
||||
ppidDataCategoriesReq *entity.PpidDataCategories,
|
||||
ppidDataCategoriesRepo repository.PpidDataCategoriesRepository,
|
||||
ppidDatasRepo ppidDatasRepository.PpidDatasRepository,
|
||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
) (ppidDataCategoriesRes *res.PpidDataCategoriesWithPpidDataResponse) {
|
||||
if ppidDataCategoriesReq != nil {
|
||||
pagination := paginator.Pagination{
|
||||
Limit: -1,
|
||||
}
|
||||
|
||||
ppidDatasReq := request.PpidDatasQueryRequest{
|
||||
CategoryId: &ppidDataCategoriesReq.ID,
|
||||
Pagination: &pagination,
|
||||
}
|
||||
|
||||
ppidDatas, _, _ := ppidDatasRepo.GetAll(ppidDatasReq)
|
||||
|
||||
var ppidDatasArr []*response.PpidDatasResponse
|
||||
if len(ppidDatas) > 0 {
|
||||
for _, result := range ppidDatas {
|
||||
ppidDatasArr = append(ppidDatasArr, mapper.PpidDatasResponseMapper(log, ppidDataCategoriesRepo, ppidDataFilesRepo, usersRepo, result))
|
||||
}
|
||||
}
|
||||
|
||||
ppidDataCategoriesRes = &res.PpidDataCategoriesWithPpidDataResponse{
|
||||
ID: ppidDataCategoriesReq.ID,
|
||||
Title: ppidDataCategoriesReq.Title,
|
||||
Description: ppidDataCategoriesReq.Description,
|
||||
Slug: ppidDataCategoriesReq.Slug,
|
||||
ParentId: ppidDataCategoriesReq.ParentId,
|
||||
ThumbnailUrl: "/ppid-data-categories/thumbnail/viewer/" + strconv.Itoa(int(ppidDataCategoriesReq.ID)),
|
||||
IsActive: ppidDataCategoriesReq.IsActive,
|
||||
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
||||
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
||||
|
||||
PpidDatas: ppidDatasArr,
|
||||
}
|
||||
}
|
||||
return ppidDataCategoriesRes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,12 @@ type PpidDataCategoriesGeneric interface {
|
|||
}
|
||||
|
||||
type PpidDataCategoriesQueryRequest struct {
|
||||
Title *string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
IsOnlyTop *bool `json:"isOnlyTop"`
|
||||
ParentId *uint `json:"parentId"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
Title *string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
IsOnlyTop *bool `json:"isOnlyTop"`
|
||||
IsPpidDataIncluded *bool `json:"isPpidDataIncluded"`
|
||||
ParentId *uint `json:"parentId"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type PpidDataCategoriesCreateRequest struct {
|
||||
|
|
@ -55,10 +56,11 @@ func (req PpidDataCategoriesUpdateRequest) ToEntity() *entity.PpidDataCategories
|
|||
}
|
||||
|
||||
type PpidDataCategoriesQueryRequestContext struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
IsOnlyTop string `json:"isOnlyTop"`
|
||||
ParentId string `json:"parentId"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
IsOnlyTop string `json:"isOnlyTop"`
|
||||
IsPpidDataIncluded string `json:"isPpidDataIncluded"`
|
||||
ParentId string `json:"parentId"`
|
||||
}
|
||||
|
||||
func (req PpidDataCategoriesQueryRequestContext) ToParamRequest() PpidDataCategoriesQueryRequest {
|
||||
|
|
@ -83,6 +85,12 @@ func (req PpidDataCategoriesQueryRequestContext) ToParamRequest() PpidDataCatego
|
|||
request.IsOnlyTop = &isOnlyTop
|
||||
}
|
||||
}
|
||||
if isPpidDataIncludedStr := req.IsPpidDataIncluded; isPpidDataIncludedStr != "" {
|
||||
isPpidDataIncluded, err := strconv.ParseBool(isPpidDataIncludedStr)
|
||||
if err == nil {
|
||||
request.IsPpidDataIncluded = &isPpidDataIncluded
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"go-humas-be/app/module/ppid_datas/response"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PpidDataCategoriesResponse struct {
|
||||
ID uint `json:"id"`
|
||||
|
|
@ -15,3 +18,17 @@ type PpidDataCategoriesResponse struct {
|
|||
|
||||
Children []*PpidDataCategoriesResponse `json:"children"`
|
||||
}
|
||||
|
||||
type PpidDataCategoriesWithPpidDataResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Slug string `json:"slug"`
|
||||
ParentId *uint `json:"parentId"`
|
||||
ThumbnailUrl string `json:"thumbnailUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
|
||||
PpidDatas []*response.PpidDatasResponse `json:"ppidDatas"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ import (
|
|||
"go-humas-be/app/module/ppid_data_categories/repository"
|
||||
"go-humas-be/app/module/ppid_data_categories/request"
|
||||
"go-humas-be/app/module/ppid_data_categories/response"
|
||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||
ppidDatasRepository "go-humas-be/app/module/ppid_datas/repository"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
minioStorage "go-humas-be/config/config"
|
||||
"go-humas-be/utils/paginator"
|
||||
"io"
|
||||
|
|
@ -23,14 +26,18 @@ import (
|
|||
|
||||
// PpidDataCategoriesService
|
||||
type ppidDataCategoriesService struct {
|
||||
Repo repository.PpidDataCategoriesRepository
|
||||
MinioStorage *minioStorage.MinioStorage
|
||||
Log zerolog.Logger
|
||||
Repo repository.PpidDataCategoriesRepository
|
||||
PpidDatasRepo ppidDatasRepository.PpidDatasRepository
|
||||
PpidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
MinioStorage *minioStorage.MinioStorage
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// PpidDataCategoriesService define interface of IPpidDataCategoriesService
|
||||
type PpidDataCategoriesService interface {
|
||||
All(req request.PpidDataCategoriesQueryRequest) (ppidDataCategories []*response.PpidDataCategoriesResponse, paging paginator.Pagination, err error)
|
||||
AllInPpidData(req request.PpidDataCategoriesQueryRequest) (ppidDataCategories []*response.PpidDataCategoriesWithPpidDataResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (ppidDataCategories *response.PpidDataCategoriesResponse, err error)
|
||||
ShowBySlug(slug string) (ppidDataCategories *response.PpidDataCategoriesResponse, err error)
|
||||
Save(req request.PpidDataCategoriesCreateRequest) (err error)
|
||||
|
|
@ -41,24 +48,47 @@ type PpidDataCategoriesService interface {
|
|||
}
|
||||
|
||||
// NewPpidDataCategoriesService init PpidDataCategoriesService
|
||||
func NewPpidDataCategoriesService(repo repository.PpidDataCategoriesRepository, minioStorage *minioStorage.MinioStorage, log zerolog.Logger) PpidDataCategoriesService {
|
||||
func NewPpidDataCategoriesService(
|
||||
repo repository.PpidDataCategoriesRepository,
|
||||
ppidDatasRepo ppidDatasRepository.PpidDatasRepository,
|
||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
minioStorage *minioStorage.MinioStorage,
|
||||
log zerolog.Logger,
|
||||
) PpidDataCategoriesService {
|
||||
|
||||
return &ppidDataCategoriesService{
|
||||
Repo: repo,
|
||||
MinioStorage: minioStorage,
|
||||
Log: log,
|
||||
Repo: repo,
|
||||
PpidDatasRepo: ppidDatasRepo,
|
||||
PpidDataFilesRepo: ppidDataFilesRepo,
|
||||
UsersRepo: usersRepo,
|
||||
MinioStorage: minioStorage,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of PpidDataCategoriesService
|
||||
func (_i *ppidDataCategoriesService) All(req request.PpidDataCategoriesQueryRequest) (ppidDataCategoriess []*response.PpidDataCategoriesResponse, paging paginator.Pagination, err error) {
|
||||
func (_i *ppidDataCategoriesService) All(req request.PpidDataCategoriesQueryRequest) (ppidDataCategories []*response.PpidDataCategoriesResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
ppidDataCategoriess = append(ppidDataCategoriess, mapper.PpidDataCategoriesResponseMapper(result, nil))
|
||||
ppidDataCategories = append(ppidDataCategories, mapper.PpidDataCategoriesResponseMapper(result, nil))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) AllInPpidData(req request.PpidDataCategoriesQueryRequest) (ppidDataCategories []*response.PpidDataCategoriesWithPpidDataResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
ppidDataCategories = append(ppidDataCategories, mapper.PpidDataCategoriesWithPpidDataResponseMapper(_i.Log, result, _i.Repo, _i.PpidDatasRepo, _i.PpidDataFilesRepo, _i.UsersRepo))
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDa
|
|||
req.Pagination.Count = count
|
||||
req.Pagination = paginator.Paging(req.Pagination)
|
||||
|
||||
if req.Pagination.Limit == 0 {
|
||||
if req.Pagination.Limit == -1 {
|
||||
query.Limit(req.Pagination.Limit)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ type PpidDatasGeneric interface {
|
|||
type PpidDatasQueryRequest struct {
|
||||
Title *string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
CategoryId *int `json:"categoryId"`
|
||||
CategoryId *uint `json:"categoryId"`
|
||||
LevelGroupId *int `json:"levelGroupId"`
|
||||
Group *string `json:"group"`
|
||||
UserId *uint `json:"userId"`
|
||||
|
|
@ -113,7 +113,8 @@ func (req PpidDatasQueryRequestContext) ToParamRequest() PpidDatasQueryRequest {
|
|||
if categoryIdStr := req.CategoryId; categoryIdStr != "" {
|
||||
categoryId, err := strconv.Atoi(categoryIdStr)
|
||||
if err == nil {
|
||||
request.CategoryId = &categoryId
|
||||
categoryIdUint := uint(categoryId)
|
||||
request.CategoryId = &categoryIdUint
|
||||
}
|
||||
}
|
||||
if isPublishStr := req.IsPublish; isPublishStr != "" {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func (_i *userLevelsRepository) GetAll(req request.UserLevelsQueryRequest) (user
|
|||
req.Pagination.Count = count
|
||||
req.Pagination = paginator.Paging(req.Pagination)
|
||||
|
||||
if req.Pagination.Limit == 0 {
|
||||
if req.Pagination.Limit == -1 {
|
||||
query.Limit(req.Pagination.Limit)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3643,6 +3643,11 @@ const docTemplate = `{
|
|||
"name": "isOnlyTop",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"name": "isPpidDataIncluded",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "parentId",
|
||||
|
|
|
|||
|
|
@ -3632,6 +3632,11 @@
|
|||
"name": "isOnlyTop",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"name": "isPpidDataIncluded",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "parentId",
|
||||
|
|
|
|||
|
|
@ -2907,6 +2907,9 @@ paths:
|
|||
- in: query
|
||||
name: isOnlyTop
|
||||
type: boolean
|
||||
- in: query
|
||||
name: isPpidDataIncluded
|
||||
type: boolean
|
||||
- in: query
|
||||
name: parentId
|
||||
type: integer
|
||||
|
|
|
|||
Loading…
Reference in New Issue