fix pagination and search

This commit is contained in:
dpurbosakti
2025-10-08 12:21:42 +07:00
parent e9b262175d
commit 7940c895b1
46 changed files with 175 additions and 47 deletions

No files matched your search

@@ -11,12 +11,19 @@ type CreateDto struct {
} }
type ReadListDto struct { type ReadListDto struct {
Code string `json:"code"` FilterDto
Name string `json:"name"` Includes string `json:"includes"`
IndName string `json:"indName"` Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
IndName string `json:"indName"`
}
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id uint16 `json:"id"`
Code *string `json:"code"` Code *string `json:"code"`
@@ -17,6 +17,7 @@ type ReadListDto struct {
FilterDto FilterDto
Includes string `json:"includes"` Includes string `json:"includes"`
Preloads []string `json:"-"` Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
+9 -3
View File
@@ -10,12 +10,18 @@ type CreateDto struct {
} }
type ReadListDto struct { type ReadListDto struct {
Code string `json:"code"` FilterDto
Name string `json:"name"` Includes string `json:"includes"`
Search string `json:"search"` Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id uint16 `json:"id"`
Code *string `json:"code"` Code *string `json:"code"`
@@ -17,6 +17,7 @@ type ReadListDto struct {
FilterDto FilterDto
Includes string `json:"includes"` Includes string `json:"includes"`
Preloads []string `json:"-"` Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
@@ -19,6 +19,7 @@ type ReadListDto struct {
FilterDto FilterDto
Includes string `json:"includes"` Includes string `json:"includes"`
Preloads []string `json:"-"` Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
@@ -10,12 +10,18 @@ type CreateDto struct {
} }
type ReadListDto struct { type ReadListDto struct {
Code string `json:"code"` FilterDto
Name string `json:"name"` Includes string `json:"includes"`
Preloads []string
Search string `json:"search"` Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id uint16 `json:"id"`
Code string `json:"code"` Code string `json:"code"`
@@ -13,10 +13,17 @@ type CreateDto struct {
} }
type ReadListDto struct { type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
Scope_Code *ere.CheckupScopeCode `json:"scope-code"` Scope_Code *ere.CheckupScopeCode `json:"scope-code"`
Pagination ecore.Pagination
} }
type ReadDetailDto struct { type ReadDetailDto struct {
@@ -10,11 +10,18 @@ type CreateDto struct {
} }
type ReadListDto struct { type ReadListDto struct {
Code string `json:"code"` FilterDto
Name string `json:"name"` Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id uint16 `json:"id"`
Code *string `json:"code"` Code *string `json:"code"`
@@ -10,11 +10,18 @@ type CreateDto struct {
} }
type ReadListDto struct { type ReadListDto struct {
Code string `json:"code"` FilterDto
Name string `json:"name"` Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id uint16 `json:"id"`
Code *string `json:"code"` Code *string `json:"code"`
@@ -11,10 +11,17 @@ type CreateDto struct {
} }
type ReadListDto struct { type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
Regency_Code string `json:"regency-code"` Regency_Code string `json:"regency-code"`
Pagination ecore.Pagination
} }
type ReadDetailDto struct { type ReadDetailDto struct {
@@ -11,13 +11,19 @@ type CreateDto struct {
} }
type ReadListDto struct { type ReadListDto struct {
Code string `json:"code"` FilterDto
Name string `json:"name"` Includes string `json:"includes"`
IndName string `json:"indName"` Preloads []string `json:"-"`
Search string `json:"search"` Search string `json:"search"`
Pagination ecore.Pagination Pagination ecore.Pagination
} }
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
IndName string `json:"indName"`
}
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id uint16 `json:"id"`
Code *string `json:"code"` Code *string `json:"code"`
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.De
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Device{}). Model(&e.Device{}).
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err return err
} }
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err return err
} }
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di
tx = dg.I tx = dg.I
} }
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.DiagnoseSrc{}). Model(&e.DiagnoseSrc{}).
Scopes(gh.Filter(input)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") Order("\"CreatedAt\" DESC")
@@ -53,6 +53,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di
} }
} }
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.DivisionPosition{}). Model(&e.DivisionPosition{}).
Preload("Division"). Preload("Division").
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
if input.OnlyHaveChildren { if input.OnlyHaveChildren {
tx = tx.Where(` tx = tx.Where(`
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err return err
} }
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err return err
} }
@@ -47,11 +47,11 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Et
tx = dg.I tx = dg.I
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Ethnic{}). Model(&e.Ethnic{}).
Scopes(gh.Filter(input)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") Order("\"CreatedAt\" DESC")
+1 -1
View File
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
if input.OnlyHaveChildren { if input.OnlyHaveChildren {
tx = tx.Where(` tx = tx.Where(`
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Installation{}). Model(&e.Installation{}).
@@ -53,6 +53,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In
} }
} }
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.InsuranceCompany{}). Model(&e.InsuranceCompany{}).
Scopes(gh.Filter(input.FilterDto)). Scopes(gh.Filter(input.FilterDto)).
@@ -53,6 +53,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.It
} }
} }
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Item{}). Model(&e.Item{}).
Scopes(gh.Filter(input.FilterDto)). Scopes(gh.Filter(input.FilterDto)).
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err return err
} }
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err return err
} }
@@ -51,7 +51,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.La
tx = tx. tx = tx.
Model(&e.Language{}). Model(&e.Language{}).
Scopes(gh.Filter(input)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") Order("\"CreatedAt\" DESC")
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err return err
} }
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err return err
} }
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Mc
tx = dg.I tx = dg.I
} }
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.McuSrcCategory{}). Model(&e.McuSrcCategory{}).
Scopes(gh.Filter(input)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") Order("\"CreatedAt\" DESC")
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Mc
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.McuSrc{}). Model(&e.McuSrc{}).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Mc
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.McuSubSrc{}). Model(&e.McuSubSrc{}).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.MedicalActionSrc{}). Model(&e.MedicalActionSrc{}).
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err return err
} }
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err return err
} }
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me
tx = dg.I tx = dg.I
} }
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.MedicineGroup{}). Model(&e.MedicineGroup{}).
Scopes(gh.Filter(input)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") Order("\"CreatedAt\" DESC")
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err return err
} }
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err return err
} }
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me
tx = dg.I tx = dg.I
} }
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.MedicineMethod{}). Model(&e.MedicineMethod{}).
Scopes(gh.Filter(input)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") Order("\"CreatedAt\" DESC")
@@ -53,9 +53,9 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.Debug().
Model(&e.Medicine{}). Model(&e.Medicine{}).
Scopes(gh.Filter(input.FilterDto)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err return err
} }
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err return err
} }
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Ph
tx = dg.I tx = dg.I
} }
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.PharmacyCompany{}). Model(&e.PharmacyCompany{}).
Scopes(gh.Filter(input)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") Order("\"CreatedAt\" DESC")
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err return err
} }
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err return err
} }
@@ -47,11 +47,11 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Pr
tx = dg.I tx = dg.I
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.ProcedureSrc{}). Model(&e.ProcedureSrc{}).
Scopes(gh.Filter(input)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") Order("\"CreatedAt\" DESC")
@@ -53,9 +53,9 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Pr
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.Debug().
Model(&e.Province{}). Model(&e.Province{}).
Scopes(gh.Filter(input.FilterDto)). Scopes(gh.Filter(input.FilterDto)).
Count(&count). Count(&count).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Re
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Regency{}). Model(&e.Regency{}).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Sp
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Specialist{}). Model(&e.Specialist{}).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Su
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Subspecialist{}). Model(&e.Subspecialist{}).
+1 -1
View File
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Un
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Unit{}). Model(&e.Unit{}).
+1 -1
View File
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Uo
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Uom{}). Model(&e.Uom{}).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Vi
} }
} }
plh.SearchCodeOrName(input.Search, tx) tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx. tx = tx.
Model(&e.Village{}). Model(&e.Village{}).
+4 -2
View File
@@ -8,10 +8,12 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
func SearchCodeOrName(search string, tx *gorm.DB) { func SearchCodeOrName(search string, tx *gorm.DB) *gorm.DB {
if search != "" { if search != "" {
tx.Where("\"Code\" ILIKE ? OR \"Name\" ILIKE ?", "%"+search+"%", "%"+search+"%") tx = tx.Where("\"Code\" ILIKE ? OR \"Name\" ILIKE ?", "%"+search+"%", "%"+search+"%")
} }
return tx
} }
func HandleCreateError(input any, event *pl.Event, err error) error { func HandleCreateError(input any, event *pl.Event, err error) error {