added pagination to audit logs

This commit is contained in:
2026-02-11 22:18:02 +11:00
parent 6e2053175d
commit 2afa32dd63
5 changed files with 47 additions and 85 deletions

View File

@@ -50,31 +50,31 @@ func NewAuditLogFilter() *AuditLogFilter {
}
func (a *AuditLogFilter) UserID(id int) *AuditLogFilter {
a.Add("al.user_id", "=", id)
a.Equals("al.user_id", id)
return a
}
func (a *AuditLogFilter) Action(action string) *AuditLogFilter {
a.Add("al.action", "=", action)
a.Equals("al.action", action)
return a
}
func (a *AuditLogFilter) ResourceType(resourceType string) *AuditLogFilter {
a.Add("al.resource_type", "=", resourceType)
a.Equals("al.resource_type", resourceType)
return a
}
func (a *AuditLogFilter) Result(result string) *AuditLogFilter {
a.Add("al.result", "=", result)
a.Equals("al.result", result)
return a
}
func (a *AuditLogFilter) DateRange(start, end int64) *AuditLogFilter {
if start > 0 {
a.Add("al.created_at", ">=", start)
a.GreaterEqualThan("al.created_at", start)
}
if end > 0 {
a.Add("al.created_at", "<=", end)
a.LessEqualThan("al.created_at", end)
}
return a
}
@@ -83,7 +83,7 @@ func (a *AuditLogFilter) DateRange(start, end int64) *AuditLogFilter {
func GetAuditLogs(ctx context.Context, tx bun.Tx, pageOpts *PageOpts, filters *AuditLogFilter) (*List[AuditLog], error) {
defaultPageOpts := &PageOpts{
Page: 1,
PerPage: 50,
PerPage: 15,
Order: bun.OrderDesc,
OrderBy: "created_at",
}