narasiahli-be/app/module/article_comments/mapper/article_comments.mapper.go

37 lines
1.2 KiB
Go

package mapper
import (
"narasi-ahli-be/app/database/entity"
res "narasi-ahli-be/app/module/article_comments/response"
usersRepository "narasi-ahli-be/app/module/users/repository"
)
func ArticleCommentsResponseMapper(articleCommentsReq *entity.ArticleComments, usersRepo usersRepository.UsersRepository) (articleCommentsRes *res.ArticleCommentsResponse) {
if articleCommentsReq != nil {
commentFromName := ""
if articleCommentsReq.CommentFrom != nil {
findUser, _ := usersRepo.FindOne(*articleCommentsReq.CommentFrom)
if findUser != nil {
commentFromName = findUser.Fullname
}
}
articleCommentsRes = &res.ArticleCommentsResponse{
ID: articleCommentsReq.ID,
Message: articleCommentsReq.Message,
ArticleId: articleCommentsReq.ArticleId,
CommentFromId: articleCommentsReq.CommentFrom,
CommentFromName: &commentFromName,
ParentId: articleCommentsReq.ParentId,
IsPublic: articleCommentsReq.IsPublic,
StatusId: articleCommentsReq.StatusId,
IsActive: articleCommentsReq.IsActive,
CreatedAt: articleCommentsReq.CreatedAt,
UpdatedAt: articleCommentsReq.UpdatedAt,
}
}
return articleCommentsRes
}