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,20 +3,31 @@ package mapper
import (
"go-humas-be/app/database/entity"
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 {
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,
CommentFrom: articleCommentsReq.CommentFrom,
ParentId: articleCommentsReq.ParentId,
IsPublic: articleCommentsReq.IsPublic,
IsActive: articleCommentsReq.IsActive,
CreatedAt: articleCommentsReq.CreatedAt,
UpdatedAt: articleCommentsReq.UpdatedAt,
ID: articleCommentsReq.ID,
Message: articleCommentsReq.Message,
ArticleId: articleCommentsReq.ArticleId,
CommentFromId: articleCommentsReq.CommentFrom,
CommentFromName: &commentFromName,
ParentId: articleCommentsReq.ParentId,
IsPublic: articleCommentsReq.IsPublic,
IsActive: articleCommentsReq.IsActive,
CreatedAt: articleCommentsReq.CreatedAt,
UpdatedAt: articleCommentsReq.UpdatedAt,
}
}
return articleCommentsRes

View File

@ -3,13 +3,14 @@ package response
import "time"
type ArticleCommentsResponse struct {
ID uint `json:"id"`
Message string `json:"message"`
ArticleId uint `json:"articleId"`
CommentFrom *uint `json:"commentFrom"`
ParentId *int `json:"parentId"`
IsPublic bool `json:"isPublic"`
IsActive bool `json:"isActive"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID uint `json:"id"`
Message string `json:"message"`
ArticleId uint `json:"articleId"`
CommentFromId *uint `json:"commentFromId"`
CommentFromName *string `json:"commentFromName"`
ParentId *int `json:"parentId"`
IsPublic bool `json:"isPublic"`
IsActive bool `json:"isActive"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}

View File

@ -47,7 +47,7 @@ func (_i *articleCommentsService) All(req request.ArticleCommentsQueryRequest) (
}
for _, result := range results {
articleCommentss = append(articleCommentss, mapper.ArticleCommentsResponseMapper(result))
articleCommentss = append(articleCommentss, mapper.ArticleCommentsResponseMapper(result, _i.UsersRepo))
}
return
@ -59,7 +59,7 @@ func (_i *articleCommentsService) Show(id uint) (articleComments *response.Artic
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) {