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), } }