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
@@ -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"`
}
+50 -26
View File
@@ -6,17 +6,19 @@ type (
MaritalStatusCode string
ReligionCode string
EducationCode string
ProfessionCode string
OcupationCode string
AgeGroupCode string
AgeGroupForMedicineCode string
RelativeCode string
ContactTypeCode string
EthnicCode string
)
const (
GCMale GenderCode = "male"
GCFemale GenderCode = "female"
GCOther GenderCode = "other"
GCUnknown GenderCode = "unknown"
GCMale GenderCode = "male"
GCFemale GenderCode = "female"
GCNotStated GenderCode = "not-stated"
GCUnknown GenderCode = "unknown"
)
const (
@@ -44,7 +46,6 @@ const (
RCHindu ReligionCode = "hindu"
RCBudha ReligionCode = "budha"
RCKonghucu ReligionCode = "konghucu"
RCPenghayat ReligionCode = "penghayat"
)
const (
@@ -63,12 +64,14 @@ const (
)
const (
PCTidakBekerja ProfessionCode = "-"
PCPns ProfessionCode = "pns"
PCTniPolri ProfessionCode = "tni-polri"
PCBumn ProfessionCode = "bumn"
PCWiraswasta ProfessionCode = "wiraswasta"
PCLainlain ProfessionCode = "lainnya"
OCTidakBekerja OcupationCode = "tidak-bekerja"
OCPns OcupationCode = "pns"
OCTniPolisi OcupationCode = "polisi"
OCTni OcupationCode = "tni"
OCGuru OcupationCode = "guru"
OCWiraswasta OcupationCode = "wiraswasta"
OCKarySwasta OcupationCode = "kary-swasta"
OCLainlain OcupationCode = "lainnya"
)
const (
@@ -107,12 +110,19 @@ const (
RCMPamanNenek RelativeCode = "nenek"
)
const (
CTPhone ContactTypeCode = "phone"
CTMPhone ContactTypeCode = "m-phone"
CTEmail ContactTypeCode = "email"
CTFax ContactTypeCode = "fax"
)
func GetGenderCodes() map[GenderCode]string {
return map[GenderCode]string{
GCMale: "Laki-laki",
GCFemale: "Perempuan",
GCOther: "Lainnya",
GCUnknown: "Tidak diketahui",
GCMale: "Laki-laki",
GCFemale: "Perempuan",
GCNotStated: "Tidak disebutkan",
GCUnknown: "Tidak diketahui",
}
}
@@ -146,7 +156,6 @@ func GetReligionCodes() map[ReligionCode]string {
RCHindu: "Hindu",
RCBudha: "Budha",
RCKonghucu: "Konghucu",
RCPenghayat: "Penghayat",
}
}
@@ -167,14 +176,16 @@ func GetEducationCodes() map[EducationCode]string {
}
}
func GetProfessions() map[ProfessionCode]string {
return map[ProfessionCode]string{
PCTidakBekerja: "Tidak Bekerja",
PCPns: "PNS",
PCTniPolri: "TNI/POLRI",
PCBumn: "BUMN",
PCWiraswasta: "Pegawai Swasta / Wirausaha",
PCLainlain: "Lain-lain",
func GetProfessions() map[OcupationCode]string {
return map[OcupationCode]string{
OCTidakBekerja: "Tidak Bekerja",
OCPns: "PNS",
OCTniPolisi: "Polisi",
OCTni: "TNI",
OCGuru: "Guru",
OCWiraswasta: "Wiraswasta",
OCKarySwasta: "Kary Swasta",
OCLainlain: "Lain-lain",
}
}
@@ -220,6 +231,15 @@ func GetRelativeCodes() map[RelativeCode]string {
}
}
func GetContactTypeCodes() map[ContactTypeCode]string {
return map[ContactTypeCode]string{
CTPhone: "Telepon",
CTMPhone: "Telepon Seluler",
CTEmail: "Email",
CTFax: "Fax",
}
}
func (obj GenderCode) String() string {
return GetGenderCodes()[obj]
}
@@ -239,7 +259,7 @@ func (obj EducationCode) String() string {
return GetEducationCodes()[obj]
}
func (obj ProfessionCode) String() string {
func (obj OcupationCode) String() string {
return GetProfessions()[obj]
}
@@ -250,3 +270,7 @@ func (obj AgeGroupCode) String() string {
func (obj RelativeCode) String() string {
return GetRelativeCodes()[obj]
}
func (obj ContactTypeCode) String() string {
return GetContactTypeCodes()[obj]
}