feat: update article comments response

This commit is contained in:
hanif salafi 2025-01-31 18:34:25 +07:00
parent 17d19d6be4
commit 5869c11b24
3 changed files with 33 additions and 21 deletions

View File

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

View File

@ -6,7 +6,8 @@ type ArticleCommentsResponse struct {
ID uint `json:"id"` ID uint `json:"id"`
Message string `json:"message"` Message string `json:"message"`
ArticleId uint `json:"articleId"` ArticleId uint `json:"articleId"`
CommentFrom *uint `json:"commentFrom"` CommentFromId *uint `json:"commentFromId"`
CommentFromName *string `json:"commentFromName"`
ParentId *int `json:"parentId"` ParentId *int `json:"parentId"`
IsPublic bool `json:"isPublic"` IsPublic bool `json:"isPublic"`
IsActive bool `json:"isActive"` IsActive bool `json:"isActive"`

View File

@ -47,7 +47,7 @@ func (_i *articleCommentsService) All(req request.ArticleCommentsQueryRequest) (
} }
for _, result := range results { for _, result := range results {
articleCommentss = append(articleCommentss, mapper.ArticleCommentsResponseMapper(result)) articleCommentss = append(articleCommentss, mapper.ArticleCommentsResponseMapper(result, _i.UsersRepo))
} }
return return
@ -59,7 +59,7 @@ func (_i *articleCommentsService) Show(id uint) (articleComments *response.Artic
return nil, err return nil, err
} }
return mapper.ArticleCommentsResponseMapper(result), nil return mapper.ArticleCommentsResponseMapper(result, _i.UsersRepo), nil
} }
func (_i *articleCommentsService) Save(req request.ArticleCommentsCreateRequest, authToken string) (articleComments *entity.ArticleComments, err error) { func (_i *articleCommentsService) Save(req request.ArticleCommentsCreateRequest, authToken string) (articleComments *entity.ArticleComments, err error) {