feat (patient): more detail on preloading object
This commit is contained in:
@@ -2,15 +2,16 @@ package personaddress
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
epc "simrs-vx/internal/domain/main-entities/postal-code"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Person_Id uint `json:"person_id"`
|
||||
Address string `json:"address" validate:"maxLength=150"`
|
||||
Rt string `json:"rt" validate:"maxLength=2"`
|
||||
Rw string `json:"rw" validate:"maxLength=2"`
|
||||
Village_Code string `json:"village_code" validate:"maxLength=10"`
|
||||
PostalCode string `json:"postalCode" validate:"maxLength=6"`
|
||||
Person_Id uint `json:"person_id"`
|
||||
Address string `json:"address" validate:"maxLength=150"`
|
||||
Rt string `json:"rt" validate:"maxLength=2"`
|
||||
Rw string `json:"rw" validate:"maxLength=2"`
|
||||
Village_Code string `json:"village_code" validate:"maxLength=10"`
|
||||
PostalCode_Code string `json:"postalCode_code" validate:"maxLength=6"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -39,22 +40,24 @@ type MetaDto struct {
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Person_Id uint `json:"person_id"`
|
||||
Address string `json:"address"`
|
||||
Rt string `json:"rt"`
|
||||
Rw string `json:"rw"`
|
||||
Village_Code string `json:"village_code"`
|
||||
PostalCode string `json:"postalCode"`
|
||||
Person_Id uint `json:"person_id"`
|
||||
Address string `json:"address"`
|
||||
Rt string `json:"rt"`
|
||||
Rw string `json:"rw"`
|
||||
Village_Code string `json:"village_code"`
|
||||
PostalCode_Code string `json:"postalCode_code"`
|
||||
PostalCode *epc.PostalCode `json:"postalCode,omitempty"`
|
||||
}
|
||||
|
||||
func (d PersonAddress) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Person_Id: d.Person_Id,
|
||||
Address: d.Address,
|
||||
Rt: d.Rt,
|
||||
Rw: d.Rw,
|
||||
Village_Code: d.Village_Code,
|
||||
PostalCode: d.PostalCode,
|
||||
Person_Id: d.Person_Id,
|
||||
Address: d.Address,
|
||||
Rt: d.Rt,
|
||||
Rw: d.Rw,
|
||||
Village_Code: d.Village_Code,
|
||||
PostalCode_Code: d.PostalCode_Code,
|
||||
PostalCode: d.PostalCode,
|
||||
}
|
||||
resp.Main = d.Main
|
||||
return resp
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
epa "simrs-vx/internal/domain/main-entities/person-address"
|
||||
epc "simrs-vx/internal/domain/main-entities/person-contact"
|
||||
epr "simrs-vx/internal/domain/main-entities/person-relative"
|
||||
er "simrs-vx/internal/domain/main-entities/regency"
|
||||
|
||||
erp "simrs-vx/internal/domain/references/person"
|
||||
)
|
||||
@@ -91,6 +92,7 @@ type ResponseDto struct {
|
||||
EndTitle *string `json:"endTitle"`
|
||||
BirthDate *time.Time `json:"birthDate,omitempty"`
|
||||
BirthRegency_Code *string `json:"birthRegency_code"`
|
||||
BirthRegency *er.Regency `json:"birthRegency,omitempty"`
|
||||
Gender_Code *erp.GenderCode `json:"gender_code"`
|
||||
ResidentIdentityNumber *string `json:"residentIdentityNumber"`
|
||||
PassportNumber *string `json:"passportNumber"`
|
||||
@@ -121,6 +123,7 @@ func (d *Person) ToResponse() ResponseDto {
|
||||
EndTitle: d.EndTitle,
|
||||
BirthDate: d.BirthDate,
|
||||
BirthRegency_Code: d.BirthRegency_Code,
|
||||
BirthRegency: d.BirthRegency,
|
||||
Gender_Code: d.Gender_Code,
|
||||
ResidentIdentityNumber: d.ResidentIdentityNumber,
|
||||
PassportNumber: d.PassportNumber,
|
||||
|
||||
@@ -33,9 +33,6 @@ type Person struct {
|
||||
Nationality *string `json:"nationality": gorm:"size:50"`
|
||||
Ethnic_Code *string `json:"ethnic_code" gorm:"size:20"`
|
||||
Ethnic *ee.Ethnic `json:"ethnic,omitempty" gorm:"foreignKey:Ethnic_Code;references:Code"`
|
||||
Addresses *[]epa.PersonAddress `json:"addresses" gorm:"foreignKey:Person_Id"`
|
||||
Contacts *[]epc.PersonContact `json:"contacts" gorm:"foreignKey:Person_Id"`
|
||||
Relatives *[]epr.PersonRelative `json:"relatives" gorm:"foreignKey:Person_Id"`
|
||||
Language_Code *string `json:"language_code" gorm:"size:10"`
|
||||
Language *el.Language `json:"language,omitempty" gorm:"foreignKey:Language_Code;references:Code"`
|
||||
CommunicationIssueStatus bool `json:"communicationIssueStatus"`
|
||||
@@ -44,6 +41,9 @@ type Person struct {
|
||||
PassportFileUrl *string `json:"passportFileUrl" gorm:"size:1024"`
|
||||
DrivingLicenseFileUrl *string `json:"drivingLicenseFileUrl" gorm:"size:1024"`
|
||||
FamilyIdentityFileUrl *string `json:"familyIdentityFileUrl" gorm:"size:1024"`
|
||||
Addresses *[]epa.PersonAddress `json:"addresses" gorm:"foreignKey:Person_Id"`
|
||||
Contacts *[]epc.PersonContact `json:"contacts" gorm:"foreignKey:Person_Id"`
|
||||
Relatives *[]epr.PersonRelative `json:"relatives" gorm:"foreignKey:Person_Id"`
|
||||
}
|
||||
|
||||
func (d Person) IsSameResidentIdentityNumber(input *string) bool {
|
||||
|
||||
@@ -96,9 +96,13 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
|
||||
}
|
||||
|
||||
tx = tx.Preload(clause.Associations)
|
||||
tx = tx.Preload("Person.Addresses")
|
||||
tx = tx.Preload("Person.Contacts")
|
||||
tx = tx.Preload("Person.Relatives")
|
||||
tx = tx.Preload("Person.BirthRegency.Province").
|
||||
Preload("Person.Ethnic").
|
||||
Preload("Person.Language").
|
||||
Preload("Person.Contacts").
|
||||
Preload("Person.Relatives.Village.District.Regency.Province").
|
||||
Preload("Person.Addresses").
|
||||
Preload("Person.Addresses.PostalCode.Village.District.Regency.Province")
|
||||
|
||||
if err := tx.First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
|
||||
@@ -22,5 +22,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.PersonAddress) {
|
||||
data.Rt = inputSrc.Rt
|
||||
data.Rw = inputSrc.Rw
|
||||
data.Village_Code = inputSrc.Village_Code
|
||||
data.PostalCode = inputSrc.PostalCode
|
||||
data.PostalCode_Code = inputSrc.PostalCode_Code
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user