medol-be/app/module/ppid_datas/mapper/ppid_datas.mapper.go

48 lines
1.6 KiB
Go

package mapper
import (
"github.com/rs/zerolog"
"go-humas-be/app/database/entity"
ppidDataCategoriesRepository "go-humas-be/app/module/ppid_data_categories/repository"
res "go-humas-be/app/module/ppid_datas/response"
usersRepository "go-humas-be/app/module/users/repository"
"time"
)
func PpidDatasResponseMapper(log zerolog.Logger, ppidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository, usersRepo usersRepository.UsersRepository, ppidDatasReq *entity.PpidDatas) (ppidDatasRes *res.PpidDatasResponse) {
if ppidDatasReq != nil {
findCategory, _ := ppidDataCategoriesRepo.FindOne(ppidDatasReq.CategoryId)
categoryName := ""
if findCategory != nil {
categoryName = findCategory.Title
}
findUser, _ := usersRepo.FindOne(*ppidDatasReq.CreatedById)
createdByName := ""
if findUser != nil {
createdByName = findUser.Fullname
}
log.Info().Str("timestamp", time.Now().
Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "UserInfo:PpidData").
Interface("payload", findCategory).Msg("")
ppidDatasRes = &res.PpidDatasResponse{
ID: ppidDatasReq.ID,
Title: ppidDatasReq.Title,
Description: ppidDatasReq.Description,
CategoryId: ppidDatasReq.CategoryId,
CategoryName: &categoryName,
CreatedById: ppidDatasReq.CreatedById,
CreatedByName: &createdByName,
StatusId: ppidDatasReq.StatusId,
IsPublish: ppidDatasReq.IsPublish,
PublishedAt: ppidDatasReq.PublishedAt,
IsActive: ppidDatasReq.IsActive,
CreatedAt: ppidDatasReq.CreatedAt,
UpdatedAt: ppidDatasReq.UpdatedAt,
}
}
return ppidDatasRes
}