Files
simrsx-be/internal/domain/main-entities/unit/dto.go
T
2025-08-20 13:53:14 +07:00

74 lines
1.6 KiB
Go

package unit
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ei "simrs-vx/internal/domain/main-entities/installation"
)
type CreateDto struct {
Installation_Id *uint16 `json:"installation_id"`
Code string `json:"code"`
Name string `json:"name"`
}
type ReadListDto struct {
Installation_Id *uint16 `json:"installation_id"`
Code string `json:"code"`
Name string `json:"name"`
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Installation_Id *uint16 `json:"installation_id"`
Id uint16 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
}
type UpdateDto struct {
Id uint16 `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint16 `json:"id"`
}
type MetaDto struct {
PageNumber int `json:"page_number"`
PageSize int `json:"page_size"`
Count int `json:"count"`
}
type ResponseDto struct {
ecore.SmallMain
Installation_Id *uint16 `json:"installation_id"`
Installation *ei.Installation
Code string `json:"code"`
Name string `json:"name"`
}
func (u Unit) ToResponse() ResponseDto {
resp := ResponseDto{
Installation_Id: u.Installation_Id,
Code: u.Code,
Name: u.Name,
}
resp.SmallMain = u.SmallMain
if u.Installation != nil {
resp.Installation = u.Installation
}
return resp
}
func ToResponseList(users []Unit) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}