UPDATE: Fix bug
All checks were successful
Build and Release / release (push) Successful in 1m8s

This commit is contained in:
2026-04-28 09:56:41 +07:00
parent b168a343be
commit a92fc4bf3b
3 changed files with 26 additions and 13 deletions

View File

@@ -1,11 +1,14 @@
-- name: CreateProject :one -- name: CreateProject :one
INSERT INTO projects ( WITH inserted_project AS (
title, description, project_status, user_id INSERT INTO projects (
) VALUES ( title, description, project_status, user_id
$1, $2, $3, $4 ) VALUES (
$1, $2, $3, $4
)
RETURNING *
) )
RETURNING SELECT
*, p.*,
json_build_object( json_build_object(
'id', u.id, 'id', u.id,
'email', u.email, 'email', u.email,
@@ -15,7 +18,10 @@ RETURNING
)::json AS user, )::json AS user,
'[]'::json AS commits, '[]'::json AS commits,
'{}'::uuid[] AS submission_ids, '{}'::uuid[] AS submission_ids,
'[]'::json AS members; '[]'::json AS members
FROM inserted_project p
JOIN users u ON p.user_id = u.id
LEFT JOIN user_profiles up ON u.id = up.user_id;
-- name: GetProjectById :one -- name: GetProjectById :one
SELECT SELECT

View File

@@ -118,13 +118,16 @@ func (q *Queries) CountProjects(ctx context.Context, arg CountProjectsParams) (i
} }
const createProject = `-- name: CreateProject :one const createProject = `-- name: CreateProject :one
INSERT INTO projects ( WITH inserted_project AS (
title, description, project_status, user_id INSERT INTO projects (
) VALUES ( title, description, project_status, user_id
$1, $2, $3, $4 ) VALUES (
$1, $2, $3, $4
)
RETURNING id, title, description, latest_commit_id, project_status, locked_by, is_deleted, user_id, created_at, updated_at
) )
RETURNING SELECT
id, title, description, latest_commit_id, project_status, locked_by, is_deleted, user_id, created_at, 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( json_build_object(
'id', u.id, 'id', u.id,
'email', u.email, 'email', u.email,
@@ -135,6 +138,9 @@ RETURNING
'[]'::json AS commits, '[]'::json AS commits,
'{}'::uuid[] AS submission_ids, '{}'::uuid[] AS submission_ids,
'[]'::json AS members '[]'::json AS members
FROM inserted_project p
JOIN users u ON p.user_id = u.id
LEFT JOIN user_profiles up ON u.id = up.user_id
` `
type CreateProjectParams struct { type CreateProjectParams struct {

View File

@@ -79,6 +79,7 @@ func ProjectRoutes(
route.Get( route.Get(
"/", "/",
middlewares.JwtAccess(userRepo),
middlewares.RequireAnyRole(constants.RoleTypeAdmin, constants.RoleTypeMod), middlewares.RequireAnyRole(constants.RoleTypeAdmin, constants.RoleTypeMod),
controller.SearchProject, controller.SearchProject,
) )