feat: add audit log sqlc queries and generated code
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.31.1
|
||||
// source: queries.sql
|
||||
|
||||
package db
|
||||
@@ -57,6 +57,49 @@ func (q *Queries) CreateAPIToken(ctx context.Context, arg CreateAPITokenParams)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createAuditLog = `-- name: CreateAuditLog :one
|
||||
INSERT INTO audit_log (id, user_id, action, resource_type, resource_id, ip, user_agent, metadata_json)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING id, occurred_at, user_id, "action", resource_type, resource_id, ip, user_agent, metadata_json
|
||||
`
|
||||
|
||||
type CreateAuditLogParams struct {
|
||||
ID string `json:"id"`
|
||||
UserID sql.NullString `json:"user_id"`
|
||||
Action string `json:"action"`
|
||||
ResourceType sql.NullString `json:"resource_type"`
|
||||
ResourceID sql.NullString `json:"resource_id"`
|
||||
Ip sql.NullString `json:"ip"`
|
||||
UserAgent sql.NullString `json:"user_agent"`
|
||||
MetadataJson sql.NullString `json:"metadata_json"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAuditLog(ctx context.Context, arg CreateAuditLogParams) (AuditLog, error) {
|
||||
row := q.db.QueryRowContext(ctx, createAuditLog,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Action,
|
||||
arg.ResourceType,
|
||||
arg.ResourceID,
|
||||
arg.Ip,
|
||||
arg.UserAgent,
|
||||
arg.MetadataJson,
|
||||
)
|
||||
var i AuditLog
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OccurredAt,
|
||||
&i.UserID,
|
||||
&i.Action,
|
||||
&i.ResourceType,
|
||||
&i.ResourceID,
|
||||
&i.Ip,
|
||||
&i.UserAgent,
|
||||
&i.MetadataJson,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createSession = `-- name: CreateSession :one
|
||||
INSERT INTO session (id, user_id, expires_at)
|
||||
VALUES (?, ?, ?)
|
||||
@@ -124,22 +167,6 @@ func (q *Queries) DeleteSession(ctx context.Context, id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const refreshSession = `-- name: RefreshSession :exec
|
||||
UPDATE session
|
||||
SET expires_at = ?
|
||||
WHERE id = ?
|
||||
`
|
||||
|
||||
type RefreshSessionParams struct {
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) RefreshSession(ctx context.Context, arg RefreshSessionParams) error {
|
||||
_, err := q.db.ExecContext(ctx, refreshSession, arg.ExpiresAt, arg.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteWatchListEntry = `-- name: DeleteWatchListEntry :exec
|
||||
DELETE FROM watch_list_entry
|
||||
WHERE user_id = ? AND anime_id = ?
|
||||
@@ -299,6 +326,52 @@ func (q *Queries) GetAnimeNeedingRelationSync(ctx context.Context) ([]GetAnimeNe
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getAuditLogsForUser = `-- name: GetAuditLogsForUser :many
|
||||
SELECT id, occurred_at, user_id, "action", resource_type, resource_id, ip, user_agent, metadata_json
|
||||
FROM audit_log
|
||||
WHERE user_id = ?
|
||||
ORDER BY occurred_at DESC
|
||||
LIMIT ?
|
||||
`
|
||||
|
||||
type GetAuditLogsForUserParams struct {
|
||||
UserID sql.NullString `json:"user_id"`
|
||||
Limit int64 `json:"limit"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetAuditLogsForUser(ctx context.Context, arg GetAuditLogsForUserParams) ([]AuditLog, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAuditLogsForUser, arg.UserID, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []AuditLog
|
||||
for rows.Next() {
|
||||
var i AuditLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OccurredAt,
|
||||
&i.UserID,
|
||||
&i.Action,
|
||||
&i.ResourceType,
|
||||
&i.ResourceID,
|
||||
&i.Ip,
|
||||
&i.UserAgent,
|
||||
&i.MetadataJson,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getContinueWatchingEntries = `-- name: GetContinueWatchingEntries :many
|
||||
SELECT
|
||||
c.id,
|
||||
@@ -918,6 +991,22 @@ func (q *Queries) MarkRelationsSynced(ctx context.Context, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const refreshSession = `-- name: RefreshSession :exec
|
||||
UPDATE session
|
||||
SET expires_at = ?
|
||||
WHERE id = ?
|
||||
`
|
||||
|
||||
type RefreshSessionParams struct {
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) RefreshSession(ctx context.Context, arg RefreshSessionParams) error {
|
||||
_, err := q.db.ExecContext(ctx, refreshSession, arg.ExpiresAt, arg.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
const revokeAllAPITokensForUser = `-- name: RevokeAllAPITokensForUser :exec
|
||||
UPDATE api_token
|
||||
SET revoked_at = CURRENT_TIMESTAMP
|
||||
|
||||
Reference in New Issue
Block a user