refactor use case

This commit is contained in:
dpurbosakti
2025-08-20 16:51:24 +07:00
parent a218489496
commit 5c716eb269
46 changed files with 3080 additions and 278 deletions
@@ -0,0 +1,62 @@
package district
import ev "simrs-vx/internal/domain/main-entities/village"
type CreateDto struct {
Regency_Code string `json:"regency_code" validate:"numeric;maxLength=4"`
Code string `json:"code" validate:"numeric;maxLength=6"`
Name string `json:"name" validate:"alphaSpace;maxLength=50"`
}
type ReadListDto struct {
Regency_Code string `json:"regency_code"`
Code string `json:"code"`
Name string `json:"name"`
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint32 `json:"id"`
Regency_Code string `json:"regency_code"`
Code string `json:"code"`
Name string `json:"name"`
}
type UpdateDto struct {
Id uint32 `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint32 `json:"id"`
}
type MetaDto struct {
PageNumber int `json:"page_number"`
PageSize int `json:"page_size"`
Count int `json:"count"`
}
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"`
}
func (d District) ToResponse() ResponseDto {
resp := ResponseDto(d)
return resp
}
func ToResponseList(users []District) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,11 @@
package district
import ev "simrs-vx/internal/domain/main-entities/village"
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"`
}
@@ -9,6 +9,6 @@ type DivisionPosition struct {
ecore.SmallMain // adjust this according to the needs
Division_Id *uint16 `json:"division_id"`
Division *ed.Division `json:"division" gorm:"foreignKey:Division_Id"`
Code string `json:"code" gorm:"size:10"`
Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"`
}
@@ -6,7 +6,7 @@ import (
type Division struct {
ecore.SmallMain // adjust this according to the needs
Code string `json:"code" gorm:"size:10"`
Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"`
Parent_Id *int16 `json:"parent_id"`
}
@@ -7,7 +7,7 @@ import (
type Installation struct {
ecore.SmallMain // adjust this according to the needs
Code string `json:"code" gorm:"size:10"`
Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"`
EncounterClass_Code ere.EncounterClass `json:"encounterClass_code" gorm:"size:10"`
}
+9 -11
View File
@@ -1,12 +1,8 @@
package province
import (
ecore "simrs-vx/internal/domain/base-entities/core"
)
type CreateDto struct {
Code string `json:"code"`
Name string `json:"name"`
Code string `json:"code" validate:"required;minLength=2;maxLength=2"`
Name string `json:"name" validate:"required;maxLength=10"`
}
type ReadListDto struct {
@@ -19,16 +15,18 @@ type ReadListDto struct {
}
type ReadDetailDto struct {
Id int16 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
}
type UpdateDto struct {
Id int16 `json:"id"`
CreateDto
}
type DeleteDto struct {
Code string `json:"code"`
Id int16 `json:"id"`
}
type MetaDto struct {
@@ -38,14 +36,14 @@ type MetaDto struct {
}
type ResponseDto struct {
ecore.SmallMain
Code string `json:"code"`
Name string `json:"name"`
Parent_Id *int16 `json:"parent_id"`
Id int16 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
}
func (d Province) ToResponse() ResponseDto {
resp := ResponseDto{
Id: d.Id,
Code: d.Code,
Name: d.Name,
}
@@ -1,6 +1,10 @@
package province
import er "simrs-vx/internal/domain/main-entities/regency"
type Province struct {
Code string `json:"code" gorm:"size:2"`
Name string `json:"name" gorm:"size:50"`
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"`
}
@@ -0,0 +1,62 @@
package regency
import ed "simrs-vx/internal/domain/main-entities/district"
type CreateDto struct {
Province_Code string `json:"province_code" validate:"numeric;maxLength=2"`
Code string `json:"code" validate:"numeric;maxLength=4"`
Name string `json:"name" validate:"alphaSpace;maxLength=50"`
}
type ReadListDto struct {
Province_Code string `json:"province_code"`
Code string `json:"code"`
Name string `json:"name"`
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Province_Code string `json:"province_code"`
Code string `json:"code"`
Name string `json:"name"`
}
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 {
Id uint16 `json:"id"`
Province_Code string `json:"province_code"`
Code string `json:"code"`
Name string `json:"name"`
Districts []*ed.District `json:"districts,omitempty"`
}
func (r Regency) ToResponse() ResponseDto {
resp := ResponseDto(r)
return resp
}
func ToResponseList(users []Regency) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,11 @@
package regency
import ed "simrs-vx/internal/domain/main-entities/district"
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"`
}
+1 -1
View File
@@ -9,6 +9,6 @@ type Unit struct {
ecore.SmallMain // adjust this according to the needs
Installation_Id *uint16 `json:"installation_id"`
Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Id"`
Code string `json:"code" gorm:"size:10"`
Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"`
}
@@ -0,0 +1,59 @@
package village
type CreateDto struct {
District_Code string `json:"district_code" validate:"numeric;maxLength=6"`
Code string `json:"code" validate:"numeric;maxLength=10"`
Name string `json:"name" validate:"alphaSpace;maxLength=50"`
}
type ReadListDto struct {
District_Code string `json:"district_code"`
Code string `json:"code"`
Name string `json:"name"`
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint32 `json:"id"`
District_Code string `json:"district_code"`
Code string `json:"code"`
Name string `json:"name"`
}
type UpdateDto struct {
Id uint32 `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint32 `json:"id"`
}
type MetaDto struct {
PageNumber int `json:"page_number"`
PageSize int `json:"page_size"`
Count int `json:"count"`
}
type ResponseDto struct {
Id uint32 `json:"id"`
District_Code string `json:"district_code"`
Code string `json:"code"`
Name string `json:"name"`
}
func (v Village) ToResponse() ResponseDto {
resp := ResponseDto(v)
return resp
}
func ToResponseList(users []Village) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,8 @@
package village
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"`
}