Skip to content

Commit

Permalink
Feat/104/add working user and admin dashboard (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAgassi authored Dec 11, 2024
2 parents 0f5b417 + 6f32f16 commit 5a83003
Show file tree
Hide file tree
Showing 30 changed files with 2,011 additions and 418 deletions.
30 changes: 30 additions & 0 deletions backend/.sqlc/migrations/20241114031509_project_questions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- +goose Up
-- +goose StatementBegin
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE project_sections (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
title VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE project_questions (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
section_id UUID NOT NULL REFERENCES project_sections(id) ON DELETE CASCADE,
question_text TEXT NOT NULL,
answer_text TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);

CREATE INDEX idx_project_sections_project ON project_sections(project_id);
CREATE INDEX idx_project_questions_section ON project_questions(section_id);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE project_questions;
DROP TABLE project_sections;
-- +goose StatementEnd
22 changes: 22 additions & 0 deletions backend/.sqlc/migrations/20244119000000_add_company_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE companies
ADD COLUMN industry VARCHAR(100),
ADD COLUMN company_stage VARCHAR(50),
ADD COLUMN founded_date DATE;

-- Create indexes for common queries
CREATE INDEX idx_companies_industry ON companies(industry);
CREATE INDEX idx_companies_company_stage ON companies(company_stage);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP INDEX idx_companies_company_stage;
DROP INDEX idx_companies_industry;

ALTER TABLE companies
DROP COLUMN industry,
DROP COLUMN company_stage,
DROP COLUMN founded_date;
-- +goose StatementEnd
61 changes: 58 additions & 3 deletions backend/.sqlc/queries/projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ SELECT * FROM projects
WHERE id = $1 LIMIT 1;

-- name: ListProjects :many
SELECT * FROM projects
ORDER BY created_at DESC;
SELECT
p.*,
c.name as company_name,
c.industry as company_industry,
c.founded_date as company_founded_date,
c.company_stage as company_stage
FROM projects p
LEFT JOIN companies c ON p.company_id = c.id
ORDER BY p.created_at DESC;

-- name: ListProjectsByCompany :many
SELECT * FROM projects
Expand Down Expand Up @@ -123,4 +130,52 @@ WHERE project_id = $1 AND tag_id = $2;

-- name: DeleteAllProjectTags :exec
DELETE FROM project_tags
WHERE project_id = $1;
WHERE project_id = $1;

-- name: ListProjectWithDetails :one
SELECT
p.*,
c.name as company_name,
c.industry as company_industry,
c.founded_date as company_founded_date,
c.company_stage as company_stage,
COALESCE(
json_agg(
DISTINCT jsonb_build_object(
'id', ps.id,
'title', ps.title,
'questions', (
SELECT COALESCE(
json_agg(
jsonb_build_object(
'question', pq.question_text,
'answer', pq.answer_text
)
),
'[]'::json
)
FROM project_questions pq
WHERE pq.section_id = ps.id
)
)
FILTER (WHERE ps.id IS NOT NULL)
),
'[]'::json
) as sections,
COALESCE(
json_agg(
DISTINCT jsonb_build_object(
'id', pf.id,
'name', pf.file_type,
'url', pf.file_url
)
FILTER (WHERE pf.id IS NOT NULL)
),
'[]'::json
) as documents
FROM projects p
LEFT JOIN companies c ON p.company_id = c.id
LEFT JOIN project_sections ps ON ps.project_id = p.id
LEFT JOIN project_files pf ON pf.project_id = p.id
WHERE p.id = $1
GROUP BY p.id, c.id;
Loading

0 comments on commit 5a83003

Please sign in to comment.