From 73d0003281948f958a0029c8f0dfcfea3e4d3fcb Mon Sep 17 00:00:00 2001 From: Denozordec Date: Sun, 5 Apr 2026 22:24:54 +0700 Subject: [PATCH] refactor: update ListModules and GetModule methods in Postgres repository to include cron expression handling. Enhance module data retrieval by adding cron field to the scan process and updating the module struct accordingly. --- internal/repository/postgres.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/repository/postgres.go b/internal/repository/postgres.go index 4cb6bf9..119bf5d 100644 --- a/internal/repository/postgres.go +++ b/internal/repository/postgres.go @@ -99,14 +99,17 @@ func (p *Postgres) ListModules(tenantID string) []*store.Module { for rows.Next() { var m store.Module m.TenantID = tenantID - var doh, dc *string + var doh, dc, cron *string var refresh *int32 - if err := rows.Scan(&m.ID, &m.Type, &m.Name, &m.Enabled, &m.Priority, &doh, &refresh, &m.CronExpr, &dc); err != nil { + if err := rows.Scan(&m.ID, &m.Type, &m.Name, &m.Enabled, &m.Priority, &doh, &refresh, &cron, &dc); err != nil { continue } if refresh != nil { m.RefreshIntervalSec = int(*refresh) } + if cron != nil { + m.CronExpr = *cron + } if doh != nil && *doh != "" { m.DohProfileID = doh } @@ -122,12 +125,12 @@ func (p *Postgres) GetModule(tenantID, moduleID string) (*store.Module, error) { ctx := context.Background() var m store.Module m.TenantID = tenantID - var doh, dc *string + var doh, dc, cron *string var refresh *int32 err := p.pool.QueryRow(ctx, ` SELECT id, type, name, enabled, priority, doh_profile_id::text, refresh_interval_sec, cron_expr, default_community_id::text FROM module WHERE id = $1 AND tenant_id = $2 AND deleted_at IS NULL`, moduleID, tenantID).Scan( - &m.ID, &m.Type, &m.Name, &m.Enabled, &m.Priority, &doh, &refresh, &m.CronExpr, &dc) + &m.ID, &m.Type, &m.Name, &m.Enabled, &m.Priority, &doh, &refresh, &cron, &dc) if err != nil { if errors.Is(err, pgx.ErrNoRows) { return nil, store.ErrNotFound @@ -137,6 +140,9 @@ func (p *Postgres) GetModule(tenantID, moduleID string) (*store.Module, error) { if refresh != nil { m.RefreshIntervalSec = int(*refresh) } + if cron != nil { + m.CronExpr = *cron + } if doh != nil && *doh != "" { m.DohProfileID = doh }