From a43c23f4b10bb3ce61a60dff48a53304b24ac2db Mon Sep 17 00:00:00 2001 From: Haelnorr Date: Wed, 11 Feb 2026 19:10:39 +1100 Subject: [PATCH] minor tweak --- .gitignore | 1 + internal/db/auditlog.go | 36 +++++------------------------------- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 41d3e99..7a77d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ static/css/output.css internal/view/**/*_templ.go internal/view/**/*_templ.txt cmd/test/* +.opencode # Database backups (compressed) backups/*.sql.gz diff --git a/internal/db/auditlog.go b/internal/db/auditlog.go index 4c11469..b2bd307 100644 --- a/internal/db/auditlog.go +++ b/internal/db/auditlog.go @@ -41,18 +41,11 @@ func CreateAuditLog(ctx context.Context, tx bun.Tx, log *AuditLog) error { type AuditLogFilter struct { *ListFilter - customWhere []whereClause -} - -type whereClause struct { - query string - args []any } func NewAuditLogFilter() *AuditLogFilter { return &AuditLogFilter{ - ListFilter: NewListFilter(), - customWhere: []whereClause{}, + ListFilter: NewListFilter(), } } @@ -95,16 +88,10 @@ func GetAuditLogs(ctx context.Context, tx bun.Tx, pageOpts *PageOpts, filters *A OrderBy: "created_at", } - lg := GetList[AuditLog](tx). + return GetList[AuditLog](tx). Relation("User"). - Filter(filters.filters...) - - // Apply custom where clauses (e.g., date range) - for _, clause := range filters.customWhere { - lg = lg.Where(clause.query, clause.args...) - } - - return lg.GetPaged(ctx, pageOpts, defaultPageOpts) + Filter(filters.filters...). + GetPaged(ctx, pageOpts, defaultPageOpts) } // GetAuditLogsByUser retrieves audit logs for a specific user @@ -132,20 +119,7 @@ func GetAuditLogByID(ctx context.Context, tx bun.Tx, id int) (*AuditLog, error) if id <= 0 { return nil, errors.New("id must be positive") } - - log := new(AuditLog) - err := tx.NewSelect(). - Model(log). - Relation("User"). - Where("al.id = ?", id). - Scan(ctx) - if err != nil { - if err.Error() == "sql: no rows in result set" { - return nil, nil - } - return nil, errors.Wrap(err, "tx.NewSelect") - } - return log, nil + return GetByID[AuditLog](tx, id).Relation("User").Get(ctx) } // GetUniqueActions retrieves a list of all unique actions in the audit log