minor tweak
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user