Files
simrsx-be/internal/domain/main-entities/person-relative/dto.go
T
2025-10-06 11:08:43 +07:00

108 lines
3.8 KiB
Go

package personrelative
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ev "simrs-vx/internal/domain/main-entities/village"
erp "simrs-vx/internal/domain/references/person"
)
type CreateDto struct {
Person_Id uint `json:"person_id"`
Relationship_Code erp.RelationshipCode `json:"relationship_code" validate:"maxLength=100"`
Name *string `json:"name" validate:"maxLength=100"`
Address *string `json:"address" validate:"maxLength=100"`
Village_Code *string `json:"village_code" validate:"maxLength=10"`
Gender_Code *erp.GenderCode `json:"gender_code" validate:"maxLength=10"`
PhoneNumber *string `json:"phoneNumber" validate:"maxLength=30"`
Education_Code *erp.EducationCode `json:"education_code" validate:"maxLength=10"`
Occupation_Code *erp.OcupationCode `json:"occupation_code" validate:"maxLength=10"`
Occupation_Name *string `json:"occupation_name" validate:"maxLength=50"`
Responsible bool `json:"responsible"`
}
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Pagination ecore.Pagination
}
type FilterDto struct {
Person_Id uint `json:"person-id"`
Relationship_Code erp.RelationshipCode `json:"relationship-code" `
Name *string `json:"name"`
Address *string `json:"address"`
Village_Code *string `json:"village-code"`
Gender_Code *erp.GenderCode `json:"gender-code"`
PhoneNumber *string `json:"phoneNumber"`
Education_Code *erp.EducationCode `json:"education-code"`
Occupation_Code *erp.OcupationCode `json:"occupation-code"`
Occupation_Name *string `json:"occupation-name"`
Responsible bool `json:"responsible"`
}
type ReadDetailDto struct {
Id uint `json:"id"`
Person_Id uint `json:"person_id"`
Name *string `json:"name"`
PhoneNumber *string `json:"phoneNumber"`
}
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
Person_Id uint `json:"person_id"`
Relationship_Code erp.RelationshipCode `json:"relationship_code"`
Name *string `json:"name"`
Address *string `json:"address"`
Village_Code *string `json:"village_code"`
Village *ev.Village `json:"village,omitempty"`
Gender_Code *erp.GenderCode `json:"gender_code"`
PhoneNumber *string `json:"phoneNumber"`
Education_Code *erp.EducationCode `json:"education_code"`
Occupation_Code *erp.OcupationCode `json:"occupation_code"`
Occupation_Name *string `json:"occupation_name"`
Responsible bool `json:"responsible"`
}
func (d *PersonRelative) ToResponse() ResponseDto {
resp := ResponseDto{
Person_Id: d.Person_Id,
Relationship_Code: d.Relationship_Code,
Name: d.Name,
Address: d.Address,
Village_Code: d.Village_Code,
Village: d.Village,
Gender_Code: d.Gender_Code,
PhoneNumber: d.PhoneNumber,
Education_Code: d.Education_Code,
Occupation_Code: d.Occupation_Code,
Occupation_Name: d.Occupation_Name,
Responsible: d.Responsible,
}
resp.Main = d.Main
return resp
}
func ToResponseList(data []PersonRelative) []ResponseDto {
resp := make([]ResponseDto, len(data))
for i, u := range data {
resp[i] = u.ToResponse()
}
return resp
}