Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go
4.4 KB
Raw Blame
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: notification_preference.sql

package db

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const getNotificationPreference = `-- name: GetNotificationPreference :one
SELECT id, workspace_id, user_id, preferences, updated_at FROM notification_preference
WHERE workspace_id = $1 AND user_id = $2
`

type GetNotificationPreferenceParams struct {
	WorkspaceID pgtype.UUID `json:"workspace_id"`
	UserID      pgtype.UUID `json:"user_id"`
}

func (q *Queries) GetNotificationPreference(ctx context.Context, arg GetNotificationPreferenceParams) (NotificationPreference, error) {
	row := q.db.QueryRow(ctx, getNotificationPreference, arg.WorkspaceID, arg.UserID)
	var i NotificationPreference
	err := row.Scan(
		&i.ID,
		&i.WorkspaceID,
		&i.UserID,
		&i.Preferences,
		&i.UpdatedAt,
	)
	return i, err
}

const listNotificationPreferencesByUsers = `-- name: ListNotificationPreferencesByUsers :many
SELECT id, workspace_id, user_id, preferences, updated_at FROM notification_preference
WHERE workspace_id = $1 AND user_id = ANY($2::uuid[])
`

type ListNotificationPreferencesByUsersParams struct {
	WorkspaceID pgtype.UUID   `json:"workspace_id"`
	UserIds     []pgtype.UUID `json:"user_ids"`
}

func (q *Queries) ListNotificationPreferencesByUsers(ctx context.Context, arg ListNotificationPreferencesByUsersParams) ([]NotificationPreference, error) {
	rows, err := q.db.Query(ctx, listNotificationPreferencesByUsers, arg.WorkspaceID, arg.UserIds)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []NotificationPreference{}
	for rows.Next() {
		var i NotificationPreference
		if err := rows.Scan(
			&i.ID,
			&i.WorkspaceID,
			&i.UserID,
			&i.Preferences,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const patchNotificationPreference = `-- name: PatchNotificationPreference :one
INSERT INTO notification_preference (workspace_id, user_id, preferences)
VALUES ($1, $2, $3)
ON CONFLICT (workspace_id, user_id)
DO UPDATE SET
    preferences = notification_preference.preferences || EXCLUDED.preferences,
    updated_at = now()
RETURNING id, workspace_id, user_id, preferences, updated_at
`

type PatchNotificationPreferenceParams struct {
	WorkspaceID pgtype.UUID `json:"workspace_id"`
	UserID      pgtype.UUID `json:"user_id"`
	Preferences []byte      `json:"preferences"`
}

func (q *Queries) PatchNotificationPreference(ctx context.Context, arg PatchNotificationPreferenceParams) (NotificationPreference, error) {
	row := q.db.QueryRow(ctx, patchNotificationPreference, arg.WorkspaceID, arg.UserID, arg.Preferences)
	var i NotificationPreference
	err := row.Scan(
		&i.ID,
		&i.WorkspaceID,
		&i.UserID,
		&i.Preferences,
		&i.UpdatedAt,
	)
	return i, err
}

const resolveAutoArchivePrompt = `-- name: ResolveAutoArchivePrompt :exec
UPDATE notification_preference
SET preferences = (preferences - 'auto_archive_prompt') || $1::jsonb,
    updated_at = now()
WHERE user_id = $2
  AND preferences ->> 'auto_archive_prompt' IS NOT NULL
`

type ResolveAutoArchivePromptParams struct {
	Preferences []byte      `json:"preferences"`
	UserID      pgtype.UUID `json:"user_id"`
}

// Answers the one-time auto-archive question in every workspace where the
// user still has it pending: merges their choice and drops the marker.
func (q *Queries) ResolveAutoArchivePrompt(ctx context.Context, arg ResolveAutoArchivePromptParams) error {
	_, err := q.db.Exec(ctx, resolveAutoArchivePrompt, arg.Preferences, arg.UserID)
	return err
}

const upsertNotificationPreference = `-- name: UpsertNotificationPreference :one
INSERT INTO notification_preference (workspace_id, user_id, preferences)
VALUES ($1, $2, $3)
ON CONFLICT (workspace_id, user_id)
DO UPDATE SET preferences = $3, updated_at = now()
RETURNING id, workspace_id, user_id, preferences, updated_at
`

type UpsertNotificationPreferenceParams struct {
	WorkspaceID pgtype.UUID `json:"workspace_id"`
	UserID      pgtype.UUID `json:"user_id"`
	Preferences []byte      `json:"preferences"`
}

func (q *Queries) UpsertNotificationPreference(ctx context.Context, arg UpsertNotificationPreferenceParams) (NotificationPreference, error) {
	row := q.db.QueryRow(ctx, upsertNotificationPreference, arg.WorkspaceID, arg.UserID, arg.Preferences)
	var i NotificationPreference
	err := row.Scan(
		&i.ID,
		&i.WorkspaceID,
		&i.UserID,
		&i.Preferences,
		&i.UpdatedAt,
	)
	return i, err
}