279 lines
7.1 KiB
Go
279 lines
7.1 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 getNotificationOrganizationNameForRecipient = `-- name: GetNotificationOrganizationNameForRecipient :one
|
|
SELECT organizations.name
|
|
FROM organizations
|
|
INNER JOIN users ON users.id = $1
|
|
WHERE organizations.id = $2
|
|
AND (
|
|
(
|
|
users.scenario = 'candidate'
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM candidate_hidden_organizations
|
|
WHERE candidate_hidden_organizations.user_id = users.id
|
|
AND candidate_hidden_organizations.organization_id = organizations.id
|
|
)
|
|
)
|
|
OR (
|
|
users.scenario = 'employer'
|
|
AND EXISTS (
|
|
SELECT 1 FROM memberships
|
|
WHERE memberships.user_id = users.id
|
|
AND memberships.organization_id = organizations.id
|
|
AND memberships.state = 'active'
|
|
)
|
|
)
|
|
)
|
|
`
|
|
|
|
type GetNotificationOrganizationNameForRecipientParams struct {
|
|
RecipientUserID pgtype.UUID
|
|
OrganizationID pgtype.UUID
|
|
}
|
|
|
|
// Resolve the sender organization of a synthetic notice under the recipient's
|
|
// current standing, so the notice never outlives that standing. A candidate
|
|
// sees the name only while the organization is not hidden from them; an
|
|
// employer sees it only while they are an active member. No row means the
|
|
// content is no longer visible to this recipient.
|
|
func (q *Queries) GetNotificationOrganizationNameForRecipient(ctx context.Context, arg GetNotificationOrganizationNameForRecipientParams) (string, error) {
|
|
row := q.db.QueryRow(ctx, getNotificationOrganizationNameForRecipient, arg.RecipientUserID, arg.OrganizationID)
|
|
var name string
|
|
err := row.Scan(&name)
|
|
return name, 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 (
|
|
$3::uuid IS NULL
|
|
OR organization_id = $3::uuid
|
|
)
|
|
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 for the recipient, optionally under one exact
|
|
// organization context. A missing organization is the candidate cabinet,
|
|
// which spans the organizations that sent to it; the employer cabinet always
|
|
// names its organization. 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
|
|
}
|