Module project, commit, submission
All checks were successful
Build and Release / release (push) Successful in 1m15s
All checks were successful
Build and Release / release (push) Successful in 1m15s
This commit is contained in:
206
internal/gen/sqlc/commit.sql.go
Normal file
206
internal/gen/sqlc/commit.sql.go
Normal file
@@ -0,0 +1,206 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: commit.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createCommit = `-- name: CreateCommit :one
|
||||
INSERT INTO commits (
|
||||
project_id, snapshot_json, snapshot_hash, user_id, edit_summary
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5
|
||||
)
|
||||
RETURNING id, project_id, snapshot_json, snapshot_hash, user_id, edit_summary, is_deleted, created_at
|
||||
`
|
||||
|
||||
type CreateCommitParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
SnapshotJson json.RawMessage `json:"snapshot_json"`
|
||||
SnapshotHash pgtype.Text `json:"snapshot_hash"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EditSummary pgtype.Text `json:"edit_summary"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCommit(ctx context.Context, arg CreateCommitParams) (Commit, error) {
|
||||
row := q.db.QueryRow(ctx, createCommit,
|
||||
arg.ProjectID,
|
||||
arg.SnapshotJson,
|
||||
arg.SnapshotHash,
|
||||
arg.UserID,
|
||||
arg.EditSummary,
|
||||
)
|
||||
var i Commit
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteCommit = `-- name: DeleteCommit :exec
|
||||
UPDATE commits
|
||||
SET is_deleted = true
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteCommit(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteCommit, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getCommitById = `-- name: GetCommitById :one
|
||||
SELECT id, project_id, snapshot_json, snapshot_hash, user_id, edit_summary, is_deleted, created_at
|
||||
FROM commits
|
||||
WHERE id = $1 AND is_deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetCommitById(ctx context.Context, id pgtype.UUID) (Commit, error) {
|
||||
row := q.db.QueryRow(ctx, getCommitById, id)
|
||||
var i Commit
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCommitsByIDs = `-- name: GetCommitsByIDs :many
|
||||
SELECT id, project_id, snapshot_json, snapshot_hash, user_id, edit_summary, is_deleted, created_at FROM commits WHERE id = ANY($1::uuid[]) AND is_deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetCommitsByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]Commit, error) {
|
||||
rows, err := q.db.Query(ctx, getCommitsByIDs, dollar_1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Commit{}
|
||||
for rows.Next() {
|
||||
var i Commit
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getCommitsByProjectID = `-- name: GetCommitsByProjectID :many
|
||||
SELECT id, project_id, snapshot_json, snapshot_hash, user_id, edit_summary, is_deleted, created_at
|
||||
FROM commits
|
||||
WHERE project_id = $1 AND is_deleted = false
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) GetCommitsByProjectID(ctx context.Context, projectID pgtype.UUID) ([]Commit, error) {
|
||||
rows, err := q.db.Query(ctx, getCommitsByProjectID, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Commit{}
|
||||
for rows.Next() {
|
||||
var i Commit
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const searchCommits = `-- name: SearchCommits :many
|
||||
SELECT id, project_id, snapshot_json, snapshot_hash, user_id, edit_summary, is_deleted, created_at
|
||||
FROM commits
|
||||
WHERE is_deleted = false
|
||||
AND ($1::uuid IS NULL OR project_id = $1)
|
||||
AND ($2::uuid IS NULL OR user_id = $2)
|
||||
AND ($3::uuid IS NULL OR id < $3::uuid)
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $4
|
||||
`
|
||||
|
||||
type SearchCommitsParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CursorID pgtype.UUID `json:"cursor_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchCommits(ctx context.Context, arg SearchCommitsParams) ([]Commit, error) {
|
||||
rows, err := q.db.Query(ctx, searchCommits,
|
||||
arg.ProjectID,
|
||||
arg.UserID,
|
||||
arg.CursorID,
|
||||
arg.Limit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Commit{}
|
||||
for rows.Next() {
|
||||
var i Commit
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -10,6 +10,17 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Commit struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
SnapshotJson json.RawMessage `json:"snapshot_json"`
|
||||
SnapshotHash pgtype.Text `json:"snapshot_hash"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EditSummary pgtype.Text `json:"edit_summary"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Entity struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -56,30 +67,24 @@ type Media struct {
|
||||
}
|
||||
|
||||
type Project struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestRevisionID pgtype.UUID `json:"latest_revision_id"`
|
||||
VersionCount int32 `json:"version_count"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Revision struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
VersionNo int32 `json:"version_no"`
|
||||
SnapshotJson json.RawMessage `json:"snapshot_json"`
|
||||
SnapshotHash pgtype.Text `json:"snapshot_hash"`
|
||||
ParentID pgtype.UUID `json:"parent_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EditSummary pgtype.Text `json:"edit_summary"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
type ProjectMember struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role int16 `json:"role"`
|
||||
InvitedBy pgtype.UUID `json:"invited_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Role struct {
|
||||
@@ -91,16 +96,17 @@ type Role struct {
|
||||
}
|
||||
|
||||
type Submission struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RevisionID pgtype.UUID `json:"revision_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
SubmittedAt pgtype.Timestamptz `json:"submitted_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
CommitID pgtype.UUID `json:"commit_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
|
||||
@@ -11,13 +11,80 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const addProjectMember = `-- name: AddProjectMember :one
|
||||
INSERT INTO project_members (
|
||||
project_id, user_id, role, invited_by
|
||||
) VALUES (
|
||||
$1, $2, $3, $4
|
||||
)
|
||||
RETURNING project_id, user_id, role, invited_by, created_at
|
||||
`
|
||||
|
||||
type AddProjectMemberParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role int16 `json:"role"`
|
||||
InvitedBy pgtype.UUID `json:"invited_by"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddProjectMember(ctx context.Context, arg AddProjectMemberParams) (ProjectMember, error) {
|
||||
row := q.db.QueryRow(ctx, addProjectMember,
|
||||
arg.ProjectID,
|
||||
arg.UserID,
|
||||
arg.Role,
|
||||
arg.InvitedBy,
|
||||
)
|
||||
var i ProjectMember
|
||||
err := row.Scan(
|
||||
&i.ProjectID,
|
||||
&i.UserID,
|
||||
&i.Role,
|
||||
&i.InvitedBy,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const changeProjectOwner = `-- name: ChangeProjectOwner :exec
|
||||
UPDATE projects
|
||||
SET user_id = $2, updated_at = NOW()
|
||||
WHERE id = $1 AND is_deleted = false
|
||||
`
|
||||
|
||||
type ChangeProjectOwnerParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) ChangeProjectOwner(ctx context.Context, arg ChangeProjectOwnerParams) error {
|
||||
_, err := q.db.Exec(ctx, changeProjectOwner, arg.ID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const checkProjectPermission = `-- name: CheckProjectPermission :one
|
||||
SELECT role FROM project_members
|
||||
WHERE project_id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type CheckProjectPermissionParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CheckProjectPermission(ctx context.Context, arg CheckProjectPermissionParams) (int16, error) {
|
||||
row := q.db.QueryRow(ctx, checkProjectPermission, arg.ProjectID, arg.UserID)
|
||||
var role int16
|
||||
err := row.Scan(&role)
|
||||
return role, err
|
||||
}
|
||||
|
||||
const countProjects = `-- name: CountProjects :one
|
||||
SELECT count(*)
|
||||
FROM projects p
|
||||
WHERE p.is_deleted = false
|
||||
AND (
|
||||
$1::text[] IS NULL
|
||||
OR p.project_status = ANY($1::text[])
|
||||
$1::smallint[] IS NULL
|
||||
OR p.project_status = ANY($1::smallint[])
|
||||
)
|
||||
AND ($2::uuid[] IS NULL OR p.user_id = ANY($2::uuid[]))
|
||||
AND (
|
||||
@@ -30,7 +97,7 @@ WHERE p.is_deleted = false
|
||||
`
|
||||
|
||||
type CountProjectsParams struct {
|
||||
Statuses []string `json:"statuses"`
|
||||
Statuses []int16 `json:"statuses"`
|
||||
UserIds []pgtype.UUID `json:"user_ids"`
|
||||
SearchText pgtype.Text `json:"search_text"`
|
||||
CreatedFrom pgtype.Timestamptz `json:"created_from"`
|
||||
@@ -57,7 +124,7 @@ INSERT INTO projects (
|
||||
$1, $2, $3, $4
|
||||
)
|
||||
RETURNING
|
||||
id, title, description, latest_revision_id, version_count, project_status, locked_by, is_deleted, user_id, created_at, updated_at,
|
||||
id, title, description, latest_commit_id, project_status, locked_by, is_deleted, user_id, created_at, updated_at,
|
||||
json_build_object(
|
||||
'id', u.id,
|
||||
'email', u.email,
|
||||
@@ -65,8 +132,9 @@ RETURNING
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS user,
|
||||
'{}'::uuid[] AS commit_ids,
|
||||
'{}'::uuid[] AS submission_ids
|
||||
'[]'::json AS commits,
|
||||
'{}'::uuid[] AS submission_ids,
|
||||
'[]'::json AS members
|
||||
`
|
||||
|
||||
type CreateProjectParams struct {
|
||||
@@ -77,20 +145,20 @@ type CreateProjectParams struct {
|
||||
}
|
||||
|
||||
type CreateProjectRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestRevisionID pgtype.UUID `json:"latest_revision_id"`
|
||||
VersionCount int32 `json:"version_count"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
User []byte `json:"user"`
|
||||
CommitIds []pgtype.UUID `json:"commit_ids"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
User []byte `json:"user"`
|
||||
Commits []byte `json:"commits"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
Members []byte `json:"members"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateProject(ctx context.Context, arg CreateProjectParams) (CreateProjectRow, error) {
|
||||
@@ -105,8 +173,7 @@ func (q *Queries) CreateProject(ctx context.Context, arg CreateProjectParams) (C
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.LatestRevisionID,
|
||||
&i.VersionCount,
|
||||
&i.LatestCommitID,
|
||||
&i.ProjectStatus,
|
||||
&i.LockedBy,
|
||||
&i.IsDeleted,
|
||||
@@ -114,8 +181,9 @@ func (q *Queries) CreateProject(ctx context.Context, arg CreateProjectParams) (C
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.User,
|
||||
&i.CommitIds,
|
||||
&i.Commits,
|
||||
&i.SubmissionIds,
|
||||
&i.Members,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -134,11 +202,12 @@ func (q *Queries) DeleteProject(ctx context.Context, id pgtype.UUID) error {
|
||||
|
||||
const getProjectById = `-- name: GetProjectById :one
|
||||
SELECT
|
||||
p.id, p.title, p.description, p.latest_revision_id, p.version_count, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
p.id, p.title, p.description, p.latest_commit_id, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
COALESCE(
|
||||
(SELECT array_agg(id) FROM revisions WHERE project_id = p.id),
|
||||
'{}'
|
||||
)::uuid[] AS commit_ids,
|
||||
(SELECT json_agg(json_build_object('id', c.id, 'edit_summary', c.edit_summary) ORDER BY c.created_at DESC)
|
||||
FROM commits c WHERE c.project_id = p.id AND c.is_deleted = false),
|
||||
'[]'
|
||||
)::json AS commits,
|
||||
COALESCE(
|
||||
(SELECT array_agg(id) FROM submissions WHERE project_id = p.id),
|
||||
'{}'
|
||||
@@ -149,7 +218,18 @@ SELECT
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS user
|
||||
)::json AS user,
|
||||
COALESCE(
|
||||
(SELECT json_agg(json_build_object(
|
||||
'user_id', pm.user_id, 'role', pm.role,
|
||||
'display_name', mup.display_name, 'avatar_url', mup.avatar_url
|
||||
) ORDER BY pm.role ASC, pm.created_at ASC)
|
||||
FROM project_members pm
|
||||
JOIN users mu ON pm.user_id = mu.id
|
||||
LEFT JOIN user_profiles mup ON mu.id = mup.user_id
|
||||
WHERE pm.project_id = p.id),
|
||||
'[]'
|
||||
)::json AS members
|
||||
FROM projects p
|
||||
JOIN users u ON p.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
@@ -157,20 +237,20 @@ WHERE p.id = $1 AND p.is_deleted = false
|
||||
`
|
||||
|
||||
type GetProjectByIdRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestRevisionID pgtype.UUID `json:"latest_revision_id"`
|
||||
VersionCount int32 `json:"version_count"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
CommitIds []pgtype.UUID `json:"commit_ids"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
User []byte `json:"user"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
Commits []byte `json:"commits"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
User []byte `json:"user"`
|
||||
Members []byte `json:"members"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetProjectById(ctx context.Context, id pgtype.UUID) (GetProjectByIdRow, error) {
|
||||
@@ -180,25 +260,29 @@ func (q *Queries) GetProjectById(ctx context.Context, id pgtype.UUID) (GetProjec
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.LatestRevisionID,
|
||||
&i.VersionCount,
|
||||
&i.LatestCommitID,
|
||||
&i.ProjectStatus,
|
||||
&i.LockedBy,
|
||||
&i.IsDeleted,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CommitIds,
|
||||
&i.Commits,
|
||||
&i.SubmissionIds,
|
||||
&i.User,
|
||||
&i.Members,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getProjectsByIDs = `-- name: GetProjectsByIDs :many
|
||||
SELECT
|
||||
p.id, p.title, p.description, p.latest_revision_id, p.version_count, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
COALESCE((SELECT array_agg(id) FROM revisions WHERE project_id = p.id), '{}')::uuid[] AS commit_ids,
|
||||
p.id, p.title, p.description, p.latest_commit_id, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
COALESCE(
|
||||
(SELECT json_agg(json_build_object('id', c.id, 'edit_summary', c.edit_summary) ORDER BY c.created_at DESC)
|
||||
FROM commits c WHERE c.project_id = p.id AND c.is_deleted = false),
|
||||
'[]'
|
||||
)::json AS commits,
|
||||
COALESCE((SELECT array_agg(id) FROM submissions WHERE project_id = p.id), '{}')::uuid[] AS submission_ids,
|
||||
json_build_object(
|
||||
'id', u.id,
|
||||
@@ -206,7 +290,18 @@ SELECT
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS user
|
||||
)::json AS user,
|
||||
COALESCE(
|
||||
(SELECT json_agg(json_build_object(
|
||||
'user_id', pm.user_id, 'role', pm.role,
|
||||
'display_name', mup.display_name, 'avatar_url', mup.avatar_url
|
||||
) ORDER BY pm.role ASC, pm.created_at ASC)
|
||||
FROM project_members pm
|
||||
JOIN users mu ON pm.user_id = mu.id
|
||||
LEFT JOIN user_profiles mup ON mu.id = mup.user_id
|
||||
WHERE pm.project_id = p.id),
|
||||
'[]'
|
||||
)::json AS members
|
||||
FROM projects p
|
||||
JOIN users u ON p.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
@@ -214,20 +309,20 @@ WHERE p.id = ANY($1::uuid[]) AND p.is_deleted = false
|
||||
`
|
||||
|
||||
type GetProjectsByIDsRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestRevisionID pgtype.UUID `json:"latest_revision_id"`
|
||||
VersionCount int32 `json:"version_count"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
CommitIds []pgtype.UUID `json:"commit_ids"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
User []byte `json:"user"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
Commits []byte `json:"commits"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
User []byte `json:"user"`
|
||||
Members []byte `json:"members"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetProjectsByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]GetProjectsByIDsRow, error) {
|
||||
@@ -243,17 +338,17 @@ func (q *Queries) GetProjectsByIDs(ctx context.Context, dollar_1 []pgtype.UUID)
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.LatestRevisionID,
|
||||
&i.VersionCount,
|
||||
&i.LatestCommitID,
|
||||
&i.ProjectStatus,
|
||||
&i.LockedBy,
|
||||
&i.IsDeleted,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CommitIds,
|
||||
&i.Commits,
|
||||
&i.SubmissionIds,
|
||||
&i.User,
|
||||
&i.Members,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -267,11 +362,12 @@ func (q *Queries) GetProjectsByIDs(ctx context.Context, dollar_1 []pgtype.UUID)
|
||||
|
||||
const getProjectsByUserId = `-- name: GetProjectsByUserId :many
|
||||
SELECT
|
||||
p.id, p.title, p.description, p.latest_revision_id, p.version_count, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
p.id, p.title, p.description, p.latest_commit_id, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
COALESCE(
|
||||
(SELECT array_agg(id) FROM revisions WHERE project_id = p.id),
|
||||
'{}'
|
||||
)::uuid[] AS commit_ids,
|
||||
(SELECT json_agg(json_build_object('id', c.id, 'edit_summary', c.edit_summary) ORDER BY c.created_at DESC)
|
||||
FROM commits c WHERE c.project_id = p.id AND c.is_deleted = false),
|
||||
'[]'
|
||||
)::json AS commits,
|
||||
COALESCE(
|
||||
(SELECT array_agg(id) FROM submissions WHERE project_id = p.id),
|
||||
'{}'
|
||||
@@ -282,11 +378,22 @@ SELECT
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS user
|
||||
)::json AS user,
|
||||
COALESCE(
|
||||
(SELECT json_agg(json_build_object(
|
||||
'user_id', pm.user_id, 'role', pm.role,
|
||||
'display_name', mup.display_name, 'avatar_url', mup.avatar_url
|
||||
) ORDER BY pm.role ASC, pm.created_at ASC)
|
||||
FROM project_members pm
|
||||
JOIN users mu ON pm.user_id = mu.id
|
||||
LEFT JOIN user_profiles mup ON mu.id = mup.user_id
|
||||
WHERE pm.project_id = p.id),
|
||||
'[]'
|
||||
)::json AS members
|
||||
FROM projects p
|
||||
JOIN users u ON p.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
WHERE p.user_id = $1
|
||||
WHERE (p.user_id = $1 OR EXISTS (SELECT 1 FROM project_members pm2 WHERE pm2.project_id = p.id AND pm2.user_id = $1))
|
||||
AND p.is_deleted = false
|
||||
AND ($2::uuid IS NULL OR p.id < $2::uuid)
|
||||
ORDER BY p.updated_at DESC
|
||||
@@ -300,20 +407,20 @@ type GetProjectsByUserIdParams struct {
|
||||
}
|
||||
|
||||
type GetProjectsByUserIdRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestRevisionID pgtype.UUID `json:"latest_revision_id"`
|
||||
VersionCount int32 `json:"version_count"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
CommitIds []pgtype.UUID `json:"commit_ids"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
User []byte `json:"user"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
Commits []byte `json:"commits"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
User []byte `json:"user"`
|
||||
Members []byte `json:"members"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetProjectsByUserId(ctx context.Context, arg GetProjectsByUserIdParams) ([]GetProjectsByUserIdRow, error) {
|
||||
@@ -329,17 +436,17 @@ func (q *Queries) GetProjectsByUserId(ctx context.Context, arg GetProjectsByUser
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.LatestRevisionID,
|
||||
&i.VersionCount,
|
||||
&i.LatestCommitID,
|
||||
&i.ProjectStatus,
|
||||
&i.LockedBy,
|
||||
&i.IsDeleted,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CommitIds,
|
||||
&i.Commits,
|
||||
&i.SubmissionIds,
|
||||
&i.User,
|
||||
&i.Members,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -351,13 +458,29 @@ func (q *Queries) GetProjectsByUserId(ctx context.Context, arg GetProjectsByUser
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const removeProjectMember = `-- name: RemoveProjectMember :exec
|
||||
DELETE FROM project_members
|
||||
WHERE project_id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type RemoveProjectMemberParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) RemoveProjectMember(ctx context.Context, arg RemoveProjectMemberParams) error {
|
||||
_, err := q.db.Exec(ctx, removeProjectMember, arg.ProjectID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const searchProjects = `-- name: SearchProjects :many
|
||||
SELECT
|
||||
p.id, p.title, p.description, p.latest_revision_id, p.version_count, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
p.id, p.title, p.description, p.latest_commit_id, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
COALESCE(
|
||||
(SELECT array_agg(id) FROM revisions WHERE project_id = p.id),
|
||||
'{}'
|
||||
)::uuid[] AS commit_ids,
|
||||
(SELECT json_agg(json_build_object('id', c.id, 'edit_summary', c.edit_summary) ORDER BY c.created_at DESC)
|
||||
FROM commits c WHERE c.project_id = p.id AND c.is_deleted = false),
|
||||
'[]'
|
||||
)::json AS commits,
|
||||
COALESCE(
|
||||
(SELECT array_agg(id) FROM submissions WHERE project_id = p.id),
|
||||
'{}'
|
||||
@@ -368,14 +491,25 @@ SELECT
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS user
|
||||
)::json AS user,
|
||||
COALESCE(
|
||||
(SELECT json_agg(json_build_object(
|
||||
'user_id', pm.user_id, 'role', pm.role,
|
||||
'display_name', mup.display_name, 'avatar_url', mup.avatar_url
|
||||
) ORDER BY pm.role ASC, pm.created_at ASC)
|
||||
FROM project_members pm
|
||||
JOIN users mu ON pm.user_id = mu.id
|
||||
LEFT JOIN user_profiles mup ON mu.id = mup.user_id
|
||||
WHERE pm.project_id = p.id),
|
||||
'[]'
|
||||
)::json AS members
|
||||
FROM projects p
|
||||
JOIN users u ON p.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
WHERE p.is_deleted = false
|
||||
AND (
|
||||
$1::text[] IS NULL
|
||||
OR p.project_status = ANY($1::text[])
|
||||
$1::smallint[] IS NULL
|
||||
OR p.project_status = ANY($1::smallint[])
|
||||
)
|
||||
AND ($2::uuid[] IS NULL OR p.user_id = ANY($2::uuid[]))
|
||||
AND (
|
||||
@@ -398,7 +532,7 @@ OFFSET $8
|
||||
`
|
||||
|
||||
type SearchProjectsParams struct {
|
||||
Statuses []string `json:"statuses"`
|
||||
Statuses []int16 `json:"statuses"`
|
||||
UserIds []pgtype.UUID `json:"user_ids"`
|
||||
SearchText pgtype.Text `json:"search_text"`
|
||||
CreatedFrom pgtype.Timestamptz `json:"created_from"`
|
||||
@@ -410,20 +544,20 @@ type SearchProjectsParams struct {
|
||||
}
|
||||
|
||||
type SearchProjectsRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestRevisionID pgtype.UUID `json:"latest_revision_id"`
|
||||
VersionCount int32 `json:"version_count"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
CommitIds []pgtype.UUID `json:"commit_ids"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
User []byte `json:"user"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
Commits []byte `json:"commits"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
User []byte `json:"user"`
|
||||
Members []byte `json:"members"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchProjects(ctx context.Context, arg SearchProjectsParams) ([]SearchProjectsRow, error) {
|
||||
@@ -449,17 +583,17 @@ func (q *Queries) SearchProjects(ctx context.Context, arg SearchProjectsParams)
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.LatestRevisionID,
|
||||
&i.VersionCount,
|
||||
&i.LatestCommitID,
|
||||
&i.ProjectStatus,
|
||||
&i.LockedBy,
|
||||
&i.IsDeleted,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CommitIds,
|
||||
&i.Commits,
|
||||
&i.SubmissionIds,
|
||||
&i.User,
|
||||
&i.Members,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -471,22 +605,37 @@ func (q *Queries) SearchProjects(ctx context.Context, arg SearchProjectsParams)
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateLatestCommit = `-- name: UpdateLatestCommit :exec
|
||||
UPDATE projects
|
||||
SET latest_commit_id = $2, updated_at = NOW()
|
||||
WHERE id = $1 AND is_deleted = false
|
||||
`
|
||||
|
||||
type UpdateLatestCommitParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateLatestCommit(ctx context.Context, arg UpdateLatestCommitParams) error {
|
||||
_, err := q.db.Exec(ctx, updateLatestCommit, arg.ID, arg.LatestCommitID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateProject = `-- name: UpdateProject :one
|
||||
UPDATE projects
|
||||
SET
|
||||
title = COALESCE($1, title),
|
||||
description = COALESCE($2, description),
|
||||
latest_revision_id = COALESCE($3, latest_revision_id),
|
||||
version_count = COALESCE($4, version_count),
|
||||
project_status = COALESCE($5, status),
|
||||
locked_by = COALESCE($6, locked_by),
|
||||
latest_commit_id = COALESCE($3, latest_commit_id),
|
||||
project_status = COALESCE($4, status),
|
||||
locked_by = COALESCE($5, locked_by),
|
||||
updated_at = NOW()
|
||||
FROM projects p
|
||||
JOIN users u ON p.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
WHERE p.id = $7 AND p.is_deleted = false
|
||||
WHERE p.id = $6 AND p.is_deleted = false
|
||||
RETURNING
|
||||
p.id, p.title, p.description, p.latest_revision_id, p.version_count, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
p.id, p.title, p.description, p.latest_commit_id, p.project_status, p.locked_by, p.is_deleted, p.user_id, p.created_at, p.updated_at,
|
||||
json_build_object(
|
||||
'id', u.id,
|
||||
'email', u.email,
|
||||
@@ -494,43 +643,56 @@ RETURNING
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS user,
|
||||
COALESCE((SELECT array_agg(id) FROM revisions WHERE project_id = projects.id), '{}')::uuid[] AS commit_ids,
|
||||
COALESCE((SELECT array_agg(id) FROM submissions WHERE project_id = projects.id), '{}')::uuid[] AS submission_ids
|
||||
COALESCE(
|
||||
(SELECT json_agg(json_build_object('id', c.id, 'edit_summary', c.edit_summary) ORDER BY c.created_at DESC)
|
||||
FROM commits c WHERE c.project_id = projects.id AND c.is_deleted = false),
|
||||
'[]'
|
||||
)::json AS commits,
|
||||
COALESCE((SELECT array_agg(id) FROM submissions WHERE project_id = projects.id), '{}')::uuid[] AS submission_ids,
|
||||
COALESCE(
|
||||
(SELECT json_agg(json_build_object(
|
||||
'user_id', pm.user_id, 'role', pm.role,
|
||||
'display_name', mup.display_name, 'avatar_url', mup.avatar_url
|
||||
) ORDER BY pm.role ASC, pm.created_at ASC)
|
||||
FROM project_members pm
|
||||
JOIN users mu ON pm.user_id = mu.id
|
||||
LEFT JOIN user_profiles mup ON mu.id = mup.user_id
|
||||
WHERE pm.project_id = projects.id),
|
||||
'[]'
|
||||
)::json AS members
|
||||
`
|
||||
|
||||
type UpdateProjectParams struct {
|
||||
Title pgtype.Text `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestRevisionID pgtype.UUID `json:"latest_revision_id"`
|
||||
VersionCount pgtype.Int4 `json:"version_count"`
|
||||
Status pgtype.Int2 `json:"status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title pgtype.Text `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
Status pgtype.Int2 `json:"status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
type UpdateProjectRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestRevisionID pgtype.UUID `json:"latest_revision_id"`
|
||||
VersionCount int32 `json:"version_count"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
User []byte `json:"user"`
|
||||
CommitIds []pgtype.UUID `json:"commit_ids"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
LatestCommitID pgtype.UUID `json:"latest_commit_id"`
|
||||
ProjectStatus int16 `json:"project_status"`
|
||||
LockedBy pgtype.UUID `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
User []byte `json:"user"`
|
||||
Commits []byte `json:"commits"`
|
||||
SubmissionIds []pgtype.UUID `json:"submission_ids"`
|
||||
Members []byte `json:"members"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateProject(ctx context.Context, arg UpdateProjectParams) (UpdateProjectRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateProject,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.LatestRevisionID,
|
||||
arg.VersionCount,
|
||||
arg.LatestCommitID,
|
||||
arg.Status,
|
||||
arg.LockedBy,
|
||||
arg.ID,
|
||||
@@ -540,8 +702,7 @@ func (q *Queries) UpdateProject(ctx context.Context, arg UpdateProjectParams) (U
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.LatestRevisionID,
|
||||
&i.VersionCount,
|
||||
&i.LatestCommitID,
|
||||
&i.ProjectStatus,
|
||||
&i.LockedBy,
|
||||
&i.IsDeleted,
|
||||
@@ -549,8 +710,35 @@ func (q *Queries) UpdateProject(ctx context.Context, arg UpdateProjectParams) (U
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.User,
|
||||
&i.CommitIds,
|
||||
&i.Commits,
|
||||
&i.SubmissionIds,
|
||||
&i.Members,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateProjectMemberRole = `-- name: UpdateProjectMemberRole :one
|
||||
UPDATE project_members
|
||||
SET role = $3
|
||||
WHERE project_id = $1 AND user_id = $2
|
||||
RETURNING project_id, user_id, role, invited_by, created_at
|
||||
`
|
||||
|
||||
type UpdateProjectMemberRoleParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role int16 `json:"role"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateProjectMemberRole(ctx context.Context, arg UpdateProjectMemberRoleParams) (ProjectMember, error) {
|
||||
row := q.db.QueryRow(ctx, updateProjectMemberRole, arg.ProjectID, arg.UserID, arg.Role)
|
||||
var i ProjectMember
|
||||
err := row.Scan(
|
||||
&i.ProjectID,
|
||||
&i.UserID,
|
||||
&i.Role,
|
||||
&i.InvitedBy,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: revision.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createRevision = `-- name: CreateRevision :one
|
||||
INSERT INTO revisions (
|
||||
project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7
|
||||
)
|
||||
RETURNING id, project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary, is_deleted, created_at
|
||||
`
|
||||
|
||||
type CreateRevisionParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
VersionNo int32 `json:"version_no"`
|
||||
SnapshotJson json.RawMessage `json:"snapshot_json"`
|
||||
SnapshotHash pgtype.Text `json:"snapshot_hash"`
|
||||
ParentID pgtype.UUID `json:"parent_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EditSummary pgtype.Text `json:"edit_summary"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateRevision(ctx context.Context, arg CreateRevisionParams) (Revision, error) {
|
||||
row := q.db.QueryRow(ctx, createRevision,
|
||||
arg.ProjectID,
|
||||
arg.VersionNo,
|
||||
arg.SnapshotJson,
|
||||
arg.SnapshotHash,
|
||||
arg.ParentID,
|
||||
arg.UserID,
|
||||
arg.EditSummary,
|
||||
)
|
||||
var i Revision
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.VersionNo,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.ParentID,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteRevision = `-- name: DeleteRevision :exec
|
||||
UPDATE revisions
|
||||
SET is_deleted = true
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteRevision(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteRevision, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getRevisionById = `-- name: GetRevisionById :one
|
||||
SELECT id, project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary, is_deleted, created_at
|
||||
FROM revisions
|
||||
WHERE id = $1 AND is_deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetRevisionById(ctx context.Context, id pgtype.UUID) (Revision, error) {
|
||||
row := q.db.QueryRow(ctx, getRevisionById, id)
|
||||
var i Revision
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.VersionNo,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.ParentID,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getRevisionsByIDs = `-- name: GetRevisionsByIDs :many
|
||||
SELECT id, project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary, is_deleted, created_at FROM revisions WHERE id = ANY($1::uuid[]) AND is_deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetRevisionsByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]Revision, error) {
|
||||
rows, err := q.db.Query(ctx, getRevisionsByIDs, dollar_1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Revision{}
|
||||
for rows.Next() {
|
||||
var i Revision
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.VersionNo,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.ParentID,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const searchRevisions = `-- name: SearchRevisions :many
|
||||
SELECT id, project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary, is_deleted, created_at
|
||||
FROM revisions
|
||||
WHERE is_deleted = false
|
||||
AND ($1::uuid IS NULL OR project_id = $1)
|
||||
AND ($2::uuid IS NULL OR user_id = $2)
|
||||
AND ($3::uuid IS NULL OR id < $3::uuid)
|
||||
ORDER BY version_no DESC
|
||||
LIMIT $4
|
||||
`
|
||||
|
||||
type SearchRevisionsParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CursorID pgtype.UUID `json:"cursor_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchRevisions(ctx context.Context, arg SearchRevisionsParams) ([]Revision, error) {
|
||||
rows, err := q.db.Query(ctx, searchRevisions,
|
||||
arg.ProjectID,
|
||||
arg.UserID,
|
||||
arg.CursorID,
|
||||
arg.Limit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Revision{}
|
||||
for rows.Next() {
|
||||
var i Revision
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.VersionNo,
|
||||
&i.SnapshotJson,
|
||||
&i.SnapshotHash,
|
||||
&i.ParentID,
|
||||
&i.UserID,
|
||||
&i.EditSummary,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -16,26 +16,27 @@ SELECT count(*)
|
||||
FROM submissions s
|
||||
WHERE s.is_deleted = false
|
||||
AND ($1::uuid IS NULL OR s.project_id = $1)
|
||||
AND ($2::uuid IS NULL OR s.submitted_by = $2)
|
||||
AND ($2::uuid[] IS NULL OR uv.user_id = ANY($2::uuid[]))
|
||||
AND ($3::uuid IS NULL OR s.reviewed_by = $3)
|
||||
AND (
|
||||
$4::text[] IS NULL
|
||||
OR s.status = ANY($4::text[])
|
||||
$4::smallint[] IS NULL
|
||||
OR s.status = ANY($4::smallint[])
|
||||
)
|
||||
AND ($5::timestamptz IS NULL OR s.submitted_at >= $5::timestamptz)
|
||||
AND ($6::timestamptz IS NULL OR s.submitted_at <= $6::timestamptz)
|
||||
AND ($5::timestamptz IS NULL OR s.created_at >= $5::timestamptz)
|
||||
AND ($6::timestamptz IS NULL OR s.created_at <= $6::timestamptz)
|
||||
AND (
|
||||
$7::text IS NULL OR
|
||||
s.id::text ILIKE '%' || $7::text || '%' OR
|
||||
s.review_note ILIKE '%' || $7::text || '%'
|
||||
s.review_note ILIKE '%' || $7::text || '%' OR
|
||||
s.content ILIKE '%' || $7::text || '%'
|
||||
)
|
||||
`
|
||||
|
||||
type CountSubmissionsParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
UserIds []pgtype.UUID `json:"user_ids"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
Statuses []string `json:"statuses"`
|
||||
Statuses []int16 `json:"statuses"`
|
||||
CreatedFrom pgtype.Timestamptz `json:"created_from"`
|
||||
CreatedTo pgtype.Timestamptz `json:"created_to"`
|
||||
SearchText pgtype.Text `json:"search_text"`
|
||||
@@ -44,7 +45,7 @@ type CountSubmissionsParams struct {
|
||||
func (q *Queries) CountSubmissions(ctx context.Context, arg CountSubmissionsParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countSubmissions,
|
||||
arg.ProjectID,
|
||||
arg.SubmittedBy,
|
||||
arg.UserIds,
|
||||
arg.ReviewedBy,
|
||||
arg.Statuses,
|
||||
arg.CreatedFrom,
|
||||
@@ -57,81 +58,85 @@ func (q *Queries) CountSubmissions(ctx context.Context, arg CountSubmissionsPara
|
||||
}
|
||||
|
||||
const createSubmission = `-- name: CreateSubmission :one
|
||||
WITH inserted_submission AS (
|
||||
INSERT INTO submissions (
|
||||
project_id, revision_id, submitted_by, status
|
||||
) VALUES (
|
||||
$1, $2, $3, $4
|
||||
)
|
||||
RETURNING id, project_id, revision_id, submitted_by, submitted_at, status, reviewed_by, reviewed_at, review_note, is_deleted
|
||||
INSERT INTO submissions (
|
||||
project_id, commit_id, user_id, status, content
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5
|
||||
)
|
||||
SELECT
|
||||
s.id, s.project_id, s.revision_id, s.submitted_by, s.submitted_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.is_deleted,
|
||||
json_build_object(
|
||||
'id', u.id,
|
||||
'email', u.email,
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS submitter,
|
||||
CASE WHEN s.reviewed_by IS NOT NULL THEN
|
||||
json_build_object(
|
||||
RETURNING
|
||||
id, project_id, commit_id, user_id, created_at, status, reviewed_by, reviewed_at, review_note, content, is_deleted,
|
||||
(
|
||||
SELECT json_build_object(
|
||||
'id', u.id,
|
||||
'email', u.email,
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)
|
||||
FROM users u
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
WHERE u.id = submissions.user_id
|
||||
)::json AS user,
|
||||
(
|
||||
SELECT json_build_object(
|
||||
'id', ru.id,
|
||||
'email', ru.email,
|
||||
'display_name', rup.display_name,
|
||||
'full_name', rup.full_name,
|
||||
'avatar_url', rup.avatar_url
|
||||
)::json
|
||||
ELSE NULL::json END AS reviewer
|
||||
FROM inserted_submission s
|
||||
JOIN users u ON s.submitted_by = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
LEFT JOIN users ru ON s.reviewed_by = ru.id
|
||||
LEFT JOIN user_profiles rup ON ru.id = rup.user_id
|
||||
)
|
||||
FROM users ru
|
||||
LEFT JOIN user_profiles rup ON ru.id = rup.user_id
|
||||
WHERE ru.id = submissions.reviewed_by
|
||||
)::json AS reviewer
|
||||
`
|
||||
|
||||
type CreateSubmissionParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RevisionID pgtype.UUID `json:"revision_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
Status int16 `json:"status"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
CommitID pgtype.UUID `json:"commit_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Status int16 `json:"status"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
}
|
||||
|
||||
type CreateSubmissionRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RevisionID pgtype.UUID `json:"revision_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
SubmittedAt pgtype.Timestamptz `json:"submitted_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Submitter []byte `json:"submitter"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
CommitID pgtype.UUID `json:"commit_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
User []byte `json:"user"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateSubmission(ctx context.Context, arg CreateSubmissionParams) (CreateSubmissionRow, error) {
|
||||
row := q.db.QueryRow(ctx, createSubmission,
|
||||
arg.ProjectID,
|
||||
arg.RevisionID,
|
||||
arg.SubmittedBy,
|
||||
arg.CommitID,
|
||||
arg.UserID,
|
||||
arg.Status,
|
||||
arg.Content,
|
||||
)
|
||||
var i CreateSubmissionRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.RevisionID,
|
||||
&i.SubmittedBy,
|
||||
&i.SubmittedAt,
|
||||
&i.CommitID,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.ReviewNote,
|
||||
&i.Content,
|
||||
&i.IsDeleted,
|
||||
&i.Submitter,
|
||||
&i.User,
|
||||
&i.Reviewer,
|
||||
)
|
||||
return i, err
|
||||
@@ -150,14 +155,14 @@ func (q *Queries) DeleteSubmission(ctx context.Context, id pgtype.UUID) error {
|
||||
|
||||
const getSubmissionById = `-- name: GetSubmissionById :one
|
||||
SELECT
|
||||
s.id, s.project_id, s.revision_id, s.submitted_by, s.submitted_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.is_deleted,
|
||||
s.id, s.project_id, s.commit_id, s.user_id, s.created_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.content, s.is_deleted,
|
||||
json_build_object(
|
||||
'id', u.id,
|
||||
'email', u.email,
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS submitter,
|
||||
)::json AS user,
|
||||
CASE WHEN s.reviewed_by IS NOT NULL THEN
|
||||
json_build_object(
|
||||
'id', ru.id,
|
||||
@@ -168,7 +173,7 @@ SELECT
|
||||
)::json
|
||||
ELSE NULL::json END AS reviewer
|
||||
FROM submissions s
|
||||
JOIN users u ON s.submitted_by = u.id
|
||||
JOIN users u ON s.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
LEFT JOIN users ru ON s.reviewed_by = ru.id
|
||||
LEFT JOIN user_profiles rup ON ru.id = rup.user_id
|
||||
@@ -176,18 +181,19 @@ WHERE s.id = $1 AND s.is_deleted = false
|
||||
`
|
||||
|
||||
type GetSubmissionByIdRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RevisionID pgtype.UUID `json:"revision_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
SubmittedAt pgtype.Timestamptz `json:"submitted_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Submitter []byte `json:"submitter"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
CommitID pgtype.UUID `json:"commit_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
User []byte `json:"user"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetSubmissionById(ctx context.Context, id pgtype.UUID) (GetSubmissionByIdRow, error) {
|
||||
@@ -196,15 +202,16 @@ func (q *Queries) GetSubmissionById(ctx context.Context, id pgtype.UUID) (GetSub
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.RevisionID,
|
||||
&i.SubmittedBy,
|
||||
&i.SubmittedAt,
|
||||
&i.CommitID,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.ReviewNote,
|
||||
&i.Content,
|
||||
&i.IsDeleted,
|
||||
&i.Submitter,
|
||||
&i.User,
|
||||
&i.Reviewer,
|
||||
)
|
||||
return i, err
|
||||
@@ -212,14 +219,14 @@ func (q *Queries) GetSubmissionById(ctx context.Context, id pgtype.UUID) (GetSub
|
||||
|
||||
const getSubmissionsByIDs = `-- name: GetSubmissionsByIDs :many
|
||||
SELECT
|
||||
s.id, s.project_id, s.revision_id, s.submitted_by, s.submitted_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.is_deleted,
|
||||
s.id, s.project_id, s.commit_id, s.user_id, s.created_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.content, s.is_deleted,
|
||||
json_build_object(
|
||||
'id', u.id,
|
||||
'email', u.email,
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS submitter,
|
||||
)::json AS user,
|
||||
CASE WHEN s.reviewed_by IS NOT NULL THEN
|
||||
json_build_object(
|
||||
'id', ru.id,
|
||||
@@ -230,7 +237,7 @@ SELECT
|
||||
)::json
|
||||
ELSE NULL::json END AS reviewer
|
||||
FROM submissions s
|
||||
JOIN users u ON s.submitted_by = u.id
|
||||
JOIN users u ON s.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
LEFT JOIN users ru ON s.reviewed_by = ru.id
|
||||
LEFT JOIN user_profiles rup ON ru.id = rup.user_id
|
||||
@@ -238,18 +245,19 @@ WHERE s.id = ANY($1::uuid[]) AND s.is_deleted = false
|
||||
`
|
||||
|
||||
type GetSubmissionsByIDsRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RevisionID pgtype.UUID `json:"revision_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
SubmittedAt pgtype.Timestamptz `json:"submitted_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Submitter []byte `json:"submitter"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
CommitID pgtype.UUID `json:"commit_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
User []byte `json:"user"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetSubmissionsByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]GetSubmissionsByIDsRow, error) {
|
||||
@@ -264,15 +272,16 @@ func (q *Queries) GetSubmissionsByIDs(ctx context.Context, dollar_1 []pgtype.UUI
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.RevisionID,
|
||||
&i.SubmittedBy,
|
||||
&i.SubmittedAt,
|
||||
&i.CommitID,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.ReviewNote,
|
||||
&i.Content,
|
||||
&i.IsDeleted,
|
||||
&i.Submitter,
|
||||
&i.User,
|
||||
&i.Reviewer,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -287,14 +296,14 @@ func (q *Queries) GetSubmissionsByIDs(ctx context.Context, dollar_1 []pgtype.UUI
|
||||
|
||||
const searchSubmissions = `-- name: SearchSubmissions :many
|
||||
SELECT
|
||||
s.id, s.project_id, s.revision_id, s.submitted_by, s.submitted_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.is_deleted,
|
||||
s.id, s.project_id, s.commit_id, s.user_id, s.created_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.content, s.is_deleted,
|
||||
json_build_object(
|
||||
'id', u.id,
|
||||
'email', u.email,
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS submitter,
|
||||
)::json AS user,
|
||||
CASE WHEN s.reviewed_by IS NOT NULL THEN
|
||||
json_build_object(
|
||||
'id', ru.id,
|
||||
@@ -305,42 +314,43 @@ SELECT
|
||||
)::json
|
||||
ELSE NULL::json END AS reviewer
|
||||
FROM submissions s
|
||||
JOIN users u ON s.submitted_by = u.id
|
||||
JOIN users u ON s.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
LEFT JOIN users ru ON s.reviewed_by = ru.id
|
||||
LEFT JOIN user_profiles rup ON ru.id = rup.user_id
|
||||
WHERE s.is_deleted = false
|
||||
AND ($1::uuid IS NULL OR s.project_id = $1)
|
||||
AND ($2::uuid IS NULL OR s.submitted_by = $2)
|
||||
AND ($2::uuid[] IS NULL OR uv.user_id = ANY($2::uuid[]))
|
||||
AND ($3::uuid IS NULL OR s.reviewed_by = $3)
|
||||
AND (
|
||||
$4::text[] IS NULL
|
||||
OR s.status = ANY($4::text[])
|
||||
$4::smallint[] IS NULL
|
||||
OR s.status = ANY($4::smallint[])
|
||||
)
|
||||
AND ($5::timestamptz IS NULL OR s.submitted_at >= $5::timestamptz)
|
||||
AND ($6::timestamptz IS NULL OR s.submitted_at <= $6::timestamptz)
|
||||
AND ($5::timestamptz IS NULL OR s.created_at >= $5::timestamptz)
|
||||
AND ($6::timestamptz IS NULL OR s.created_at <= $6::timestamptz)
|
||||
AND (
|
||||
$7::text IS NULL OR
|
||||
s.id::text ILIKE '%' || $7::text || '%' OR
|
||||
s.review_note ILIKE '%' || $7::text || '%'
|
||||
s.review_note ILIKE '%' || $7::text || '%' OR
|
||||
s.content ILIKE '%' || $7::text || '%'
|
||||
)
|
||||
ORDER BY
|
||||
CASE WHEN $8 = 'submitted_at' AND $9 = 'asc' THEN s.submitted_at END ASC,
|
||||
CASE WHEN $8 = 'submitted_at' AND $9 = 'desc' THEN s.submitted_at END DESC,
|
||||
CASE WHEN $8 = 'created_at' AND $9 = 'asc' THEN s.created_at END ASC,
|
||||
CASE WHEN $8 = 'created_at' AND $9 = 'desc' THEN s.created_at END DESC,
|
||||
CASE WHEN $8 = 'reviewed_at' AND $9 = 'asc' THEN s.reviewed_at END ASC,
|
||||
CASE WHEN $8 = 'reviewed_at' AND $9 = 'desc' THEN s.reviewed_at END DESC,
|
||||
CASE WHEN $8 = 'status' AND $9 = 'asc' THEN s.status END ASC,
|
||||
CASE WHEN $8 = 'status' AND $9 = 'desc' THEN s.status END DESC,
|
||||
CASE WHEN $8 IS NULL THEN s.submitted_at END DESC
|
||||
CASE WHEN $8 IS NULL THEN s.created_at END DESC
|
||||
LIMIT $11
|
||||
OFFSET $10
|
||||
`
|
||||
|
||||
type SearchSubmissionsParams struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
UserIds []pgtype.UUID `json:"user_ids"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
Statuses []string `json:"statuses"`
|
||||
Statuses []int16 `json:"statuses"`
|
||||
CreatedFrom pgtype.Timestamptz `json:"created_from"`
|
||||
CreatedTo pgtype.Timestamptz `json:"created_to"`
|
||||
SearchText pgtype.Text `json:"search_text"`
|
||||
@@ -351,24 +361,25 @@ type SearchSubmissionsParams struct {
|
||||
}
|
||||
|
||||
type SearchSubmissionsRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RevisionID pgtype.UUID `json:"revision_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
SubmittedAt pgtype.Timestamptz `json:"submitted_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Submitter []byte `json:"submitter"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
CommitID pgtype.UUID `json:"commit_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
User []byte `json:"user"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchSubmissions(ctx context.Context, arg SearchSubmissionsParams) ([]SearchSubmissionsRow, error) {
|
||||
rows, err := q.db.Query(ctx, searchSubmissions,
|
||||
arg.ProjectID,
|
||||
arg.SubmittedBy,
|
||||
arg.UserIds,
|
||||
arg.ReviewedBy,
|
||||
arg.Statuses,
|
||||
arg.CreatedFrom,
|
||||
@@ -389,15 +400,16 @@ func (q *Queries) SearchSubmissions(ctx context.Context, arg SearchSubmissionsPa
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.RevisionID,
|
||||
&i.SubmittedBy,
|
||||
&i.SubmittedAt,
|
||||
&i.CommitID,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.ReviewNote,
|
||||
&i.Content,
|
||||
&i.IsDeleted,
|
||||
&i.Submitter,
|
||||
&i.User,
|
||||
&i.Reviewer,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -415,23 +427,23 @@ UPDATE submissions
|
||||
SET
|
||||
status = COALESCE($1, status),
|
||||
reviewed_by = COALESCE($2, reviewed_by),
|
||||
reviewed_at = COALESCE($3, reviewed_at),
|
||||
review_note = COALESCE($4, review_note)
|
||||
review_note = COALESCE($3, review_note),
|
||||
content = COALESCE($4, content)
|
||||
FROM submissions s
|
||||
JOIN users u ON s.submitted_by = u.id
|
||||
JOIN users u ON s.user_id = u.id
|
||||
LEFT JOIN user_profiles up ON u.id = up.user_id
|
||||
LEFT JOIN users ru ON s.reviewed_by = ru.id
|
||||
LEFT JOIN user_profiles rup ON ru.id = rup.user_id
|
||||
WHERE s.id = $5
|
||||
RETURNING
|
||||
s.id, s.project_id, s.revision_id, s.submitted_by, s.submitted_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.is_deleted,
|
||||
s.id, s.project_id, s.commit_id, s.user_id, s.created_at, s.status, s.reviewed_by, s.reviewed_at, s.review_note, s.content, s.is_deleted,
|
||||
json_build_object(
|
||||
'id', u.id,
|
||||
'email', u.email,
|
||||
'display_name', up.display_name,
|
||||
'full_name', up.full_name,
|
||||
'avatar_url', up.avatar_url
|
||||
)::json AS submitter,
|
||||
)::json AS user,
|
||||
CASE WHEN s.reviewed_by IS NOT NULL THEN
|
||||
json_build_object(
|
||||
'id', ru.id,
|
||||
@@ -444,49 +456,51 @@ RETURNING
|
||||
`
|
||||
|
||||
type UpdateSubmissionParams struct {
|
||||
Status pgtype.Int2 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Status pgtype.Int2 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
type UpdateSubmissionRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RevisionID pgtype.UUID `json:"revision_id"`
|
||||
SubmittedBy pgtype.UUID `json:"submitted_by"`
|
||||
SubmittedAt pgtype.Timestamptz `json:"submitted_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Submitter []byte `json:"submitter"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
CommitID pgtype.UUID `json:"commit_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
ReviewNote pgtype.Text `json:"review_note"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
User []byte `json:"user"`
|
||||
Reviewer []byte `json:"reviewer"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateSubmission(ctx context.Context, arg UpdateSubmissionParams) (UpdateSubmissionRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateSubmission,
|
||||
arg.Status,
|
||||
arg.ReviewedBy,
|
||||
arg.ReviewedAt,
|
||||
arg.ReviewNote,
|
||||
arg.Content,
|
||||
arg.ID,
|
||||
)
|
||||
var i UpdateSubmissionRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.RevisionID,
|
||||
&i.SubmittedBy,
|
||||
&i.SubmittedAt,
|
||||
&i.CommitID,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.ReviewNote,
|
||||
&i.Content,
|
||||
&i.IsDeleted,
|
||||
&i.Submitter,
|
||||
&i.User,
|
||||
&i.Reviewer,
|
||||
)
|
||||
return i, err
|
||||
|
||||
Reference in New Issue
Block a user