优化结构

This commit is contained in:
Yvan
2026-08-28 11:51:37 +08:00
parent 5b04998731
commit 33ba777137
25 changed files with 163 additions and 125 deletions
+10 -5
View File
@@ -10,13 +10,18 @@ import (
// count the filtered query, apply the bounded page, load POs, and convert them
// at the data/biz boundary. Domain-specific filters and ordering stay in each
// repository.
func queryRows[PO any](db *gorm.DB, page, size int, paginate, required bool) ([]PO, int64, error) {
type rowQueryOptions struct {
Paginate bool
Required bool
}
func queryRows[PO any](db *gorm.DB, page, size int, options rowQueryOptions) ([]PO, int64, error) {
var total int64
if err := db.Count(&total).Error; err != nil {
return nil, 0, err
}
if paginate {
if required {
if options.Paginate {
if options.Required {
db = pagination.ApplyRequired(db, page, size, 100)
} else {
db = pagination.Apply(db, page, size, 100)
@@ -29,8 +34,8 @@ func queryRows[PO any](db *gorm.DB, page, size int, paginate, required bool) ([]
return pos, total, nil
}
func listRows[PO any, DO any](db *gorm.DB, page, size int, paginate bool, convert func(PO) *DO) ([]*DO, int64, error) {
pos, total, err := queryRows[PO](db, page, size, paginate, false)
func listRows[PO any, DO any](db *gorm.DB, page, size int, options rowQueryOptions, convert func(PO) *DO) ([]*DO, int64, error) {
pos, total, err := queryRows[PO](db, page, size, options)
if err != nil {
return nil, 0, err
}