Files
simrsx-be/internal/domain/main-entities/employee/dto.go
T

91 lines
2.6 KiB
Go

package employee
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ep "simrs-vx/internal/domain/main-entities/person"
eu "simrs-vx/internal/domain/main-entities/user"
"time"
erc "simrs-vx/internal/domain/references/common"
erg "simrs-vx/internal/domain/references/organization"
)
type CreateDto struct {
User_Id *uint `json:"user_id"`
Person_Id *uint `json:"person_id"`
Number *string `json:"number" validate:"maxLength=20"`
Status_Code erc.ActiveStatusCode `json:"status_code" validate:"maxLength=10"`
Position_Code *erg.EmployeePositionCode `json:"position_code"`
}
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Pagination ecore.Pagination
}
type FilterDto struct {
User_Id *uint `json:"user-id"`
Person_Id *uint `json:"person-id"`
Position_Code *string `json:"position-code"`
Number *string `json:"number"`
Status_Code erc.ActiveStatusCode `json:"status-code"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
User_Id *uint `json:"user_id"`
Person_Id *uint `json:"person_id"`
Number *string `json:"number"`
}
type UpdateDto struct {
Id uint `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint `json:"id"`
}
type MetaDto struct {
PageNumber int `json:"page_number"`
PageSize int `json:"page_size"`
Count int `json:"count"`
}
type ResponseDto struct {
ecore.Main
User_Id *uint `json:"user_id"`
User *eu.User `json:"user,omitempty"`
Person_Id *uint `json:"person_id"`
Person *ep.Person `json:"person,omitempty"`
Number *string `json:"number"`
Position_Code *erg.EmployeePositionCode `json:"position_code"`
Contract_ExpiredDate *time.Time `json:"contract_expiredDate"`
Status_Code erc.ActiveStatusCode `json:"status_code"`
}
func (d Employee) ToResponse() ResponseDto {
resp := ResponseDto{
User_Id: d.User_Id,
User: d.User,
Person_Id: d.Person_Id,
Person: d.Person,
Number: d.Number,
Position_Code: d.Position_Code,
Contract_ExpiredDate: d.Contract_ExpiredDate,
Status_Code: d.Status_Code,
}
resp.Main = d.Main
return resp
}
func ToResponseList(data []Employee) []ResponseDto {
resp := make([]ResponseDto, len(data))
for i, u := range data {
resp[i] = u.ToResponse()
}
return resp
}