feat: update article comments response
This commit is contained in:
parent
4897ddd713
commit
af72ce00b6
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue