Skip to content

Commit

Permalink
Add project endpoints (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAgassi authored Dec 31, 2024
2 parents 319b0a4 + 13a267d commit c90299e
Show file tree
Hide file tree
Showing 32 changed files with 2,767 additions and 93 deletions.
6 changes: 4 additions & 2 deletions backend/.sqlc/migrations/20241215194302_initial_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ CREATE TABLE IF NOT EXISTS projects (
updated_at bigint NOT NULL DEFAULT extract(epoch from now())
);

CREATE TABLE IF NOT EXISTS project_questions (
CREATE TABLE project_questions (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
question varchar NOT NULL,
section varchar NOT NULL DEFAULT 'overall',
required boolean NOT NULL DEFAULT false,
validations varchar,
created_at bigint NOT NULL DEFAULT extract(epoch from now()),
updated_at bigint NOT NULL DEFAULT extract(epoch from now())
);
);

CREATE TABLE IF NOT EXISTS project_answers (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
Expand Down
26 changes: 26 additions & 0 deletions backend/.sqlc/migrations/20241226195458_add_default_questions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- +goose Up
INSERT INTO project_questions (id, question, section, required, validations) VALUES
(
gen_random_uuid(),
'What is the core product or service, and what problem does it solve?',
'business_overview',
true,
'min=100' -- Warning if less than 100 chars
),
(
gen_random_uuid(),
'What is the unique value proposition?',
'business_overview',
true,
'min=50' -- Warning if less than 50 chars
),
(
gen_random_uuid(),
'Company website',
'business_overview',
true,
'url' -- Error if not valid URL
);

-- +goose Down
DELETE FROM project_questions WHERE section = 'business_overview';
136 changes: 136 additions & 0 deletions backend/.sqlc/queries/projects.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
-- name: GetCompanyByUserID :one
SELECT * FROM companies
WHERE owner_id = $1
LIMIT 1;

-- name: CreateProject :one
INSERT INTO projects (
company_id,
title,
description,
status,
created_at,
updated_at
) VALUES (
$1, $2, $3, $4, $5, $6
) RETURNING *;

-- name: GetProjectsByCompanyID :many
SELECT * FROM projects
WHERE company_id = $1
ORDER BY created_at DESC;

-- name: GetProjectByID :one
SELECT * FROM projects
WHERE id = $1 AND company_id = $2
LIMIT 1;

-- name: UpdateProjectAnswer :one
UPDATE project_answers
SET
answer = $1,
updated_at = extract(epoch from now())
WHERE
project_answers.id = $2
AND project_id = $3
RETURNING *;

-- name: GetProjectAnswers :many
SELECT
pa.id as answer_id,
pa.answer,
pq.id as question_id,
pq.question,
pq.section
FROM project_answers pa
JOIN project_questions pq ON pa.question_id = pq.id
WHERE pa.project_id = $1
ORDER BY pq.section, pq.id;

-- name: CreateProjectAnswers :many
INSERT INTO project_answers (id, project_id, question_id, answer)
SELECT
gen_random_uuid(),
$1, -- project_id
pq.id,
'' -- empty default answer
FROM project_questions pq
RETURNING *;

-- name: CreateProjectDocument :one
INSERT INTO project_documents (
id,
project_id,
name,
url,
section,
created_at,
updated_at
) VALUES (
gen_random_uuid(),
$1, -- project_id
$2, -- name
$3, -- url
$4, -- section
extract(epoch from now()),
extract(epoch from now())
) RETURNING *;

-- name: GetProjectDocuments :many
SELECT * FROM project_documents
WHERE project_id = $1
ORDER BY created_at DESC;

-- name: DeleteProjectDocument :one
DELETE FROM project_documents
WHERE project_documents.id = $1
AND project_documents.project_id = $2
AND project_documents.project_id IN (
SELECT projects.id
FROM projects
WHERE projects.company_id = $3
)
RETURNING id;

-- name: GetProjectDocument :one
SELECT project_documents.* FROM project_documents
JOIN projects ON project_documents.project_id = projects.id
WHERE project_documents.id = $1
AND project_documents.project_id = $2
AND projects.company_id = $3;

-- name: ListCompanyProjects :many
SELECT projects.* FROM projects
WHERE company_id = $1
ORDER BY created_at DESC;

-- name: GetProjectQuestions :many
SELECT id, question, section, required, validations FROM project_questions;

-- name: UpdateProjectStatus :exec
UPDATE projects
SET
status = $1,
updated_at = extract(epoch from now())
WHERE id = $2;

-- name: GetQuestionByAnswerID :one
SELECT q.* FROM project_questions q
JOIN project_answers a ON a.question_id = q.id
WHERE a.id = $1;

-- name: GetProjectQuestion :one
SELECT * FROM project_questions
WHERE id = $1
LIMIT 1;

-- name: CreateProjectAnswer :one
INSERT INTO project_answers (
project_id,
question_id,
answer
) VALUES (
$1, -- project_id
$2, -- question_id
$3 -- answer
) RETURNING *;
12 changes: 7 additions & 5 deletions backend/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c90299e

Please sign in to comment.