fixed relationship issues

This commit is contained in:
2026-02-05 00:10:10 +11:00
parent 20308fe35c
commit 4c31c24069
22 changed files with 236 additions and 254 deletions

View File

@@ -104,39 +104,37 @@ func (l *Logger) log(
}
// GetRecentLogs retrieves recent audit logs with pagination
// TODO: change this to user db.PageOpts
func (l *Logger) GetRecentLogs(ctx context.Context, limit, offset int) ([]*db.AuditLog, int, error) {
func (l *Logger) GetRecentLogs(ctx context.Context, pageOpts *db.PageOpts) (*db.AuditLogs, error) {
tx, err := l.conn.BeginTx(ctx, nil)
if err != nil {
return nil, 0, errors.Wrap(err, "conn.BeginTx")
return nil, errors.Wrap(err, "conn.BeginTx")
}
defer func() { _ = tx.Rollback() }()
logs, total, err := db.GetAuditLogs(ctx, tx, limit, offset, nil)
logs, err := db.GetAuditLogs(ctx, tx, pageOpts, nil)
if err != nil {
return nil, 0, err
return nil, err
}
_ = tx.Commit() // read only transaction
return logs, total, nil
return logs, nil
}
// GetLogsByUser retrieves audit logs for a specific user
// TODO: change this to user db.PageOpts
func (l *Logger) GetLogsByUser(ctx context.Context, userID int, limit, offset int) ([]*db.AuditLog, int, error) {
func (l *Logger) GetLogsByUser(ctx context.Context, userID int, pageOpts *db.PageOpts) (*db.AuditLogs, error) {
tx, err := l.conn.BeginTx(ctx, nil)
if err != nil {
return nil, 0, errors.Wrap(err, "conn.BeginTx")
return nil, errors.Wrap(err, "conn.BeginTx")
}
defer func() { _ = tx.Rollback() }()
logs, total, err := db.GetAuditLogsByUser(ctx, tx, userID, limit, offset)
logs, err := db.GetAuditLogsByUser(ctx, tx, userID, pageOpts)
if err != nil {
return nil, 0, err
return nil, err
}
_ = tx.Commit() // read only transaction
return logs, total, nil
return logs, nil
}
// CleanupOldLogs deletes audit logs older than the specified number of days