411 lines
10 KiB
Go
411 lines
10 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: invitation_answers.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const acceptInvitation = `-- name: AcceptInvitation :one
|
|
UPDATE invitations
|
|
SET
|
|
state = 'accepted',
|
|
version = $1,
|
|
responded_at = $2,
|
|
updated_at = $2
|
|
WHERE
|
|
organization_id = $3
|
|
AND id = $4
|
|
AND state IN ('delivered', 'viewed')
|
|
AND version = $5
|
|
AND terms_version = $6
|
|
AND response_deadline_at > $2
|
|
AND $1::bigint = $5::bigint + 1
|
|
RETURNING id
|
|
`
|
|
|
|
type AcceptInvitationParams struct {
|
|
NextVersion int64
|
|
AcceptedAt pgtype.Timestamptz
|
|
OrganizationID pgtype.UUID
|
|
InvitationID pgtype.UUID
|
|
ExpectedVersion int64
|
|
TermsVersion int64
|
|
}
|
|
|
|
// The compare-and-swap of an acceptance: it applies only to a delivered or
|
|
// viewed invitation at the version and the terms version that the candidate
|
|
// read, and before its deadline. The answer is the acceptance time, and the
|
|
// deadline is kept.
|
|
func (q *Queries) AcceptInvitation(ctx context.Context, arg AcceptInvitationParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, acceptInvitation,
|
|
arg.NextVersion,
|
|
arg.AcceptedAt,
|
|
arg.OrganizationID,
|
|
arg.InvitationID,
|
|
arg.ExpectedVersion,
|
|
arg.TermsVersion,
|
|
)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const declineInvitation = `-- name: DeclineInvitation :one
|
|
UPDATE invitations
|
|
SET
|
|
state = 'declined',
|
|
version = $1,
|
|
responded_at = $2,
|
|
updated_at = $2
|
|
WHERE
|
|
organization_id = $3
|
|
AND id = $4
|
|
AND state IN ('delivered', 'viewed', 'counter')
|
|
AND version = $5
|
|
AND response_deadline_at > $2
|
|
AND $1::bigint = $5::bigint + 1
|
|
RETURNING id
|
|
`
|
|
|
|
type DeclineInvitationParams struct {
|
|
NextVersion int64
|
|
DeclinedAt pgtype.Timestamptz
|
|
OrganizationID pgtype.UUID
|
|
InvitationID pgtype.UUID
|
|
ExpectedVersion int64
|
|
}
|
|
|
|
// The compare-and-swap of a decline: it applies only to an answerable
|
|
// invitation at the version the caller read and before its deadline.
|
|
func (q *Queries) DeclineInvitation(ctx context.Context, arg DeclineInvitationParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, declineInvitation,
|
|
arg.NextVersion,
|
|
arg.DeclinedAt,
|
|
arg.OrganizationID,
|
|
arg.InvitationID,
|
|
arg.ExpectedVersion,
|
|
)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const getInvitationAcceptResult = `-- name: GetInvitationAcceptResult :one
|
|
SELECT
|
|
invitation_id,
|
|
outcome
|
|
FROM invitation_accept_results
|
|
WHERE scope_hash = $1
|
|
`
|
|
|
|
type GetInvitationAcceptResultRow struct {
|
|
InvitationID pgtype.UUID
|
|
Outcome string
|
|
}
|
|
|
|
func (q *Queries) GetInvitationAcceptResult(ctx context.Context, scopeHash []byte) (GetInvitationAcceptResultRow, error) {
|
|
row := q.db.QueryRow(ctx, getInvitationAcceptResult, scopeHash)
|
|
var i GetInvitationAcceptResultRow
|
|
err := row.Scan(&i.InvitationID, &i.Outcome)
|
|
return i, err
|
|
}
|
|
|
|
const getInvitationDeclineResult = `-- name: GetInvitationDeclineResult :one
|
|
SELECT
|
|
invitation_id,
|
|
outcome
|
|
FROM invitation_decline_results
|
|
WHERE scope_hash = $1
|
|
`
|
|
|
|
type GetInvitationDeclineResultRow struct {
|
|
InvitationID pgtype.UUID
|
|
Outcome string
|
|
}
|
|
|
|
func (q *Queries) GetInvitationDeclineResult(ctx context.Context, scopeHash []byte) (GetInvitationDeclineResultRow, error) {
|
|
row := q.db.QueryRow(ctx, getInvitationDeclineResult, scopeHash)
|
|
var i GetInvitationDeclineResultRow
|
|
err := row.Scan(&i.InvitationID, &i.Outcome)
|
|
return i, err
|
|
}
|
|
|
|
const insertInvitationAcceptResult = `-- name: InsertInvitationAcceptResult :exec
|
|
INSERT INTO invitation_accept_results (
|
|
scope_hash,
|
|
invitation_id,
|
|
outcome
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3
|
|
)
|
|
`
|
|
|
|
type InsertInvitationAcceptResultParams struct {
|
|
ScopeHash []byte
|
|
InvitationID pgtype.UUID
|
|
Outcome string
|
|
}
|
|
|
|
func (q *Queries) InsertInvitationAcceptResult(ctx context.Context, arg InsertInvitationAcceptResultParams) error {
|
|
_, err := q.db.Exec(ctx, insertInvitationAcceptResult, arg.ScopeHash, arg.InvitationID, arg.Outcome)
|
|
return err
|
|
}
|
|
|
|
const insertInvitationDecline = `-- name: InsertInvitationDecline :exec
|
|
INSERT INTO invitation_declines (
|
|
invitation_id,
|
|
organization_id,
|
|
reason,
|
|
comment,
|
|
declined_at
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5
|
|
)
|
|
`
|
|
|
|
type InsertInvitationDeclineParams struct {
|
|
InvitationID pgtype.UUID
|
|
OrganizationID pgtype.UUID
|
|
Reason string
|
|
Comment pgtype.Text
|
|
DeclinedAt pgtype.Timestamptz
|
|
}
|
|
|
|
func (q *Queries) InsertInvitationDecline(ctx context.Context, arg InsertInvitationDeclineParams) error {
|
|
_, err := q.db.Exec(ctx, insertInvitationDecline,
|
|
arg.InvitationID,
|
|
arg.OrganizationID,
|
|
arg.Reason,
|
|
arg.Comment,
|
|
arg.DeclinedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertInvitationDeclineResult = `-- name: InsertInvitationDeclineResult :exec
|
|
INSERT INTO invitation_decline_results (
|
|
scope_hash,
|
|
invitation_id,
|
|
outcome
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3
|
|
)
|
|
`
|
|
|
|
type InsertInvitationDeclineResultParams struct {
|
|
ScopeHash []byte
|
|
InvitationID pgtype.UUID
|
|
Outcome string
|
|
}
|
|
|
|
func (q *Queries) InsertInvitationDeclineResult(ctx context.Context, arg InsertInvitationDeclineResultParams) error {
|
|
_, err := q.db.Exec(ctx, insertInvitationDeclineResult, arg.ScopeHash, arg.InvitationID, arg.Outcome)
|
|
return err
|
|
}
|
|
|
|
const lockCandidateInvitation = `-- name: LockCandidateInvitation :one
|
|
SELECT id
|
|
FROM invitations
|
|
WHERE
|
|
candidate_id = $1
|
|
AND id = $2
|
|
AND delivered_at IS NOT NULL
|
|
FOR UPDATE
|
|
`
|
|
|
|
type LockCandidateInvitationParams struct {
|
|
CandidateID pgtype.UUID
|
|
InvitationID pgtype.UUID
|
|
}
|
|
|
|
// Lock one delivered invitation addressed to the candidate. Only the
|
|
// invitation row is locked, never the organization.
|
|
func (q *Queries) LockCandidateInvitation(ctx context.Context, arg LockCandidateInvitationParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, lockCandidateInvitation, arg.CandidateID, arg.InvitationID)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const readCandidateInvitationEntry = `-- name: ReadCandidateInvitationEntry :one
|
|
SELECT
|
|
invitation.id,
|
|
invitation.organization_id,
|
|
invitation.candidate_id,
|
|
invitation.need_id,
|
|
invitation.need_requirements_version,
|
|
invitation.state,
|
|
invitation.expiry_reason,
|
|
invitation.version,
|
|
invitation.terms_version,
|
|
invitation.response_period_days,
|
|
invitation.policy_version_id,
|
|
invitation.response_deadline_at,
|
|
invitation.salary_raise_used,
|
|
invitation.created_by,
|
|
invitation.created_at,
|
|
invitation.updated_at,
|
|
invitation.delivered_at,
|
|
invitation.viewed_at,
|
|
invitation.responded_at,
|
|
terms.terms::text AS terms,
|
|
organization.name AS organization_name
|
|
FROM invitations AS invitation
|
|
INNER JOIN invitation_terms_versions AS terms
|
|
ON terms.invitation_id = invitation.id
|
|
AND terms.version = invitation.terms_version
|
|
INNER JOIN organizations AS organization
|
|
ON organization.id = invitation.organization_id
|
|
WHERE
|
|
invitation.candidate_id = $1
|
|
AND invitation.id = $2
|
|
AND invitation.delivered_at IS NOT NULL
|
|
`
|
|
|
|
type ReadCandidateInvitationEntryParams struct {
|
|
CandidateID pgtype.UUID
|
|
InvitationID pgtype.UUID
|
|
}
|
|
|
|
type ReadCandidateInvitationEntryRow struct {
|
|
ID pgtype.UUID
|
|
OrganizationID pgtype.UUID
|
|
CandidateID pgtype.UUID
|
|
NeedID pgtype.UUID
|
|
NeedRequirementsVersion pgtype.Int8
|
|
State string
|
|
ExpiryReason pgtype.Text
|
|
Version int64
|
|
TermsVersion int64
|
|
ResponsePeriodDays int16
|
|
PolicyVersionID pgtype.UUID
|
|
ResponseDeadlineAt pgtype.Timestamptz
|
|
SalaryRaiseUsed bool
|
|
CreatedBy pgtype.UUID
|
|
CreatedAt pgtype.Timestamptz
|
|
UpdatedAt pgtype.Timestamptz
|
|
DeliveredAt pgtype.Timestamptz
|
|
ViewedAt pgtype.Timestamptz
|
|
RespondedAt pgtype.Timestamptz
|
|
Terms string
|
|
OrganizationName string
|
|
}
|
|
|
|
// Read one delivered invitation addressed to the candidate with the current
|
|
// name of the organization that sent it. A draft and an invitation of
|
|
// another candidate find nothing.
|
|
func (q *Queries) ReadCandidateInvitationEntry(ctx context.Context, arg ReadCandidateInvitationEntryParams) (ReadCandidateInvitationEntryRow, error) {
|
|
row := q.db.QueryRow(ctx, readCandidateInvitationEntry, arg.CandidateID, arg.InvitationID)
|
|
var i ReadCandidateInvitationEntryRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.OrganizationID,
|
|
&i.CandidateID,
|
|
&i.NeedID,
|
|
&i.NeedRequirementsVersion,
|
|
&i.State,
|
|
&i.ExpiryReason,
|
|
&i.Version,
|
|
&i.TermsVersion,
|
|
&i.ResponsePeriodDays,
|
|
&i.PolicyVersionID,
|
|
&i.ResponseDeadlineAt,
|
|
&i.SalaryRaiseUsed,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeliveredAt,
|
|
&i.ViewedAt,
|
|
&i.RespondedAt,
|
|
&i.Terms,
|
|
&i.OrganizationName,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const readInvitationDecline = `-- name: ReadInvitationDecline :one
|
|
SELECT
|
|
invitation_id,
|
|
organization_id,
|
|
reason,
|
|
comment,
|
|
declined_at
|
|
FROM invitation_declines
|
|
WHERE
|
|
organization_id = $1
|
|
AND invitation_id = $2
|
|
`
|
|
|
|
type ReadInvitationDeclineParams struct {
|
|
OrganizationID pgtype.UUID
|
|
InvitationID pgtype.UUID
|
|
}
|
|
|
|
func (q *Queries) ReadInvitationDecline(ctx context.Context, arg ReadInvitationDeclineParams) (InvitationDecline, error) {
|
|
row := q.db.QueryRow(ctx, readInvitationDecline, arg.OrganizationID, arg.InvitationID)
|
|
var i InvitationDecline
|
|
err := row.Scan(
|
|
&i.InvitationID,
|
|
&i.OrganizationID,
|
|
&i.Reason,
|
|
&i.Comment,
|
|
&i.DeclinedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const recordInvitationView = `-- name: RecordInvitationView :one
|
|
UPDATE invitations
|
|
SET
|
|
state = 'viewed',
|
|
version = $1,
|
|
viewed_at = $2,
|
|
updated_at = $2
|
|
WHERE
|
|
organization_id = $3
|
|
AND id = $4
|
|
AND state = 'delivered'
|
|
AND version = $5
|
|
AND response_deadline_at > $2
|
|
AND $1::bigint = $5::bigint + 1
|
|
RETURNING id
|
|
`
|
|
|
|
type RecordInvitationViewParams struct {
|
|
NextVersion int64
|
|
ViewedAt pgtype.Timestamptz
|
|
OrganizationID pgtype.UUID
|
|
InvitationID pgtype.UUID
|
|
ExpectedVersion int64
|
|
}
|
|
|
|
// The compare-and-swap of the first view: it applies only to a delivered
|
|
// invitation at the version the caller read and before its deadline, and it
|
|
// keeps the deadline.
|
|
func (q *Queries) RecordInvitationView(ctx context.Context, arg RecordInvitationViewParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, recordInvitationView,
|
|
arg.NextVersion,
|
|
arg.ViewedAt,
|
|
arg.OrganizationID,
|
|
arg.InvitationID,
|
|
arg.ExpectedVersion,
|
|
)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|