107 lines
3.2 KiB
Go
107 lines
3.2 KiB
Go
package division
|
|
|
|
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"
|
|
erc "simrs-vx/internal/domain/references/common"
|
|
erg "simrs-vx/internal/domain/references/organization"
|
|
)
|
|
|
|
type CreateDto struct {
|
|
Code string `json:"code" validate:"maxLength=10"`
|
|
Name string `json:"name" validate:"maxLength=50"`
|
|
Parent_Id *uint16 `json:"parent_id"`
|
|
}
|
|
|
|
type ReadListDto struct {
|
|
FilterDto
|
|
Includes string `json:"includes"`
|
|
Sort string `json:"sort"`
|
|
Pagination ecore.Pagination
|
|
OnlyHaveChildren bool `json:"only-have-children"`
|
|
}
|
|
|
|
type FilterDto struct {
|
|
Code string `json:"code"`
|
|
Name string `json:"name"`
|
|
Parent_Id *uint16 `json:"parent-id"`
|
|
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
|
|
}
|
|
|
|
type ReadDetailDto struct {
|
|
Id uint16 `json:"id"`
|
|
Code *string `json:"code"`
|
|
Includes string `json:"includes"`
|
|
}
|
|
|
|
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
|
|
Code string `json:"code"`
|
|
Name string `json:"name"`
|
|
Parent_Id *uint16 `json:"parent_id"`
|
|
Parent *Division `json:"parent,omitempty"`
|
|
Childrens []Division `json:"childrens,omitempty"`
|
|
DivisionPosition []ResponseDivisionPosition `json:"divisionPositions,omitempty"`
|
|
}
|
|
|
|
type ResponseDivisionPosition struct {
|
|
ecore.SmallMain // adjust this according to the needs
|
|
Division_Id *uint16 `json:"division_id"`
|
|
Code string `json:"code"`
|
|
Name string `json:"name"`
|
|
HeadStatus bool `json:"headStatus"`
|
|
Employee_Id *uint `json:"employee_id"`
|
|
Employee ResponseDivisionEmployee `json:"employee"`
|
|
}
|
|
|
|
type ResponseDivisionEmployee struct {
|
|
ecore.Main // adjust this according to the needs
|
|
User_Id *uint `json:"user_id"`
|
|
User *eu.User `json:"user,omitempty"`
|
|
Person_Id *uint `json:"person_id"`
|
|
Person *ep.Person `json:"person,omitempty"`
|
|
Position_Code *erg.EmployeePositionCode `json:"position_code"`
|
|
Number *string `json:"number"`
|
|
Status_Code erc.ActiveStatusCode `json:"status_code"`
|
|
}
|
|
|
|
func (d Division) ToResponse(divPos []ResponseDivisionPosition) ResponseDto {
|
|
resp := ResponseDto{
|
|
Code: d.Code,
|
|
Name: d.Name,
|
|
Parent_Id: d.Parent_Id,
|
|
Parent: d.Parent,
|
|
Childrens: d.Childrens,
|
|
}
|
|
resp.SmallMain = d.SmallMain
|
|
|
|
if divPos != nil {
|
|
resp.DivisionPosition = divPos
|
|
}
|
|
return resp
|
|
}
|
|
|
|
func ToResponseList(data []Division) []ResponseDto {
|
|
resp := make([]ResponseDto, len(data))
|
|
for i, u := range data {
|
|
resp[i] = u.ToResponse(nil)
|
|
}
|
|
return resp
|
|
}
|