feat: fixing article response
This commit is contained in:
parent
bcf8c1ad71
commit
e5775814d8
|
|
@ -1,6 +1,7 @@
|
||||||
package mapper
|
package mapper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/rs/zerolog"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
articleFilesMapper "go-humas-be/app/module/article_files/mapper"
|
articleFilesMapper "go-humas-be/app/module/article_files/mapper"
|
||||||
articleFilesRepository "go-humas-be/app/module/article_files/repository"
|
articleFilesRepository "go-humas-be/app/module/article_files/repository"
|
||||||
|
|
@ -10,6 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ArticlesResponseMapper(
|
func ArticlesResponseMapper(
|
||||||
|
log zerolog.Logger,
|
||||||
articlesReq *entity.Articles,
|
articlesReq *entity.Articles,
|
||||||
articleFilesRepo articleFilesRepository.ArticleFilesRepository,
|
articleFilesRepo articleFilesRepository.ArticleFilesRepository,
|
||||||
usersRepo usersRepository.UsersRepository,
|
usersRepo usersRepository.UsersRepository,
|
||||||
|
|
@ -19,16 +21,17 @@ func ArticlesResponseMapper(
|
||||||
thumbnailUrl += *articlesReq.ThumbnailName
|
thumbnailUrl += *articlesReq.ThumbnailName
|
||||||
}
|
}
|
||||||
|
|
||||||
findUser, _ := usersRepo.FindOne(*articlesReq.CreatedById)
|
|
||||||
createdByName := ""
|
createdByName := ""
|
||||||
if findUser != nil {
|
if articlesReq.CreatedById != nil {
|
||||||
createdByName = findUser.Fullname
|
findUser, _ := usersRepo.FindOne(*articlesReq.CreatedById)
|
||||||
|
if findUser != nil {
|
||||||
|
createdByName = findUser.Fullname
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
articleFiles, _ := articleFilesRepo.FindByArticle(articlesReq.ID)
|
articleFiles, _ := articleFilesRepo.FindByArticle(articlesReq.ID)
|
||||||
|
|
||||||
var articleFilesArr []*articleFilesResponse.ArticleFilesResponse
|
var articleFilesArr []*articleFilesResponse.ArticleFilesResponse
|
||||||
if len(articleFiles) > 0 {
|
if articleFiles != nil && len(articleFiles) > 0 {
|
||||||
for _, result := range articleFiles {
|
for _, result := range articleFiles {
|
||||||
articleFilesArr = append(articleFilesArr, articleFilesMapper.ArticleFilesResponseMapper(result))
|
articleFilesArr = append(articleFilesArr, articleFilesMapper.ArticleFilesResponseMapper(result))
|
||||||
}
|
}
|
||||||
|
|
@ -56,9 +59,9 @@ func ArticlesResponseMapper(
|
||||||
IsActive: articlesReq.IsActive,
|
IsActive: articlesReq.IsActive,
|
||||||
CreatedAt: articlesReq.CreatedAt,
|
CreatedAt: articlesReq.CreatedAt,
|
||||||
UpdatedAt: articlesReq.UpdatedAt,
|
UpdatedAt: articlesReq.UpdatedAt,
|
||||||
|
ArticleFiles: articleFilesArr,
|
||||||
ArticleFiles: articleFilesArr,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return articlesRes
|
return articlesRes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ type ArticlesResponse struct {
|
||||||
PageUrl *string `json:"pageUrl"`
|
PageUrl *string `json:"pageUrl"`
|
||||||
CreatedById *uint `json:"createdById"`
|
CreatedById *uint `json:"createdById"`
|
||||||
CreatedByName *string `json:"createdByName"`
|
CreatedByName *string `json:"createdByName"`
|
||||||
ShareCount *int `json:"shareSount"`
|
ShareCount *int `json:"shareCount"`
|
||||||
ViewCount *int `json:"viewCount"`
|
ViewCount *int `json:"viewCount"`
|
||||||
DownloadCount *int `json:"downloadCount"`
|
DownloadCount *int `json:"downloadCount"`
|
||||||
StatusId *int `json:"statusId"`
|
StatusId *int `json:"statusId"`
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,8 @@ func (_i *articlesService) All(req request.ArticlesQueryRequest) (articless []*r
|
||||||
Interface("results", results).Msg("")
|
Interface("results", results).Msg("")
|
||||||
|
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
articless = append(articless, mapper.ArticlesResponseMapper(result, _i.ArticleFilesRepo, _i.UsersRepo))
|
articleRes := mapper.ArticlesResponseMapper(_i.Log, result, _i.ArticleFilesRepo, _i.UsersRepo)
|
||||||
|
articless = append(articless, articleRes)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -87,7 +88,7 @@ func (_i *articlesService) Show(id uint) (articles *response.ArticlesResponse, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapper.ArticlesResponseMapper(result, _i.ArticleFilesRepo, _i.UsersRepo), nil
|
return mapper.ArticlesResponseMapper(_i.Log, result, _i.ArticleFilesRepo, _i.UsersRepo), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error) {
|
func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue