diff --git a/model/query.go b/model/query.go index d5ea473..6e267dc 100644 --- a/model/query.go +++ b/model/query.go @@ -76,16 +76,10 @@ func paginationToMap[T Model](db dbQuery, ctx context.Context, q QueryCondition) } func PaginationToMap[T Model](ctx context.Context, q QueryCondition) (r []map[string]string, total int, err error) { - ctx = context.WithValue(ctx, "handle=>", "toMap") - ctx = context.WithValue(ctx, "map", &r) - _, total, err = pagination[T](globalBb, ctx, q) - return + return paginationToMap[T](globalBb, ctx, q) } func PaginationToMapFromDB[T Model](db dbQuery, ctx context.Context, q QueryCondition) (r []map[string]string, total int, err error) { - ctx = context.WithValue(ctx, "handle=>", "toMap") - ctx = context.WithValue(ctx, "map", &r) - _, total, err = pagination[T](db, ctx, q) - return + return paginationToMap[T](db, ctx, q) } func FindOneById[T Model, I constraints.Integer](ctx context.Context, id I) (T, error) { diff --git a/model/query_test.go b/model/query_test.go index e2aff9e..b588455 100644 --- a/model/query_test.go +++ b/model/query_test.go @@ -563,7 +563,12 @@ func Test_paginationToMap(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gotR, gotTotal, err := paginationToMap[post](tt.args.db, tt.args.ctx, tt.args.q) + gotR, gotTotal, err := PaginationToMap[post](tt.args.ctx, tt.args.q) + fmt.Println(gotR, gotTotal, err) + gotR, gotTotal, err = PaginationToMapFromDB[post](tt.args.db, tt.args.ctx, tt.args.q) + fmt.Println(gotR, gotTotal, err) + gotR, gotTotal, err = paginationToMap[post](tt.args.db, tt.args.ctx, tt.args.q) + if (err != nil) != tt.wantErr { t.Errorf("paginationToMap() error = %v, wantErr %v", err, tt.wantErr) return