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.go
|
||||||
internal/view/**/*_templ.txt
|
internal/view/**/*_templ.txt
|
||||||
cmd/test/*
|
cmd/test/*
|
||||||
|
.opencode
|
||||||
|
|
||||||
# Database backups (compressed)
|
# Database backups (compressed)
|
||||||
backups/*.sql.gz
|
backups/*.sql.gz
|
||||||
|
|||||||
@@ -41,18 +41,11 @@ func CreateAuditLog(ctx context.Context, tx bun.Tx, log *AuditLog) error {
|
|||||||
|
|
||||||
type AuditLogFilter struct {
|
type AuditLogFilter struct {
|
||||||
*ListFilter
|
*ListFilter
|
||||||
customWhere []whereClause
|
|
||||||
}
|
|
||||||
|
|
||||||
type whereClause struct {
|
|
||||||
query string
|
|
||||||
args []any
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuditLogFilter() *AuditLogFilter {
|
func NewAuditLogFilter() *AuditLogFilter {
|
||||||
return &AuditLogFilter{
|
return &AuditLogFilter{
|
||||||
ListFilter: NewListFilter(),
|
ListFilter: NewListFilter(),
|
||||||
customWhere: []whereClause{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,16 +88,10 @@ func GetAuditLogs(ctx context.Context, tx bun.Tx, pageOpts *PageOpts, filters *A
|
|||||||
OrderBy: "created_at",
|
OrderBy: "created_at",
|
||||||
}
|
}
|
||||||
|
|
||||||
lg := GetList[AuditLog](tx).
|
return GetList[AuditLog](tx).
|
||||||
Relation("User").
|
Relation("User").
|
||||||
Filter(filters.filters...)
|
Filter(filters.filters...).
|
||||||
|
GetPaged(ctx, pageOpts, defaultPageOpts)
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAuditLogsByUser retrieves audit logs for a specific user
|
// 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 {
|
if id <= 0 {
|
||||||
return nil, errors.New("id must be positive")
|
return nil, errors.New("id must be positive")
|
||||||
}
|
}
|
||||||
|
return GetByID[AuditLog](tx, id).Relation("User").Get(ctx)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUniqueActions retrieves a list of all unique actions in the audit log
|
// GetUniqueActions retrieves a list of all unique actions in the audit log
|
||||||
|
|||||||
Reference in New Issue
Block a user