feat/BE/US-74/pengajuan-flock

This commit is contained in:
ragilap
2025-10-16 10:06:18 +07:00
parent 7392d8a679
commit 6c7ab8a0f8
37 changed files with 2038 additions and 99 deletions
@@ -0,0 +1,64 @@
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 FlockBaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
}
type FlockListDTO struct {
FlockBaseDTO
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type FlockDetailDTO struct {
FlockListDTO
}
// === Mapper Functions ===
func ToFlockBaseDTO(e entity.Flock) FlockBaseDTO {
return FlockBaseDTO{
Id: e.Id,
Name: e.Name,
}
}
func ToFlockListDTO(e entity.Flock) FlockListDTO {
var createdUser *userDTO.UserBaseDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
createdUser = &mapped
}
return FlockListDTO{
FlockBaseDTO: ToFlockBaseDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
}
}
func ToFlockListDTOs(e []entity.Flock) []FlockListDTO {
result := make([]FlockListDTO, len(e))
for i, r := range e {
result[i] = ToFlockListDTO(r)
}
return result
}
func ToFlockDetailDTO(e entity.Flock) FlockDetailDTO {
return FlockDetailDTO{
FlockListDTO: ToFlockListDTO(e),
}
}