Files
lincodex/backend/internal/adapter/secondary/postgres/sqlc/notification_inbox.sql.go
T

230 lines
5.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: notification_inbox.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getNotificationInboxEvent = `-- name: GetNotificationInboxEvent :one
SELECT
recipient_user_id,
event_id,
organization_id,
event_type,
schema_version,
source_type,
source_id,
occurred_at,
read_at
FROM notification_inbox_events
WHERE recipient_user_id = $1
AND event_id = $2
`
type GetNotificationInboxEventParams struct {
RecipientUserID pgtype.UUID
EventID pgtype.UUID
}
// Read the existing row after a duplicate insert so the repository can reject
// an event ID whose immutable metadata changed on redelivery.
func (q *Queries) GetNotificationInboxEvent(ctx context.Context, arg GetNotificationInboxEventParams) (NotificationInboxEvent, error) {
row := q.db.QueryRow(ctx, getNotificationInboxEvent, arg.RecipientUserID, arg.EventID)
var i NotificationInboxEvent
err := row.Scan(
&i.RecipientUserID,
&i.EventID,
&i.OrganizationID,
&i.EventType,
&i.SchemaVersion,
&i.SourceType,
&i.SourceID,
&i.OccurredAt,
&i.ReadAt,
)
return i, err
}
const insertNotificationInboxEvent = `-- name: InsertNotificationInboxEvent :execrows
INSERT INTO notification_inbox_events (
recipient_user_id,
event_id,
organization_id,
event_type,
schema_version,
source_type,
source_id,
occurred_at
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8
)
ON CONFLICT (recipient_user_id, event_id) DO NOTHING
`
type InsertNotificationInboxEventParams struct {
RecipientUserID pgtype.UUID
EventID pgtype.UUID
OrganizationID pgtype.UUID
EventType string
SchemaVersion int32
SourceType string
SourceID pgtype.UUID
OccurredAt pgtype.Timestamptz
}
// Store one recipient's reference to a delivered invitation event. The
// unique key absorbs at-least-once redelivery without copying event content.
func (q *Queries) InsertNotificationInboxEvent(ctx context.Context, arg InsertNotificationInboxEventParams) (int64, error) {
result, err := q.db.Exec(ctx, insertNotificationInboxEvent,
arg.RecipientUserID,
arg.EventID,
arg.OrganizationID,
arg.EventType,
arg.SchemaVersion,
arg.SourceType,
arg.SourceID,
arg.OccurredAt,
)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const listNotificationInboxEvents = `-- name: ListNotificationInboxEvents :many
SELECT
recipient_user_id,
event_id,
organization_id,
event_type,
schema_version,
source_type,
source_id,
occurred_at,
read_at
FROM notification_inbox_events
WHERE recipient_user_id = $1
AND (
$2::uuid IS NULL
OR organization_id = $2::uuid
)
AND (
$3::timestamptz IS NULL
OR (occurred_at, event_id) < (
$3::timestamptz,
$4::uuid
)
)
ORDER BY occurred_at DESC, event_id DESC
LIMIT $5
`
type ListNotificationInboxEventsParams struct {
RecipientUserID pgtype.UUID
OrganizationID pgtype.UUID
AfterOccurredAt pgtype.Timestamptz
AfterEventID pgtype.UUID
PageLimit int32
}
// List only the authenticated recipient's rows, optionally narrowed to one
// organization context. The caller resolves current source visibility before
// returning content.
func (q *Queries) ListNotificationInboxEvents(ctx context.Context, arg ListNotificationInboxEventsParams) ([]NotificationInboxEvent, error) {
rows, err := q.db.Query(ctx, listNotificationInboxEvents,
arg.RecipientUserID,
arg.OrganizationID,
arg.AfterOccurredAt,
arg.AfterEventID,
arg.PageLimit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []NotificationInboxEvent
for rows.Next() {
var i NotificationInboxEvent
if err := rows.Scan(
&i.RecipientUserID,
&i.EventID,
&i.OrganizationID,
&i.EventType,
&i.SchemaVersion,
&i.SourceType,
&i.SourceID,
&i.OccurredAt,
&i.ReadAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const markNotificationInboxEventRead = `-- name: MarkNotificationInboxEventRead :one
UPDATE notification_inbox_events
SET read_at = COALESCE(read_at, $1::timestamptz)
WHERE recipient_user_id = $2
AND organization_id = $3
AND event_id = $4
RETURNING
recipient_user_id,
event_id,
organization_id,
event_type,
schema_version,
source_type,
source_id,
occurred_at,
read_at
`
type MarkNotificationInboxEventReadParams struct {
ReadAt pgtype.Timestamptz
RecipientUserID pgtype.UUID
OrganizationID pgtype.UUID
EventID pgtype.UUID
}
// Persist the first read time under exact recipient and organization scope.
// Repeated calls preserve the original read timestamp.
func (q *Queries) MarkNotificationInboxEventRead(ctx context.Context, arg MarkNotificationInboxEventReadParams) (NotificationInboxEvent, error) {
row := q.db.QueryRow(ctx, markNotificationInboxEventRead,
arg.ReadAt,
arg.RecipientUserID,
arg.OrganizationID,
arg.EventID,
)
var i NotificationInboxEvent
err := row.Scan(
&i.RecipientUserID,
&i.EventID,
&i.OrganizationID,
&i.EventType,
&i.SchemaVersion,
&i.SourceType,
&i.SourceID,
&i.OccurredAt,
&i.ReadAt,
)
return i, err
}