From 271e252c53e15304e5f2793f371831c5164d2057 Mon Sep 17 00:00:00 2001 From: mikestefanello <552328+mikestefanello@users.noreply.github.com> Date: Sat, 12 Apr 2025 10:20:20 -0400 Subject: [PATCH] Use handler config. --- pkg/handlers/admin.go | 17 ++++++++++------- pkg/services/container_test.go | 5 ----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/handlers/admin.go b/pkg/handlers/admin.go index 5588494..cde84f1 100644 --- a/pkg/handlers/admin.go +++ b/pkg/handlers/admin.go @@ -5,6 +5,7 @@ import ( "net/http" "strconv" "strings" + "time" "entgo.io/ent/entc/gen" "entgo.io/ent/entc/load" @@ -24,10 +25,9 @@ const entityContextKey = "admin:entity" const entityIDContextKey = "admin:entity_id" type Admin struct { - orm *ent.Client - graph *gen.Graph - admin *admin.Handler - itemsPerPage int + orm *ent.Client + graph *gen.Graph + admin *admin.Handler } func init() { @@ -35,10 +35,13 @@ func init() { } func (h *Admin) Init(c *services.Container) error { - h.itemsPerPage = 25 h.graph = c.Graph h.orm = c.ORM - h.admin = admin.NewHandler(h.orm, h.itemsPerPage) + h.admin = admin.NewHandler(h.orm, admin.HandlerConfig{ + ItemsPerPage: 25, + PageQueryKey: pager.QueryKey, + TimeFormat: time.DateTime, + }) return nil } @@ -96,7 +99,7 @@ func (h *Admin) EntityList(n *gen.Type) echo.HandlerFunc { return pages.AdminEntityList(ctx, pages.AdminEntityListParams{ EntityType: n, EntityList: list, - Pager: pager.NewPager(ctx, h.itemsPerPage), + Pager: pager.NewPager(ctx, h.admin.Config.ItemsPerPage), }) } } diff --git a/pkg/services/container_test.go b/pkg/services/container_test.go index 5d2c3d7..7f4a5d4 100644 --- a/pkg/services/container_test.go +++ b/pkg/services/container_test.go @@ -17,9 +17,4 @@ func TestNewContainer(t *testing.T) { assert.NotNil(t, c.Mail) assert.NotNil(t, c.Auth) assert.NotNil(t, c.Tasks) - - g := c.Graph - if g == nil { - //c.ORM.User.Create(). - } }