mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-31 08:59:12 +02:00
369 lines
9.7 KiB
Go
369 lines
9.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: issue_view.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const clearDefaultIssueView = `-- name: ClearDefaultIssueView :exec
|
|
DELETE FROM issue_view_preference
|
|
WHERE workspace_id = $1
|
|
AND user_id = $2
|
|
AND scope_type = $3
|
|
AND scope_id = $4
|
|
`
|
|
|
|
type ClearDefaultIssueViewParams struct {
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID pgtype.UUID `json:"scope_id"`
|
|
}
|
|
|
|
func (q *Queries) ClearDefaultIssueView(ctx context.Context, arg ClearDefaultIssueViewParams) error {
|
|
_, err := q.db.Exec(ctx, clearDefaultIssueView,
|
|
arg.WorkspaceID,
|
|
arg.UserID,
|
|
arg.ScopeType,
|
|
arg.ScopeID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const countIssueViewsByWorkspace = `-- name: CountIssueViewsByWorkspace :one
|
|
SELECT count(*) FROM issue_view WHERE workspace_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountIssueViewsByWorkspace(ctx context.Context, workspaceID pgtype.UUID) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countIssueViewsByWorkspace, workspaceID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createIssueView = `-- name: CreateIssueView :one
|
|
INSERT INTO issue_view (
|
|
workspace_id, creator_id, name, icon, color, scope_type, scope_id,
|
|
visibility, definition, position
|
|
) VALUES (
|
|
$1, $2, $3,
|
|
$4, $5, $6,
|
|
$7, $8, $9,
|
|
$10
|
|
)
|
|
RETURNING id, workspace_id, creator_id, name, icon, color, scope_type, scope_id, visibility, definition, position, created_at, updated_at
|
|
`
|
|
|
|
type CreateIssueViewParams struct {
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
CreatorID pgtype.UUID `json:"creator_id"`
|
|
Name string `json:"name"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
Color pgtype.Text `json:"color"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID pgtype.UUID `json:"scope_id"`
|
|
Visibility string `json:"visibility"`
|
|
Definition []byte `json:"definition"`
|
|
Position float64 `json:"position"`
|
|
}
|
|
|
|
func (q *Queries) CreateIssueView(ctx context.Context, arg CreateIssueViewParams) (IssueView, error) {
|
|
row := q.db.QueryRow(ctx, createIssueView,
|
|
arg.WorkspaceID,
|
|
arg.CreatorID,
|
|
arg.Name,
|
|
arg.Icon,
|
|
arg.Color,
|
|
arg.ScopeType,
|
|
arg.ScopeID,
|
|
arg.Visibility,
|
|
arg.Definition,
|
|
arg.Position,
|
|
)
|
|
var i IssueView
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.CreatorID,
|
|
&i.Name,
|
|
&i.Icon,
|
|
&i.Color,
|
|
&i.ScopeType,
|
|
&i.ScopeID,
|
|
&i.Visibility,
|
|
&i.Definition,
|
|
&i.Position,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteIssueView = `-- name: DeleteIssueView :exec
|
|
DELETE FROM issue_view
|
|
WHERE id = $1 AND workspace_id = $2
|
|
`
|
|
|
|
type DeleteIssueViewParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteIssueView(ctx context.Context, arg DeleteIssueViewParams) error {
|
|
_, err := q.db.Exec(ctx, deleteIssueView, arg.ID, arg.WorkspaceID)
|
|
return err
|
|
}
|
|
|
|
const deleteIssueViewPreferencesByView = `-- name: DeleteIssueViewPreferencesByView :exec
|
|
DELETE FROM issue_view_preference
|
|
WHERE workspace_id = $1
|
|
AND default_view_id = $2
|
|
`
|
|
|
|
type DeleteIssueViewPreferencesByViewParams struct {
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
DefaultViewID pgtype.UUID `json:"default_view_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteIssueViewPreferencesByView(ctx context.Context, arg DeleteIssueViewPreferencesByViewParams) error {
|
|
_, err := q.db.Exec(ctx, deleteIssueViewPreferencesByView, arg.WorkspaceID, arg.DefaultViewID)
|
|
return err
|
|
}
|
|
|
|
const getDefaultIssueViewID = `-- name: GetDefaultIssueViewID :one
|
|
SELECT default_view_id FROM issue_view_preference
|
|
WHERE workspace_id = $1
|
|
AND user_id = $2
|
|
AND scope_type = $3
|
|
AND scope_id = $4
|
|
`
|
|
|
|
type GetDefaultIssueViewIDParams struct {
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID pgtype.UUID `json:"scope_id"`
|
|
}
|
|
|
|
func (q *Queries) GetDefaultIssueViewID(ctx context.Context, arg GetDefaultIssueViewIDParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, getDefaultIssueViewID,
|
|
arg.WorkspaceID,
|
|
arg.UserID,
|
|
arg.ScopeType,
|
|
arg.ScopeID,
|
|
)
|
|
var default_view_id pgtype.UUID
|
|
err := row.Scan(&default_view_id)
|
|
return default_view_id, err
|
|
}
|
|
|
|
const getIssueViewForUser = `-- name: GetIssueViewForUser :one
|
|
SELECT id, workspace_id, creator_id, name, icon, color, scope_type, scope_id, visibility, definition, position, created_at, updated_at FROM issue_view
|
|
WHERE id = $1
|
|
AND workspace_id = $2
|
|
AND (visibility = 'workspace' OR creator_id = $3)
|
|
`
|
|
|
|
type GetIssueViewForUserParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) GetIssueViewForUser(ctx context.Context, arg GetIssueViewForUserParams) (IssueView, error) {
|
|
row := q.db.QueryRow(ctx, getIssueViewForUser, arg.ID, arg.WorkspaceID, arg.UserID)
|
|
var i IssueView
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.CreatorID,
|
|
&i.Name,
|
|
&i.Icon,
|
|
&i.Color,
|
|
&i.ScopeType,
|
|
&i.ScopeID,
|
|
&i.Visibility,
|
|
&i.Definition,
|
|
&i.Position,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getMaxIssueViewPosition = `-- name: GetMaxIssueViewPosition :one
|
|
SELECT COALESCE(MAX(position), 0)::float8 AS max_position
|
|
FROM issue_view
|
|
WHERE workspace_id = $1
|
|
AND scope_type = $2
|
|
AND scope_id IS NOT DISTINCT FROM $3::uuid
|
|
`
|
|
|
|
type GetMaxIssueViewPositionParams struct {
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID pgtype.UUID `json:"scope_id"`
|
|
}
|
|
|
|
func (q *Queries) GetMaxIssueViewPosition(ctx context.Context, arg GetMaxIssueViewPositionParams) (float64, error) {
|
|
row := q.db.QueryRow(ctx, getMaxIssueViewPosition, arg.WorkspaceID, arg.ScopeType, arg.ScopeID)
|
|
var max_position float64
|
|
err := row.Scan(&max_position)
|
|
return max_position, err
|
|
}
|
|
|
|
const listIssueViews = `-- name: ListIssueViews :many
|
|
SELECT id, workspace_id, creator_id, name, icon, color, scope_type, scope_id, visibility, definition, position, created_at, updated_at FROM issue_view
|
|
WHERE workspace_id = $1
|
|
AND scope_type = $2
|
|
AND scope_id IS NOT DISTINCT FROM $3::uuid
|
|
AND (visibility = 'workspace' OR creator_id = $4)
|
|
ORDER BY position ASC, created_at ASC
|
|
`
|
|
|
|
type ListIssueViewsParams struct {
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID pgtype.UUID `json:"scope_id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) ListIssueViews(ctx context.Context, arg ListIssueViewsParams) ([]IssueView, error) {
|
|
rows, err := q.db.Query(ctx, listIssueViews,
|
|
arg.WorkspaceID,
|
|
arg.ScopeType,
|
|
arg.ScopeID,
|
|
arg.UserID,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []IssueView{}
|
|
for rows.Next() {
|
|
var i IssueView
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.CreatorID,
|
|
&i.Name,
|
|
&i.Icon,
|
|
&i.Color,
|
|
&i.ScopeType,
|
|
&i.ScopeID,
|
|
&i.Visibility,
|
|
&i.Definition,
|
|
&i.Position,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const lockWorkspaceForIssueViewCreate = `-- name: LockWorkspaceForIssueViewCreate :one
|
|
SELECT id FROM workspace WHERE id = $1 FOR UPDATE
|
|
`
|
|
|
|
// Serializes the per-workspace 100-view cap and conflicts with workspace
|
|
// deletion so a view cannot be inserted behind the delete sweep.
|
|
func (q *Queries) LockWorkspaceForIssueViewCreate(ctx context.Context, workspaceID pgtype.UUID) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, lockWorkspaceForIssueViewCreate, workspaceID)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const setDefaultIssueView = `-- name: SetDefaultIssueView :exec
|
|
INSERT INTO issue_view_preference (
|
|
workspace_id, user_id, scope_type, scope_id, default_view_id
|
|
) VALUES (
|
|
$1, $2, $3,
|
|
$4, $5
|
|
)
|
|
ON CONFLICT (workspace_id, user_id, scope_type, scope_id)
|
|
DO UPDATE SET default_view_id = EXCLUDED.default_view_id, updated_at = now()
|
|
`
|
|
|
|
type SetDefaultIssueViewParams struct {
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID pgtype.UUID `json:"scope_id"`
|
|
DefaultViewID pgtype.UUID `json:"default_view_id"`
|
|
}
|
|
|
|
func (q *Queries) SetDefaultIssueView(ctx context.Context, arg SetDefaultIssueViewParams) error {
|
|
_, err := q.db.Exec(ctx, setDefaultIssueView,
|
|
arg.WorkspaceID,
|
|
arg.UserID,
|
|
arg.ScopeType,
|
|
arg.ScopeID,
|
|
arg.DefaultViewID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const updateIssueView = `-- name: UpdateIssueView :one
|
|
UPDATE issue_view SET
|
|
name = $1,
|
|
icon = $2,
|
|
color = $3,
|
|
visibility = $4,
|
|
definition = $5,
|
|
updated_at = now()
|
|
WHERE id = $6 AND workspace_id = $7
|
|
RETURNING id, workspace_id, creator_id, name, icon, color, scope_type, scope_id, visibility, definition, position, created_at, updated_at
|
|
`
|
|
|
|
type UpdateIssueViewParams struct {
|
|
Name string `json:"name"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
Color pgtype.Text `json:"color"`
|
|
Visibility string `json:"visibility"`
|
|
Definition []byte `json:"definition"`
|
|
ID pgtype.UUID `json:"id"`
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateIssueView(ctx context.Context, arg UpdateIssueViewParams) (IssueView, error) {
|
|
row := q.db.QueryRow(ctx, updateIssueView,
|
|
arg.Name,
|
|
arg.Icon,
|
|
arg.Color,
|
|
arg.Visibility,
|
|
arg.Definition,
|
|
arg.ID,
|
|
arg.WorkspaceID,
|
|
)
|
|
var i IssueView
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.CreatorID,
|
|
&i.Name,
|
|
&i.Icon,
|
|
&i.Color,
|
|
&i.ScopeType,
|
|
&i.ScopeID,
|
|
&i.Visibility,
|
|
&i.Definition,
|
|
&i.Position,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|