feat (infra): add filter data that only have children
This commit is contained in:
@@ -21,10 +21,11 @@ type CreateDto struct {
|
|||||||
|
|
||||||
type ReadListDto struct {
|
type ReadListDto struct {
|
||||||
FilterDto
|
FilterDto
|
||||||
Includes string `json:"includes"`
|
Includes string `json:"includes"`
|
||||||
Preloads []string `json:"-"`
|
Preloads []string `json:"-"`
|
||||||
Search string `json:"search"`
|
Search string `json:"search"`
|
||||||
Pagination ecore.Pagination
|
Pagination ecore.Pagination
|
||||||
|
OnlyHaveChildren bool `json:"only-have-children"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilterDto struct {
|
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)
|
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.
|
tx = tx.
|
||||||
Model(&e.Infra{}).
|
Model(&e.Infra{}).
|
||||||
Scopes(gh.Filter(input.FilterDto)).
|
Scopes(gh.Filter(input.FilterDto)).
|
||||||
|
|||||||
Reference in New Issue
Block a user