fixed db issues
This commit is contained in:
@@ -59,11 +59,9 @@ type AuditLogFilters struct {
|
||||
|
||||
// GetAuditLogs retrieves audit logs with optional filters and pagination
|
||||
func GetAuditLogs(ctx context.Context, tx bun.Tx, pageOpts *PageOpts, filters *AuditLogFilters) (*AuditLogs, error) {
|
||||
pageOpts = setDefaultPageOpts(pageOpts, 1, 50, bun.OrderDesc, "created_at")
|
||||
query := tx.NewSelect().
|
||||
Model((*AuditLog)(nil)).
|
||||
Relation("User").
|
||||
OrderBy(pageOpts.OrderBy, pageOpts.Order)
|
||||
Relation("User")
|
||||
|
||||
// Apply filters if provided
|
||||
if filters != nil {
|
||||
@@ -88,11 +86,9 @@ func GetAuditLogs(ctx context.Context, tx bun.Tx, pageOpts *PageOpts, filters *A
|
||||
}
|
||||
|
||||
// Get paginated results
|
||||
query, pageOpts = setPageOpts(query, pageOpts, 1, 50, bun.OrderDesc, "created_at")
|
||||
logs := new([]*AuditLog)
|
||||
err = query.
|
||||
Offset(pageOpts.PerPage*(pageOpts.Page-1)).
|
||||
Limit(pageOpts.PerPage).
|
||||
Scan(ctx, &logs)
|
||||
err = query.Scan(ctx, &logs)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, errors.Wrap(err, "query.Scan")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user