2024-03-05 19:15:53 +00:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
|
|
import (
|
2024-05-07 11:08:38 +00:00
|
|
|
"github.com/rs/zerolog"
|
2024-03-05 19:15:53 +00:00
|
|
|
"go-humas-be/app/database/entity"
|
2024-11-04 01:12:22 +00:00
|
|
|
articleCategoriesRepository "go-humas-be/app/module/article_categories/repository"
|
2024-05-07 07:48:46 +00:00
|
|
|
articleFilesMapper "go-humas-be/app/module/article_files/mapper"
|
|
|
|
|
articleFilesRepository "go-humas-be/app/module/article_files/repository"
|
|
|
|
|
articleFilesResponse "go-humas-be/app/module/article_files/response"
|
2024-03-05 19:15:53 +00:00
|
|
|
res "go-humas-be/app/module/articles/response"
|
2024-05-07 07:48:46 +00:00
|
|
|
usersRepository "go-humas-be/app/module/users/repository"
|
2024-03-05 19:15:53 +00:00
|
|
|
)
|
|
|
|
|
|
2024-05-07 07:48:46 +00:00
|
|
|
func ArticlesResponseMapper(
|
2024-05-07 11:08:38 +00:00
|
|
|
log zerolog.Logger,
|
2024-05-07 07:48:46 +00:00
|
|
|
articlesReq *entity.Articles,
|
2024-11-04 01:12:22 +00:00
|
|
|
articleCategoriesRepo articleCategoriesRepository.ArticleCategoriesRepository,
|
2024-05-07 07:48:46 +00:00
|
|
|
articleFilesRepo articleFilesRepository.ArticleFilesRepository,
|
|
|
|
|
usersRepo usersRepository.UsersRepository,
|
|
|
|
|
) (articlesRes *res.ArticlesResponse) {
|
2024-05-05 09:24:49 +00:00
|
|
|
thumbnailUrl := "/articles/thumbnail/viewer/"
|
|
|
|
|
if articlesReq.ThumbnailName != nil {
|
|
|
|
|
thumbnailUrl += *articlesReq.ThumbnailName
|
|
|
|
|
}
|
2024-05-07 07:48:46 +00:00
|
|
|
|
|
|
|
|
createdByName := ""
|
2024-05-07 11:08:38 +00:00
|
|
|
if articlesReq.CreatedById != nil {
|
|
|
|
|
findUser, _ := usersRepo.FindOne(*articlesReq.CreatedById)
|
|
|
|
|
if findUser != nil {
|
|
|
|
|
createdByName = findUser.Fullname
|
|
|
|
|
}
|
2024-05-07 07:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-04 01:12:22 +00:00
|
|
|
categoryName := ""
|
|
|
|
|
if articlesReq.CategoryId != 0 {
|
|
|
|
|
findCategory, _ := articleCategoriesRepo.FindOne(uint(articlesReq.CategoryId))
|
|
|
|
|
if findCategory != nil {
|
|
|
|
|
categoryName = findCategory.Title
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-07 07:48:46 +00:00
|
|
|
articleFiles, _ := articleFilesRepo.FindByArticle(articlesReq.ID)
|
|
|
|
|
var articleFilesArr []*articleFilesResponse.ArticleFilesResponse
|
2024-05-07 11:08:38 +00:00
|
|
|
if articleFiles != nil && len(articleFiles) > 0 {
|
2024-05-07 07:48:46 +00:00
|
|
|
for _, result := range articleFiles {
|
|
|
|
|
articleFilesArr = append(articleFilesArr, articleFilesMapper.ArticleFilesResponseMapper(result))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 19:15:53 +00:00
|
|
|
if articlesReq != nil {
|
|
|
|
|
articlesRes = &res.ArticlesResponse{
|
2024-05-05 09:24:49 +00:00
|
|
|
ID: articlesReq.ID,
|
|
|
|
|
Title: articlesReq.Title,
|
|
|
|
|
Slug: articlesReq.Slug,
|
|
|
|
|
Description: articlesReq.Description,
|
|
|
|
|
HtmlDescription: articlesReq.HtmlDescription,
|
|
|
|
|
TypeId: articlesReq.TypeId,
|
|
|
|
|
Tags: articlesReq.Tags,
|
|
|
|
|
ThumbnailUrl: thumbnailUrl,
|
2024-11-04 01:12:22 +00:00
|
|
|
CategoryId: articlesReq.CategoryId,
|
|
|
|
|
CategoryName: categoryName,
|
2024-05-05 09:24:49 +00:00
|
|
|
PageUrl: articlesReq.PageUrl,
|
|
|
|
|
CreatedById: articlesReq.CreatedById,
|
2024-05-07 07:48:46 +00:00
|
|
|
CreatedByName: &createdByName,
|
2024-05-05 09:24:49 +00:00
|
|
|
ShareCount: articlesReq.ShareCount,
|
|
|
|
|
ViewCount: articlesReq.ViewCount,
|
|
|
|
|
DownloadCount: articlesReq.DownloadCount,
|
|
|
|
|
StatusId: articlesReq.StatusId,
|
|
|
|
|
IsPublish: articlesReq.IsPublish,
|
|
|
|
|
PublishedAt: articlesReq.PublishedAt,
|
|
|
|
|
IsActive: articlesReq.IsActive,
|
|
|
|
|
CreatedAt: articlesReq.CreatedAt,
|
|
|
|
|
UpdatedAt: articlesReq.UpdatedAt,
|
2024-05-07 11:08:38 +00:00
|
|
|
ArticleFiles: articleFilesArr,
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-07 11:08:38 +00:00
|
|
|
|
2024-03-05 19:15:53 +00:00
|
|
|
return articlesRes
|
2024-05-05 09:24:49 +00:00
|
|
|
}
|