feat (unit, division-position): add preload

This commit is contained in:
dpurbosakti
2025-08-20 13:53:14 +07:00
parent 4c25bdf8db
commit a218489496
6 changed files with 84 additions and 5 deletions
@@ -2,6 +2,7 @@ package divisionposition
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ed "simrs-vx/internal/domain/main-entities/division"
)
type CreateDto struct {
@@ -44,9 +45,10 @@ type MetaDto struct {
type ResponseDto struct {
ecore.SmallMain
Division_Id *uint16 `json:"division_id"`
Code string `json:"code"`
Name string `json:"name"`
Division_Id *uint16 `json:"division_id"`
Division *ed.Division `json:"division,omitempty"`
Code string `json:"code"`
Name string `json:"name"`
}
func (d DivisionPosition) ToResponse() ResponseDto {
@@ -56,6 +58,9 @@ func (d DivisionPosition) ToResponse() ResponseDto {
Name: d.Name,
}
resp.SmallMain = d.SmallMain
if d.Division != nil {
resp.Division = d.Division
}
return resp
}
@@ -0,0 +1,61 @@
package province
import (
ecore "simrs-vx/internal/domain/base-entities/core"
)
type CreateDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadListDto struct {
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 {
Code string `json:"code"`
Name string `json:"name"`
}
type UpdateDto struct {
CreateDto
}
type DeleteDto struct {
Code string `json:"code"`
}
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 Province) ToResponse() ResponseDto {
resp := ResponseDto{
Code: d.Code,
Name: d.Name,
}
return resp
}
func ToResponseList(users []Province) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,6 @@
package province
type Province struct {
Code string `json:"code" gorm:"size:2"`
Name string `json:"name" gorm:"size:50"`
}
+7 -2
View File
@@ -2,6 +2,7 @@ package unit
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ei "simrs-vx/internal/domain/main-entities/installation"
)
type CreateDto struct {
@@ -45,8 +46,9 @@ type MetaDto struct {
type ResponseDto struct {
ecore.SmallMain
Installation_Id *uint16 `json:"installation_id"`
Code string `json:"code"`
Name string `json:"name"`
Installation *ei.Installation
Code string `json:"code"`
Name string `json:"name"`
}
func (u Unit) ToResponse() ResponseDto {
@@ -56,6 +58,9 @@ func (u Unit) ToResponse() ResponseDto {
Name: u.Name,
}
resp.SmallMain = u.SmallMain
if u.Installation != nil {
resp.Installation = u.Installation
}
return resp
}
@@ -40,6 +40,7 @@ func ReadListData(input e.ReadListDto, dbx ...*gorm.DB) ([]e.DivisionPosition, *
Model(&e.DivisionPosition{}).
// Joins("Patient"). // if needed
// Preload("Patient"). // if needed
Preload("Division"). // if needed
Scopes(gh.Filter(input)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
@@ -40,6 +40,7 @@ func ReadListData(input e.ReadListDto, dbx ...*gorm.DB) ([]e.Unit, *e.MetaDto, e
Model(&e.Unit{}).
// Joins("Patient"). // if needed
// Preload("Patient"). // if needed
Preload("Installation"). // if needed
Scopes(gh.Filter(input)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).