mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Feat(BE-36,37,38,39): finish master data management api
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type FcrBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type FcrStandardDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Weight float64 `json:"weight"`
|
||||
FcrNumber float64 `json:"fcr_number"`
|
||||
Mortality float64 `json:"mortality"`
|
||||
}
|
||||
|
||||
type FcrListDTO struct {
|
||||
FcrBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type FcrDetailDTO struct {
|
||||
FcrListDTO
|
||||
Standards []FcrStandardDTO `json:"fcr_standards"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToFcrBaseDTO(e entity.Fcr) FcrBaseDTO {
|
||||
return FcrBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToFcrListDTO(e entity.Fcr) FcrListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return FcrListDTO{
|
||||
FcrBaseDTO: ToFcrBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
func ToFcrListDTOs(e []entity.Fcr) []FcrListDTO {
|
||||
result := make([]FcrListDTO, len(e))
|
||||
for i, r := range e {
|
||||
result[i] = ToFcrListDTO(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToFcrDetailDTO(e entity.Fcr) FcrDetailDTO {
|
||||
return FcrDetailDTO{
|
||||
FcrListDTO: ToFcrListDTO(e),
|
||||
Standards: ToFcrStandardDTOs(e.Standards),
|
||||
}
|
||||
}
|
||||
|
||||
func ToFcrStandardDTOs(standards []entity.FcrStandard) []FcrStandardDTO {
|
||||
result := make([]FcrStandardDTO, len(standards))
|
||||
for i, s := range standards {
|
||||
result[i] = FcrStandardDTO{
|
||||
Id: s.Id,
|
||||
Weight: s.Weight,
|
||||
FcrNumber: s.FcrNumber,
|
||||
Mortality: s.Mortality,
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user