~netlandish/gobwebs-auditlog

b4ddce55587ef5a6c673531955074e232d807830 — Peter Sanchez 28 days ago d8fad17
Add helper function
1 files changed, 14 insertions(+), 2 deletions(-)

M audit_log.go
M audit_log.go => audit_log.go +14 -2
@@ 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,
	}
}

Do not follow this link