Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project endpoints #297

Merged
merged 23 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0fab424
Add project endpoints
AmirAgassi Dec 27, 2024
71e4568
Add bruno files
AmirAgassi Dec 27, 2024
37fc3cb
Refactor project routes
AmirAgassi Dec 27, 2024
e0fa363
Add better security to SubmitProject
AmirAgassi Dec 27, 2024
63717bf
Add project tests, fix server tests, helpers
AmirAgassi Dec 27, 2024
35f8781
Fix test
AmirAgassi Dec 27, 2024
7cc300c
Add file check middleware
AmirAgassi Dec 27, 2024
c1671d4
Ensure atomic operations in project creation
AmirAgassi Dec 27, 2024
338e434
Fix param validation support for min/max length and regex patterns
AmirAgassi Dec 27, 2024
0e26ca6
Add documentation
AmirAgassi Dec 27, 2024
94060b0
Merge branch 'main' into feat/218/add-project-endpoints
AmirAgassi Dec 27, 2024
d885baf
let postgres handle project uuid generation
AmirAgassi Dec 28, 2024
ddc3099
remove redundant subquery in UpdateProjectAnswer
AmirAgassi Dec 30, 2024
088252e
incremental answer creation/validation
AmirAgassi Dec 30, 2024
4f3478e
remove redundant user creation
AmirAgassi Dec 31, 2024
d77f587
remove userID to use user.ID directly instead
AmirAgassi Dec 31, 2024
daaee27
check draft status before updating answers
AmirAgassi Dec 31, 2024
3afc907
change validation order in project answer updates
AmirAgassi Dec 31, 2024
fc84104
add role-based authorization to project endpoints
AmirAgassi Dec 31, 2024
3e28c08
a
AmirAgassi Dec 31, 2024
88db743
check draft status before submitting project
AmirAgassi Dec 31, 2024
c05b060
Merge branch 'main' into feat/218/add-project-endpoints
AmirAgassi Dec 31, 2024
13a267d
update email verification test to check HTML response
AmirAgassi Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading