Skip to content

Commit

Permalink
Add comment endpoints (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAgassi authored Jan 4, 2025
2 parents 52f57da + a29221e commit 6cfb2ad
Show file tree
Hide file tree
Showing 16 changed files with 1,215 additions and 12 deletions.
3 changes: 2 additions & 1 deletion backend/.sqlc/migrations/20241215194302_initial_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ CREATE TABLE IF NOT EXISTS project_comments (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
project_id uuid NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
target_id uuid NOT NULL,
comment uuid NOT NULL,
comment text NOT NULL,
commenter_id uuid NOT NULL REFERENCES users(id),
resolved boolean NOT NULL DEFAULT false,
created_at bigint NOT NULL DEFAULT extract(epoch from now()),
updated_at bigint NOT NULL DEFAULT extract(epoch from now())
);
Expand Down
57 changes: 56 additions & 1 deletion backend/.sqlc/queries/projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,59 @@ INSERT INTO project_answers (
$1, -- project_id
$2, -- question_id
$3 -- answer
) RETURNING *;
) RETURNING *;

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

-- name: GetProjectComment :one
SELECT * FROM project_comments
WHERE id = $1 AND project_id = $2
LIMIT 1;

-- name: CreateProjectComment :one
INSERT INTO project_comments (
project_id,
target_id,
comment,
commenter_id
) VALUES (
$1, -- project_id
$2, -- target_id
$3, -- comment
$4 -- commenter_id
) RETURNING *;

-- name: UpdateProjectComment :one
UPDATE project_comments
SET comment = $2,
updated_at = extract(epoch from now())
WHERE id = $1
RETURNING *;

-- name: DeleteProjectComment :exec
DELETE FROM project_comments
WHERE id = $1;

-- name: GetProjectByIDAdmin :one
SELECT * FROM projects
WHERE id = $1
LIMIT 1;

-- name: ResolveProjectComment :one
UPDATE project_comments
SET
resolved = true,
updated_at = extract(epoch from now())
WHERE id = $1 AND project_id = $2
RETURNING *;

-- name: UnresolveProjectComment :one
UPDATE project_comments
SET
resolved = false,
updated_at = extract(epoch from now())
WHERE id = $1 AND project_id = $2
RETURNING *;
2 changes: 1 addition & 1 deletion backend/.sqlc/queries/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ VALUES
SELECT * FROM users WHERE email = $1 LIMIT 1;

-- name: UpdateUserEmailVerifiedStatus :exec
UPDATE users SET email_verified = $1 WHERE id = $2;
UPDATE users SET email_verified = $1 WHERE id = $2;
1 change: 1 addition & 0 deletions backend/db/models.go

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

224 changes: 224 additions & 0 deletions backend/db/projects.sql.go

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

Loading

0 comments on commit 6cfb2ad

Please sign in to comment.