2025-09-28 01:53:09 +00:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-30 13:34:56 +00:00
|
|
|
"netidhub-saas-be/app/database/entity"
|
|
|
|
|
articleCategoriesMapper "netidhub-saas-be/app/module/article_categories/mapper"
|
|
|
|
|
articleCategoriesRepository "netidhub-saas-be/app/module/article_categories/repository"
|
|
|
|
|
articleCategoriesResponse "netidhub-saas-be/app/module/article_categories/response"
|
|
|
|
|
articleCategoryDetailsRepository "netidhub-saas-be/app/module/article_category_details/repository"
|
|
|
|
|
articleFilesMapper "netidhub-saas-be/app/module/article_files/mapper"
|
|
|
|
|
articleFilesRepository "netidhub-saas-be/app/module/article_files/repository"
|
|
|
|
|
articleFilesResponse "netidhub-saas-be/app/module/article_files/response"
|
|
|
|
|
res "netidhub-saas-be/app/module/articles/response"
|
2025-10-12 05:02:55 +00:00
|
|
|
clientsRepository "netidhub-saas-be/app/module/clients/repository"
|
2025-09-30 13:34:56 +00:00
|
|
|
usersRepository "netidhub-saas-be/app/module/users/repository"
|
2025-10-12 05:02:55 +00:00
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/rs/zerolog"
|
2025-09-28 01:53:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ArticlesResponseMapper(
|
|
|
|
|
log zerolog.Logger,
|
|
|
|
|
host string,
|
|
|
|
|
clientId *uuid.UUID,
|
|
|
|
|
articlesReq *entity.Articles,
|
|
|
|
|
articleCategoriesRepo articleCategoriesRepository.ArticleCategoriesRepository,
|
|
|
|
|
articleCategoryDetailsRepo articleCategoryDetailsRepository.ArticleCategoryDetailsRepository,
|
|
|
|
|
articleFilesRepo articleFilesRepository.ArticleFilesRepository,
|
|
|
|
|
usersRepo usersRepository.UsersRepository,
|
2025-10-12 05:02:55 +00:00
|
|
|
clientsRepo clientsRepository.ClientsRepository,
|
2025-09-28 01:53:09 +00:00
|
|
|
) (articlesRes *res.ArticlesResponse) {
|
|
|
|
|
|
2025-10-12 05:02:55 +00:00
|
|
|
if articlesReq == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 01:53:09 +00:00
|
|
|
createdByName := ""
|
|
|
|
|
if articlesReq.CreatedById != nil {
|
|
|
|
|
findUser, _ := usersRepo.FindOne(clientId, *articlesReq.CreatedById)
|
|
|
|
|
if findUser != nil {
|
|
|
|
|
createdByName = findUser.Fullname
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 05:02:55 +00:00
|
|
|
clientName := ""
|
|
|
|
|
if articlesReq.ClientId != nil {
|
|
|
|
|
findClient, _ := clientsRepo.FindOneByClientId(articlesReq.ClientId)
|
|
|
|
|
if findClient != nil {
|
|
|
|
|
clientName = findClient.Name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 01:53:09 +00:00
|
|
|
articleCategories, _ := articleCategoryDetailsRepo.FindByArticleId(articlesReq.ID)
|
|
|
|
|
var articleCategoriesArr []*articleCategoriesResponse.ArticleCategoriesResponse
|
2025-10-12 05:52:06 +00:00
|
|
|
categoryName := ""
|
2025-10-12 05:02:55 +00:00
|
|
|
if len(articleCategories) > 0 {
|
2025-09-28 01:53:09 +00:00
|
|
|
for _, result := range articleCategories {
|
2025-10-12 05:02:55 +00:00
|
|
|
if result.Category != nil {
|
|
|
|
|
articleCategoriesArr = append(articleCategoriesArr, articleCategoriesMapper.ArticleCategoriesResponseMapper(result.Category, host))
|
|
|
|
|
}
|
2025-09-28 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
log.Info().Interface("articleCategoriesArr", articleCategoriesArr).Msg("")
|
2025-10-12 05:52:06 +00:00
|
|
|
|
|
|
|
|
// Ambil categoryName dari array pertama
|
|
|
|
|
if len(articleCategoriesArr) > 0 {
|
|
|
|
|
categoryName = articleCategoriesArr[0].Title
|
|
|
|
|
}
|
2025-09-28 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
articleFiles, _ := articleFilesRepo.FindByArticle(clientId, articlesReq.ID)
|
|
|
|
|
var articleFilesArr []*articleFilesResponse.ArticleFilesResponse
|
2025-10-12 05:02:55 +00:00
|
|
|
if len(articleFiles) > 0 {
|
2025-09-28 01:53:09 +00:00
|
|
|
for _, result := range articleFiles {
|
|
|
|
|
articleFilesArr = append(articleFilesArr, articleFilesMapper.ArticleFilesResponseMapper(result, host))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 05:02:55 +00:00
|
|
|
articlesRes = &res.ArticlesResponse{
|
|
|
|
|
ID: articlesReq.ID,
|
|
|
|
|
Title: articlesReq.Title,
|
|
|
|
|
Slug: articlesReq.Slug,
|
|
|
|
|
Description: articlesReq.Description,
|
|
|
|
|
HtmlDescription: articlesReq.HtmlDescription,
|
|
|
|
|
TypeId: articlesReq.TypeId,
|
|
|
|
|
Tags: articlesReq.Tags,
|
|
|
|
|
CategoryId: articlesReq.CategoryId,
|
|
|
|
|
AiArticleId: articlesReq.AiArticleId,
|
|
|
|
|
CategoryName: categoryName,
|
|
|
|
|
PageUrl: articlesReq.PageUrl,
|
|
|
|
|
CreatedById: articlesReq.CreatedById,
|
|
|
|
|
CreatedByName: &createdByName,
|
|
|
|
|
ClientName: &clientName,
|
|
|
|
|
ShareCount: articlesReq.ShareCount,
|
|
|
|
|
ViewCount: articlesReq.ViewCount,
|
|
|
|
|
CommentCount: articlesReq.CommentCount,
|
|
|
|
|
OldId: articlesReq.OldId,
|
|
|
|
|
StatusId: articlesReq.StatusId,
|
|
|
|
|
IsBanner: articlesReq.IsBanner,
|
|
|
|
|
IsPublish: articlesReq.IsPublish,
|
|
|
|
|
PublishedAt: articlesReq.PublishedAt,
|
|
|
|
|
IsActive: articlesReq.IsActive,
|
|
|
|
|
CreatedAt: articlesReq.CreatedAt,
|
|
|
|
|
UpdatedAt: articlesReq.UpdatedAt,
|
|
|
|
|
ArticleFiles: articleFilesArr,
|
|
|
|
|
ArticleCategories: articleCategoriesArr,
|
|
|
|
|
}
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-12 05:02:55 +00:00
|
|
|
if articlesReq.ThumbnailName != nil {
|
|
|
|
|
articlesRes.ThumbnailUrl = host + "/articles/thumbnail/viewer/" + *articlesReq.ThumbnailName
|
2025-09-28 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return articlesRes
|
|
|
|
|
}
|