2024-03-05 19:15:53 +00:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
|
|
import (
|
2024-04-29 09:46:37 +00:00
|
|
|
"github.com/rs/zerolog"
|
2024-03-05 19:15:53 +00:00
|
|
|
"go-humas-be/app/database/entity"
|
2024-04-29 09:46:37 +00:00
|
|
|
ppidDataCategoriesRepository "go-humas-be/app/module/ppid_data_categories/repository"
|
2024-03-05 19:15:53 +00:00
|
|
|
res "go-humas-be/app/module/ppid_datas/response"
|
2024-04-29 09:46:37 +00:00
|
|
|
usersRepository "go-humas-be/app/module/users/repository"
|
|
|
|
|
"time"
|
2024-03-05 19:15:53 +00:00
|
|
|
)
|
|
|
|
|
|
2024-04-29 09:46:37 +00:00
|
|
|
func PpidDatasResponseMapper(log zerolog.Logger, ppidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository, usersRepo usersRepository.UsersRepository, ppidDatasReq *entity.PpidDatas) (ppidDatasRes *res.PpidDatasResponse) {
|
2024-03-05 19:15:53 +00:00
|
|
|
if ppidDatasReq != nil {
|
2024-04-29 09:46:37 +00:00
|
|
|
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("")
|
|
|
|
|
|
2024-03-05 19:15:53 +00:00
|
|
|
ppidDatasRes = &res.PpidDatasResponse{
|
2024-04-29 09:46:37 +00:00
|
|
|
ID: ppidDatasReq.ID,
|
|
|
|
|
Title: ppidDatasReq.Title,
|
|
|
|
|
Description: ppidDatasReq.Description,
|
2024-03-05 19:15:53 +00:00
|
|
|
CategoryId: ppidDatasReq.CategoryId,
|
2024-04-29 09:46:37 +00:00
|
|
|
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,
|
2024-03-05 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ppidDatasRes
|
2024-04-29 09:46:37 +00:00
|
|
|
}
|