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