fix: add createdBy fullname in detail categories
This commit is contained in:
parent
4b814cbdc5
commit
575c271d27
|
|
@ -7,23 +7,30 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ArticleCategoriesResponseMapper(articleCategoriesReq *entity.ArticleCategories, host string) (articleCategoriesRes *res.ArticleCategoriesResponse) {
|
// func ArticleCategoriesResponseMapper(articleCategoriesReq *entity.ArticleCategories, host string) (articleCategoriesRes *res.ArticleCategoriesResponse) {
|
||||||
|
func ArticleCategoriesResponseMapper(
|
||||||
|
articleCategoriesReq *entity.ArticleCategories,
|
||||||
|
createdByFullname *string,
|
||||||
|
host string,
|
||||||
|
) (articleCategoriesRes *res.ArticleCategoriesResponse) {
|
||||||
|
|
||||||
if articleCategoriesReq != nil {
|
if articleCategoriesReq != nil {
|
||||||
articleCategoriesRes = &res.ArticleCategoriesResponse{
|
articleCategoriesRes = &res.ArticleCategoriesResponse{
|
||||||
ID: articleCategoriesReq.ID,
|
ID: articleCategoriesReq.ID,
|
||||||
Title: articleCategoriesReq.Title,
|
Title: articleCategoriesReq.Title,
|
||||||
Description: articleCategoriesReq.Description,
|
Description: articleCategoriesReq.Description,
|
||||||
Slug: articleCategoriesReq.Slug,
|
Slug: articleCategoriesReq.Slug,
|
||||||
ThumbnailPath: articleCategoriesReq.ThumbnailPath,
|
ThumbnailPath: articleCategoriesReq.ThumbnailPath,
|
||||||
ParentId: articleCategoriesReq.ParentId,
|
ParentId: articleCategoriesReq.ParentId,
|
||||||
OldCategoryId: articleCategoriesReq.OldCategoryId,
|
OldCategoryId: articleCategoriesReq.OldCategoryId,
|
||||||
CreatedById: articleCategoriesReq.CreatedById,
|
CreatedById: articleCategoriesReq.CreatedById,
|
||||||
StatusId: articleCategoriesReq.StatusId,
|
CreatedByFullname: createdByFullname,
|
||||||
IsPublish: articleCategoriesReq.IsPublish,
|
StatusId: articleCategoriesReq.StatusId,
|
||||||
PublishedAt: articleCategoriesReq.PublishedAt,
|
IsPublish: articleCategoriesReq.IsPublish,
|
||||||
IsActive: articleCategoriesReq.IsActive,
|
PublishedAt: articleCategoriesReq.PublishedAt,
|
||||||
CreatedAt: articleCategoriesReq.CreatedAt,
|
IsActive: articleCategoriesReq.IsActive,
|
||||||
UpdatedAt: articleCategoriesReq.UpdatedAt,
|
CreatedAt: articleCategoriesReq.CreatedAt,
|
||||||
|
UpdatedAt: articleCategoriesReq.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
if articleCategoriesReq.Tags != nil {
|
if articleCategoriesReq.Tags != nil {
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,16 @@ type articleCategoriesRepository struct {
|
||||||
Cfg *config.Config
|
Cfg *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ArticleCategoryWithCreator struct {
|
||||||
|
entity.ArticleCategories
|
||||||
|
CreatedByFullname *string `gorm:"column:created_by_fullname"`
|
||||||
|
}
|
||||||
|
|
||||||
// ArticleCategoriesRepository define interface of IArticleCategoriesRepository
|
// ArticleCategoriesRepository define interface of IArticleCategoriesRepository
|
||||||
type ArticleCategoriesRepository interface {
|
type ArticleCategoriesRepository interface {
|
||||||
GetAll(clientId *uuid.UUID, req request.ArticleCategoriesQueryRequest) (articleCategoriess []*entity.ArticleCategories, paging paginator.Pagination, err error)
|
GetAll(clientId *uuid.UUID, req request.ArticleCategoriesQueryRequest) (articleCategoriess []*entity.ArticleCategories, paging paginator.Pagination, err error)
|
||||||
FindOne(clientId *uuid.UUID, id uint) (articleCategories *entity.ArticleCategories, err error)
|
FindOne(clientId *uuid.UUID, id uint) (articleCategories *entity.ArticleCategories, err error)
|
||||||
|
FindOneWithCreator(clientId *uuid.UUID, id uint) (*ArticleCategoryWithCreator, error)
|
||||||
FindOneByOldId(clientId *uuid.UUID, id uint) (articleCategories *entity.ArticleCategories, err error)
|
FindOneByOldId(clientId *uuid.UUID, id uint) (articleCategories *entity.ArticleCategories, err error)
|
||||||
FindOneBySlug(clientId *uuid.UUID, slug string) (articleCategories *entity.ArticleCategories, err error)
|
FindOneBySlug(clientId *uuid.UUID, slug string) (articleCategories *entity.ArticleCategories, err error)
|
||||||
Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error)
|
Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error)
|
||||||
|
|
@ -174,3 +180,29 @@ func (_i *articleCategoriesRepository) Delete(clientId *uuid.UUID, id uint) erro
|
||||||
}
|
}
|
||||||
return query.Delete(&entity.ArticleCategories{}).Error
|
return query.Delete(&entity.ArticleCategories{}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *articleCategoriesRepository) FindOneWithCreator(
|
||||||
|
clientId *uuid.UUID,
|
||||||
|
id uint,
|
||||||
|
) (*ArticleCategoryWithCreator, error) {
|
||||||
|
|
||||||
|
var result ArticleCategoryWithCreator
|
||||||
|
|
||||||
|
query := _i.DB.DB.Table("article_categories ac").
|
||||||
|
Select(`
|
||||||
|
ac.*,
|
||||||
|
u.fullname AS created_by_fullname
|
||||||
|
`).
|
||||||
|
Joins("LEFT JOIN users u ON u.id = ac.created_by_id").
|
||||||
|
Where("ac.id = ?", id)
|
||||||
|
|
||||||
|
if clientId != nil {
|
||||||
|
query = query.Where("ac.client_id = ?", clientId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := query.Scan(&result).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,22 @@ package response
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type ArticleCategoriesResponse struct {
|
type ArticleCategoriesResponse struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
ThumbnailUrl string `json:"thumbnailUrl"`
|
ThumbnailUrl string `json:"thumbnailUrl"`
|
||||||
Slug *string `json:"slug"`
|
Slug *string `json:"slug"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
ThumbnailPath *string `json:"thumbnailPath"`
|
ThumbnailPath *string `json:"thumbnailPath"`
|
||||||
ParentId *int `json:"parentId"`
|
ParentId *int `json:"parentId"`
|
||||||
OldCategoryId *uint `json:"oldCategoryId"`
|
OldCategoryId *uint `json:"oldCategoryId"`
|
||||||
CreatedById *uint `json:"createdById"`
|
CreatedById *uint `json:"createdById"`
|
||||||
StatusId int `json:"statusId"`
|
CreatedByFullname *string `json:"createdByFullname"`
|
||||||
IsPublish *bool `json:"isPublish"`
|
StatusId int `json:"statusId"`
|
||||||
PublishedAt *time.Time `json:"publishedAt"`
|
IsPublish *bool `json:"isPublish"`
|
||||||
IsEnabled *bool `json:"isEnabled"`
|
PublishedAt *time.Time `json:"publishedAt"`
|
||||||
IsActive *bool `json:"isActive"`
|
IsEnabled *bool `json:"isEnabled"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
IsActive *bool `json:"isActive"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,9 +87,16 @@ func (_i *articleCategoriesService) All(authToken string, req request.ArticleCat
|
||||||
|
|
||||||
host := _i.Cfg.App.Domain
|
host := _i.Cfg.App.Domain
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
articleCategoriess = append(articleCategoriess, mapper.ArticleCategoriesResponseMapper(result, host))
|
articleCategoriess = append(
|
||||||
|
articleCategoriess,
|
||||||
|
mapper.ArticleCategoriesResponseMapper(result, nil, host),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for _, result := range results {
|
||||||
|
// articleCategoriess = append(articleCategoriess, mapper.ArticleCategoriesResponseMapper(result, host))
|
||||||
|
// }
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,12 +111,25 @@ func (_i *articleCategoriesService) Show(authToken string, id uint) (articleCate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := _i.Repo.FindOne(clientId, id)
|
result, err := _i.Repo.FindOneWithCreator(clientId, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
host := _i.Cfg.App.Domain
|
host := _i.Cfg.App.Domain
|
||||||
return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
|
||||||
|
return mapper.ArticleCategoriesResponseMapper(
|
||||||
|
&result.ArticleCategories,
|
||||||
|
result.CreatedByFullname,
|
||||||
|
host,
|
||||||
|
), nil
|
||||||
|
|
||||||
|
// result, err := _i.Repo.FindOne(clientId, id)
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// host := _i.Cfg.App.Domain
|
||||||
|
// return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *articleCategoriesService) ShowByOldId(authToken string, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) {
|
func (_i *articleCategoriesService) ShowByOldId(authToken string, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) {
|
||||||
|
|
@ -128,7 +148,8 @@ func (_i *articleCategoriesService) ShowByOldId(authToken string, id uint) (arti
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
host := _i.Cfg.App.Domain
|
host := _i.Cfg.App.Domain
|
||||||
return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
return mapper.ArticleCategoriesResponseMapper(result, nil, host), nil
|
||||||
|
// return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *articleCategoriesService) ShowBySlug(authToken string, slug string) (articleCategories *response.ArticleCategoriesResponse, err error) {
|
func (_i *articleCategoriesService) ShowBySlug(authToken string, slug string) (articleCategories *response.ArticleCategoriesResponse, err error) {
|
||||||
|
|
@ -147,7 +168,8 @@ func (_i *articleCategoriesService) ShowBySlug(authToken string, slug string) (a
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
host := _i.Cfg.App.Domain
|
host := _i.Cfg.App.Domain
|
||||||
return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
return mapper.ArticleCategoriesResponseMapper(result, nil, host), nil
|
||||||
|
// return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *articleCategoriesService) Save(authToken string, req request.ArticleCategoriesCreateRequest) (articleCategories *entity.ArticleCategories, err error) {
|
func (_i *articleCategoriesService) Save(authToken string, req request.ArticleCategoriesCreateRequest) (articleCategories *entity.ArticleCategories, err error) {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ func ArticlesResponseMapper(
|
||||||
if len(articleCategories) > 0 {
|
if len(articleCategories) > 0 {
|
||||||
for _, result := range articleCategories {
|
for _, result := range articleCategories {
|
||||||
if result.Category != nil {
|
if result.Category != nil {
|
||||||
articleCategoriesArr = append(articleCategoriesArr, articleCategoriesMapper.ArticleCategoriesResponseMapper(result.Category, host))
|
articleCategoriesArr = append(articleCategoriesArr, articleCategoriesMapper.ArticleCategoriesResponseMapper(result.Category, nil, host))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info().Interface("articleCategoriesArr", articleCategoriesArr).Msg("")
|
log.Info().Interface("articleCategoriesArr", articleCategoriesArr).Msg("")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue