@@ 28,8 28,10 @@ func GetAuditLogs(ctx context.Context, opts *database.FilterOptions) ([]*AuditLo
if err := database.WithTx(ctx, database.TxOptionsRO, func(tx *sql.Tx) error {
q := opts.GetBuilder(nil)
rows, err := q.
- Columns("id", "user_id", "ip_address", "event_type", "details", "metadata", "created_on").
- From("audit_log").
+ Columns("al.id", "al.user_id", "al.ip_address", "al.event_type",
+ "al.details", "al.metadata", "al.created_on").
+ From("audit_log al").
+ LeftJoin("users u ON al.user_id = u.id").
PlaceholderFormat(sq.Dollar).
RunWith(tx).
QueryContext(ctx)
@@ 95,3 97,13 @@ func (al *AuditLog) AddMetadata(name string, value any) {
}
al.Metadata[name] = value
}
+
+// New is a helper to create an audit log instance for you
+func New(userID int, ipAddress, eventType, details string) *AuditLog {
+ return &AuditLog{
+ UserID: userID,
+ IPAddress: ipAddress,
+ EventType: eventType,
+ Details: details,
+ }
+}