feat (infra): add filter data that only have children

This commit is contained in:
dpurbosakti
2025-10-04 15:42:40 +07:00
parent 208a1e6123
commit 10ef340d63
2 changed files with 15 additions and 4 deletions
+5 -4
View File
@@ -21,10 +21,11 @@ type CreateDto struct {
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
OnlyHaveChildren bool `json:"only-have-children"`
}
type FilterDto struct {
@@ -55,6 +55,16 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In
plh.SearchCodeOrName(input.Search, tx)
if input.OnlyHaveChildren {
tx = tx.Where(`
EXISTS (
SELECT 1
FROM "Infra" c
WHERE c."Parent_Id" = "Infra"."Id"
)
`)
}
tx = tx.
Model(&e.Infra{}).
Scopes(gh.Filter(input.FilterDto)).