restructure area

This commit is contained in:
dpurbosakti
2025-10-09 12:27:56 +07:00
parent 63d2f2342c
commit 601bbd5a0a
15 changed files with 112 additions and 53 deletions
@@ -0,0 +1,8 @@
-- Modify "Regency" table
ALTER TABLE "public"."Regency" DROP CONSTRAINT "fk_Province_Regencies", ALTER COLUMN "Id" TYPE bigint, ADD CONSTRAINT "fk_Regency_Province" FOREIGN KEY ("Province_Code") REFERENCES "public"."Province" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "District" table
ALTER TABLE "public"."District" DROP CONSTRAINT "fk_Regency_Districts", ADD CONSTRAINT "fk_District_Regency" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "Village" table
ALTER TABLE "public"."Village" DROP CONSTRAINT "fk_District_Villages", ADD CONSTRAINT "fk_Village_District" FOREIGN KEY ("District_Code") REFERENCES "public"."District" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "PostalCode" table
ALTER TABLE "public"."PostalCode" DROP CONSTRAINT "fk_Village_PostalCodes", ADD CONSTRAINT "fk_PostalCode_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
+2 -1
View File
@@ -1,4 +1,4 @@
h1:CAMxY9M2WLkhsnD/5ItPa0kDPKJwprjDft26U+FW3vE=
h1:TrdoKKXrICvDA283WGDf33WtWHglk1twvjDpYrNwc8o=
20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k=
20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0=
20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI=
@@ -33,3 +33,4 @@ h1:CAMxY9M2WLkhsnD/5ItPa0kDPKJwprjDft26U+FW3vE=
20251008052346.sql h1:nxnXmooIJ6r1mmzwnw+6efxLfc/k9h2aE6RMptPRons=
20251008073620.sql h1:6YsJp1W4SmQJ1lxpqF27BBlDC1zqhw7Yhc7pLzQTY6M=
20251009042854.sql h1:vK7bDqUDTxjHMSh1wrQiKITeqbB/7aqkWaPut8nGA68=
20251009052657.sql h1:I0rBPBg1o6zuRaxqWqCh82rI+NN7Gr6C//8ItUaLmtY=
@@ -0,0 +1,8 @@
package base
type Basic struct {
Id uint32 `json:"id" gorm:"primaryKey"`
Regency_Code string `json:"regency_code" gorm:"size:4"`
Code string `json:"code" gorm:"unique;size:6"` // NOTE: THE PROPER SIZE IS 6
Name string `json:"name" gorm:"size:50"`
}
@@ -2,7 +2,9 @@ package district
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ev "simrs-vx/internal/domain/main-entities/village"
edb "simrs-vx/internal/domain/main-entities/district/base"
er "simrs-vx/internal/domain/main-entities/regency"
evb "simrs-vx/internal/domain/main-entities/village/base"
)
type CreateDto struct {
@@ -39,11 +41,9 @@ type MetaDto struct {
}
type ResponseDto struct {
Id uint32 `json:"id"`
Regency_Code string `json:"regency_code"`
Code string `json:"code"`
Name string `json:"name"`
Villages []*ev.Village `json:"villages,omitempty"`
edb.Basic
Regency *er.Regency `json:"regency,omitempty"`
Villages []*evb.Basic `json:"villages,omitempty"`
}
func (d District) ToResponse() ResponseDto {
@@ -1,11 +1,13 @@
package district
import ev "simrs-vx/internal/domain/main-entities/village"
import (
edb "simrs-vx/internal/domain/main-entities/district/base"
er "simrs-vx/internal/domain/main-entities/regency"
evb "simrs-vx/internal/domain/main-entities/village/base"
)
type District struct {
Id uint32 `json:"id" gorm:"primaryKey"`
Regency_Code string `json:"regency_code" gorm:"size:4"`
Code string `json:"code" gorm:"unique;size:6"` // NOTE: THE PROPER SIZE IS 6
Name string `json:"name" gorm:"size:50"`
Villages []*ev.Village `json:"villages,omitempty" gorm:"foreignKey:District_Code;references:Code"`
edb.Basic
Regency *er.Regency `json:"regency,omitempty" gorm:"foreignKey:Regency_Code;references:Code"`
Villages []*evb.Basic `json:"villages,omitempty" gorm:"foreignKey:District_Code;references:Code"`
}
@@ -0,0 +1,7 @@
package base
type Basic struct {
Id uint32 `json:"id" gorm:"primaryKey"`
Village_Code string `json:"village_code" gorm:"size:10"`
Code string `json:"code" gorm:"unique;size:5"`
}
@@ -1,7 +1,11 @@
package postalcode
import (
ep "simrs-vx/internal/domain/main-entities/postal-code/base"
ev "simrs-vx/internal/domain/main-entities/village"
)
type PostalCode struct {
Id uint32 `json:"id" gorm:"primaryKey"`
Code string `json:"code" gorm:"unique;size:5"`
Village_Code string `json:"village_code" gorm:"size:10"`
ep.Basic
Village *ev.Village `json:"village,omitempty" gorm:"foreignKey:Village_Code;references:Code"`
}
@@ -2,6 +2,7 @@ package province
import (
ecore "simrs-vx/internal/domain/base-entities/core"
erb "simrs-vx/internal/domain/main-entities/regency/base"
)
type CreateDto struct {
@@ -36,16 +37,18 @@ type MetaDto struct {
}
type ResponseDto struct {
Id int16 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Id int16 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Regencies []erb.Basic `json:"regencies,omitempty"`
}
func (d Province) ToResponse() ResponseDto {
resp := ResponseDto{
Id: d.Id,
Code: d.Code,
Name: d.Name,
Id: d.Id,
Code: d.Code,
Name: d.Name,
Regencies: d.Regencies,
}
return resp
}
@@ -1,10 +1,10 @@
package province
import er "simrs-vx/internal/domain/main-entities/regency"
import erb "simrs-vx/internal/domain/main-entities/regency/base"
type Province struct {
Id int16 `json:"id" gorm:"primaryKey"`
Code string `json:"code" gorm:"unique;size:2"`
Name string `json:"name" gorm:"size:50"`
Regencies []*er.Regency `json:"regencies,omitempty" gorm:"foreignKey:Province_Code;references:Code"`
Id int16 `json:"id" gorm:"primaryKey"`
Code string `json:"code" gorm:"unique;size:2"`
Name string `json:"name" gorm:"size:50"`
Regencies []erb.Basic `json:"regencies,omitempty" gorm:"foreignKey:Province_Code;references:Code"`
}
@@ -0,0 +1,8 @@
package base
type Basic struct {
Id uint32 `json:"id" gorm:"primaryKey"`
Province_Code string `json:"province_code" gorm:"size:2"`
Code string `json:"code" gorm:"unique;size:4"`
Name string `json:"name" gorm:"size:50"`
}
+11 -7
View File
@@ -2,7 +2,9 @@ package regency
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ed "simrs-vx/internal/domain/main-entities/district"
edb "simrs-vx/internal/domain/main-entities/district/base"
ep "simrs-vx/internal/domain/main-entities/province"
erb "simrs-vx/internal/domain/main-entities/regency/base"
)
type CreateDto struct {
@@ -39,15 +41,17 @@ type MetaDto struct {
}
type ResponseDto struct {
Id uint16 `json:"id"`
Province_Code string `json:"province_code"`
Code string `json:"code"`
Name string `json:"name"`
Districts []*ed.District `json:"districts,omitempty"`
erb.Basic
Province *ep.Province `json:"province,omitempty"`
Districts []*edb.Basic `json:"districts,omitempty"`
}
func (d Regency) ToResponse() ResponseDto {
resp := ResponseDto(d)
resp := ResponseDto{
Basic: d.Basic,
Province: d.Province,
Districts: d.Districts,
}
return resp
}
@@ -1,11 +1,13 @@
package regency
import ed "simrs-vx/internal/domain/main-entities/district"
import (
edb "simrs-vx/internal/domain/main-entities/district/base"
ep "simrs-vx/internal/domain/main-entities/province"
erb "simrs-vx/internal/domain/main-entities/regency/base"
)
type Regency struct {
Id uint16 `json:"id" gorm:"primaryKey"`
Province_Code string `json:"province_code" gorm:"size:2"`
Code string `json:"code" gorm:"unique;size:4"`
Name string `json:"name" gorm:"size:50"`
Districts []*ed.District `json:"districts,omitempty" gorm:"foreignKey:Regency_Code;references:Code"`
erb.Basic
Province *ep.Province `json:"province,omitempty" gorm:"foreignKey:Province_Code;references:Code"`
Districts []*edb.Basic `json:"districts,omitempty" gorm:"foreignKey:Regency_Code;references:Code"`
}
@@ -0,0 +1,8 @@
package base
type Basic struct {
Id uint32 `json:"id" gorm:"primaryKey"`
District_Code string `json:"district_code" gorm:"size:6"`
Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"`
}
+11 -7
View File
@@ -2,7 +2,9 @@ package village
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ep "simrs-vx/internal/domain/main-entities/postal-code"
ed "simrs-vx/internal/domain/main-entities/district"
epb "simrs-vx/internal/domain/main-entities/postal-code/base"
evb "simrs-vx/internal/domain/main-entities/village/base"
)
type CreateDto struct {
@@ -39,15 +41,17 @@ type MetaDto struct {
}
type ResponseDto struct {
Id uint32 `json:"id"`
District_Code string `json:"district_code"`
Code string `json:"code"`
Name string `json:"name"`
PostalCodes []ep.PostalCode `json:"postalCodes,omitempty"`
evb.Basic
District *ed.District `json:"district,omitempty"`
PostalCodes []epb.Basic `json:"postalCodes,omitempty"`
}
func (d Village) ToResponse() ResponseDto {
resp := ResponseDto(d)
resp := ResponseDto{
Basic: d.Basic,
District: d.District,
PostalCodes: d.PostalCodes,
}
return resp
}
@@ -1,13 +1,13 @@
package village
import (
ep "simrs-vx/internal/domain/main-entities/postal-code"
ed "simrs-vx/internal/domain/main-entities/district"
epb "simrs-vx/internal/domain/main-entities/postal-code/base"
evb "simrs-vx/internal/domain/main-entities/village/base"
)
type Village struct {
Id uint32 `json:"id" gorm:"primaryKey"`
District_Code string `json:"district_code" gorm:"size:6"` // NOT: THE PROPER SIZE IS 6
Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"`
PostalCodes []ep.PostalCode `json:"postalCodes,omitempty" gorm:"foreignKey:Village_Code;references:Code"`
evb.Basic
District *ed.District `json:"district,omitempty" gorm:"foreignKey:District_Code;references:Code"`
PostalCodes []epb.Basic `json:"postalCodes,omitempty" gorm:"foreignKey:Village_Code;references:Code"`
}