feat (crud): add person, person-contact, person-address

This commit is contained in:
dpurbosakti
2025-08-25 14:07:14 +07:00
parent c3132fe2b7
commit 280d373576
45 changed files with 2536 additions and 49 deletions

No files matched your search

@@ -0,0 +1,68 @@
package division
import (
ecore "simrs-vx/internal/domain/base-entities/core"
)
type CreateDto struct {
Code string `json:"code"`
Name string `json:"name"`
Parent_Id *int16 `json:"parent_id"`
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
Parent_Id *int16 `json:"parent_id"`
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Parent_Id *int16 `json:"parent_id"`
}
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 *int16 `json:"parent_id"`
}
func (d Division) ToResponse() ResponseDto {
resp := ResponseDto{
Code: d.Code,
Name: d.Name,
Parent_Id: d.Parent_Id,
}
resp.SmallMain = d.SmallMain
return resp
}
func ToResponseList(users []Division) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,12 @@
package division
import (
ecore "simrs-vx/internal/domain/base-entities/core"
)
type Division struct {
ecore.SmallMain // adjust this according to the needs
Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"`
Parent_Id *int16 `json:"parent_id"`
}
@@ -0,0 +1,72 @@
package personaddress
import (
ecore "simrs-vx/internal/domain/base-entities/core"
)
type CreateDto struct {
Person_Id uint `json:"person_id"`
Address string `json:"address"`
Rt string `json:"rt"`
Rw string `json:"rw"`
Village_Code string `json:"village_code"`
}
type ReadListDto struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint `json:"id"`
Person_Id uint `json:"person_id"`
Address string `json:"address"`
Rt string `json:"rt"`
Rw string `json:"rw"`
Village_Code string `json:"village_code"`
}
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"`
Address string `json:"address"`
Rt string `json:"rt"`
Rw string `json:"rw"`
Village_Code string `json:"village_code"`
}
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,
}
resp.Main = d.Main
return resp
}
func ToResponseList(users []PersonAddress) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,14 @@
package personaddress
import (
ecore "simrs-vx/internal/domain/base-entities/core"
)
type PersonAddress struct {
ecore.Main // adjust this according to the needs
Person_Id uint `json:"person_id"`
Address string `json:"address" gorm:"size:150"`
Rt string `json:"rt" gorm:"size:2"`
Rw string `json:"rw" gorm:"size:2"`
Village_Code string `json:"village_code" gorm:"size:10"`
}
@@ -0,0 +1,65 @@
package personcontact
import (
ecore "simrs-vx/internal/domain/base-entities/core"
erp "simrs-vx/internal/domain/references/person"
)
type CreateDto struct {
Person_Id uint `json:"person_id"`
Type_Code erp.ContactTypeCode `json:"type_code"`
Value string `json:"value"`
}
type ReadListDto struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint `json:"id"`
Person_Id uint `json:"person_id"`
Type_Code erp.ContactTypeCode `json:"type_code"`
Value string `json:"value"`
}
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"`
Type_Code erp.ContactTypeCode `json:"type_code"`
Value string `json:"value"`
}
func (u *PersonContact) ToResponse() ResponseDto {
resp := ResponseDto{
Person_Id: u.Person_Id,
Type_Code: u.Type_Code,
Value: u.Value,
}
resp.Main = u.Main
return resp
}
func ToResponseList(users []PersonContact) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,13 @@
package personcontact
import (
ecore "simrs-vx/internal/domain/base-entities/core"
erp "simrs-vx/internal/domain/references/person"
)
type PersonContact struct {
ecore.Main // adjust this according to the needs
Person_Id uint `json:"person_id"`
Type_Code erp.ContactTypeCode `json:"type_code" gorm:"size:15"`
Value string `json:"value" gorm:"size:100"`
}
+100
View File
@@ -0,0 +1,100 @@
package person
import (
ecore "simrs-vx/internal/domain/base-entities/core"
epa "simrs-vx/internal/domain/main-entities/person-address"
epc "simrs-vx/internal/domain/main-entities/person-contact"
erp "simrs-vx/internal/domain/references/person"
"time"
)
type CreateDto struct {
Name string `json:"name"`
BirthDate *time.Time `json:"birthDate,omitempty"`
BirthRegency_Code *string `json:"birthRegency_code"`
Gender_Code *erp.GenderCode `json:"gender_code"`
ResidentIdentityNumber *string `json:"residentIdentityNumber"`
Religion_Code *erp.ReligionCode `json:"religion_code"`
Education_Code *erp.EducationCode `json:"education_code"`
Ocupation_Code *erp.OcupationCode `json:"occupation_code"`
Ocupation_Name *string `json:"occupation_name"`
Ethnic_Code *erp.EthnicCode `json:"ethnic_code"`
}
type ReadListDto struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint `json:"id"`
Name string `json:"name"`
BirthDate *time.Time `json:"birthDate,omitempty"`
BirthRegency_Code *string `json:"birthRegency_code"`
Gender_Code *erp.GenderCode `json:"gender_code"`
ResidentIdentityNumber *string `json:"residentIdentityNumber"`
Religion_Code *erp.ReligionCode `json:"religion_code"`
Education_Code *erp.EducationCode `json:"education_code"`
Ocupation_Code *erp.OcupationCode `json:"occupation_code"`
Ocupation_Name *string `json:"occupation_name"`
Ethnic_Code *erp.EthnicCode `json:"ethnic_code"`
}
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
Name string `json:"name"`
BirthDate *time.Time `json:"birthDate,omitempty"`
BirthRegency_Code *string `json:"birthRegency_code"`
Gender_Code *erp.GenderCode `json:"gender_code"`
ResidentIdentityNumber *string `json:"residentIdentityNumber"`
Religion_Code *erp.ReligionCode `json:"religion_code"`
Education_Code *erp.EducationCode `json:"education_code"`
Ocupation_Code *erp.OcupationCode `json:"occupation_code"`
Ocupation_Name *string `json:"occupation_name"`
Ethnic_Code *erp.EthnicCode `json:"ethnic_code"`
Addresses *[]epa.PersonAddress `json:"addresses,omitempty"`
Contacts *[]epc.PersonContact `json:"contacts,omitempty"`
}
func (u *Person) ToResponse() ResponseDto {
resp := ResponseDto{
Name: u.Name,
BirthDate: u.BirthDate,
BirthRegency_Code: u.BirthRegency_Code,
Gender_Code: u.Gender_Code,
ResidentIdentityNumber: u.ResidentIdentityNumber,
Religion_Code: u.Religion_Code,
Education_Code: u.Education_Code,
Ocupation_Code: u.Ocupation_Code,
Ocupation_Name: u.Ocupation_Name,
Ethnic_Code: u.Ethnic_Code,
Addresses: u.Addresses,
Contacts: u.Contacts,
}
resp.Main = u.Main
return resp
}
func ToResponseList(users []Person) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,26 @@
package person
import (
ecore "simrs-vx/internal/domain/base-entities/core"
epa "simrs-vx/internal/domain/main-entities/person-address"
epc "simrs-vx/internal/domain/main-entities/person-contact"
erp "simrs-vx/internal/domain/references/person"
"time"
)
type Person struct {
ecore.Main // adjust this according to the needs
Name string `json:"name" gorm:"not null;size:150"`
BirthDate *time.Time `json:"birthDate,omitempty"`
BirthRegency_Code *string `json:"birthRegency_code" gorm:"size:4"`
Gender_Code *erp.GenderCode `json:"gender_code" gorm:"size:10"`
ResidentIdentityNumber *string `json:"residentIdentityNumber" gorm:"size:16"`
Religion_Code *erp.ReligionCode `json:"religion_code" gorm:"size:10"`
Education_Code *erp.EducationCode `json:"education_code" gorm:"size:10"`
Ocupation_Code *erp.OcupationCode `json:"occupation_code" gorm:"size:15"`
Ocupation_Name *string `json:"occupation_name" gorm:"size:50"`
Ethnic_Code *erp.EthnicCode `json:"ethnic_code" gorm:"size:15"`
Addresses *[]epa.PersonAddress `json:"addresses" gorm:"foreignKey:Person_Id"`
Contacts *[]epc.PersonContact `json:"contacts" gorm:"foreignKey:Person_Id"`
}