From e6bdaa61102c5205b7afec0d440e41ef684c0548 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2026 20:35:37 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=B9=20code=20health:=20Prevent=20d?= =?UTF-8?q?eletion=20of=20problems=20referenced=20by=20assignments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/server/db/query/assignment.sql | 2 +- apps/server/db/query/problem.sql | 11 +++ .../server/internal/db/sqlc/assignment.sql.go | 98 +++++++++++-------- apps/server/internal/db/sqlc/problem.sql.go | 29 ++++++ apps/server/internal/db/sqlc/querier.go | 2 + .../internal/modules/problem/service.go | 20 +++- 6 files changed, 116 insertions(+), 46 deletions(-) diff --git a/apps/server/db/query/assignment.sql b/apps/server/db/query/assignment.sql index 4f06b31..1b94a5e 100644 --- a/apps/server/db/query/assignment.sql +++ b/apps/server/db/query/assignment.sql @@ -149,7 +149,7 @@ RETURNING *; INSERT INTO assignment_problems ( assignment_id, problem_id, status ) -SELECT $1, unnest($2::uuid[]), 'pending'; +SELECT $1, unnest(sqlc.arg('problem_IDs')::uuid[]), 'pending'; -- name: UpdateAssignmentProblemProgress :one UPDATE assignment_problems diff --git a/apps/server/db/query/problem.sql b/apps/server/db/query/problem.sql index 3c989ee..e0cc600 100644 --- a/apps/server/db/query/problem.sql +++ b/apps/server/db/query/problem.sql @@ -135,3 +135,14 @@ LIMIT $1 OFFSET $2; -- name: CountAllProblems :one SELECT COUNT(*) FROM problems WHERE archived_at IS NULL; +-- name: CheckProblemInActiveAssignments :one +SELECT COUNT(*) +FROM assignment_problems ap +JOIN assignments a ON ap.assignment_id = a.id +WHERE ap.problem_id = $1 + AND a.status = 'active' + AND a.archived_at IS NULL; +-- name: CheckProblemInAssignmentGroups :one +SELECT COUNT(*) +FROM assignment_group_problems +WHERE problem_id = $1; diff --git a/apps/server/internal/db/sqlc/assignment.sql.go b/apps/server/internal/db/sqlc/assignment.sql.go index d9a5667..b9292f3 100644 --- a/apps/server/internal/db/sqlc/assignment.sql.go +++ b/apps/server/internal/db/sqlc/assignment.sql.go @@ -85,23 +85,6 @@ func (q *Queries) AssignGroupToMentee(ctx context.Context, arg AssignGroupToMent return i, err } -const initializeAssignmentProblems = `-- name: InitializeAssignmentProblems :exec -INSERT INTO assignment_problems ( - assignment_id, problem_id, status -) -SELECT $1, unnest($2::uuid[]), 'pending' -` - -type InitializeAssignmentProblemsParams struct { - AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` - ProblemIDs []pgtype.UUID `db:"problem_ids" json:"problem_ids"` -} - -func (q *Queries) InitializeAssignmentProblems(ctx context.Context, arg InitializeAssignmentProblemsParams) error { - _, err := q.db.Exec(ctx, initializeAssignmentProblems, arg.AssignmentID, arg.ProblemIDs) - return err -} - const checkDuplicateActiveAssignment = `-- name: CheckDuplicateActiveAssignment :one SELECT COUNT(*) FROM assignments WHERE assignment_group_id = $1 @@ -279,7 +262,7 @@ func (q *Queries) GetAssignmentGroup(ctx context.Context, id pgtype.UUID) (Assig } const getAssignmentProblem = `-- name: GetAssignmentProblem :one -SELECT ap.id, ap.assignment_id, ap.problem_id, ap.status, ap.solution_link, ap.notes, ap.completed_at, ap.created_at, ap.updated_at, p.title, p.difficulty +SELECT ap.id, ap.assignment_id, ap.problem_id, ap.status, ap.solution_link, ap.notes, ap.completed_at, ap.created_at, ap.updated_at, ap.resources, ap.app_progress_status, p.title, p.difficulty FROM assignment_problems ap JOIN problems p ON ap.problem_id = p.id WHERE ap.assignment_id = $1 AND ap.problem_id = $2 @@ -292,17 +275,19 @@ type GetAssignmentProblemParams struct { } type GetAssignmentProblemRow struct { - ID pgtype.UUID `db:"id" json:"id"` - AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` - ProblemID pgtype.UUID `db:"problem_id" json:"problem_id"` - Status AssignmentProblemStatus `db:"status" json:"status"` - SolutionLink pgtype.Text `db:"solution_link" json:"solution_link"` - Notes pgtype.Text `db:"notes" json:"notes"` - CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completed_at"` - CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"` - UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"` - Title string `db:"title" json:"title"` - Difficulty DifficultyLevel `db:"difficulty" json:"difficulty"` + ID pgtype.UUID `db:"id" json:"id"` + AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` + ProblemID pgtype.UUID `db:"problem_id" json:"problem_id"` + Status AssignmentProblemStatus `db:"status" json:"status"` + SolutionLink pgtype.Text `db:"solution_link" json:"solution_link"` + Notes pgtype.Text `db:"notes" json:"notes"` + CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completed_at"` + CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"` + UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"` + Resources pgtype.Text `db:"resources" json:"resources"` + AppProgressStatus string `db:"app_progress_status" json:"app_progress_status"` + Title string `db:"title" json:"title"` + Difficulty DifficultyLevel `db:"difficulty" json:"difficulty"` } func (q *Queries) GetAssignmentProblem(ctx context.Context, arg GetAssignmentProblemParams) (GetAssignmentProblemRow, error) { @@ -318,6 +303,8 @@ func (q *Queries) GetAssignmentProblem(ctx context.Context, arg GetAssignmentPro &i.CompletedAt, &i.CreatedAt, &i.UpdatedAt, + &i.Resources, + &i.AppProgressStatus, &i.Title, &i.Difficulty, ) @@ -433,7 +420,7 @@ INSERT INTO assignment_problems ( ) VALUES ( $1, $2, 'pending' ) -RETURNING id, assignment_id, problem_id, status, solution_link, notes, completed_at, created_at, updated_at +RETURNING id, assignment_id, problem_id, status, solution_link, notes, completed_at, created_at, updated_at, resources, app_progress_status ` type InitializeAssignmentProblemParams struct { @@ -455,10 +442,29 @@ func (q *Queries) InitializeAssignmentProblem(ctx context.Context, arg Initializ &i.CompletedAt, &i.CreatedAt, &i.UpdatedAt, + &i.Resources, + &i.AppProgressStatus, ) return i, err } +const initializeAssignmentProblems = `-- name: InitializeAssignmentProblems :exec +INSERT INTO assignment_problems ( + assignment_id, problem_id, status +) +SELECT $1, unnest($2::uuid[]), 'pending' +` + +type InitializeAssignmentProblemsParams struct { + AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` + ProblemIDs []pgtype.UUID `db:"problem_IDs" json:"problem_IDs"` +} + +func (q *Queries) InitializeAssignmentProblems(ctx context.Context, arg InitializeAssignmentProblemsParams) error { + _, err := q.db.Exec(ctx, initializeAssignmentProblems, arg.AssignmentID, arg.ProblemIDs) + return err +} + const listAssignmentGroupProblems = `-- name: ListAssignmentGroupProblems :many SELECT p.id, p.organization_id, p.created_by, p.title, p.description, p.difficulty, p.external_link, p.archived_at, p.created_at, p.updated_at, agp.position FROM problems p @@ -564,7 +570,7 @@ func (q *Queries) ListAssignmentGroupsByBootcamp(ctx context.Context, arg ListAs } const listAssignmentProblemsStatus = `-- name: ListAssignmentProblemsStatus :many -SELECT ap.id, ap.assignment_id, ap.problem_id, ap.status, ap.solution_link, ap.notes, ap.completed_at, ap.created_at, ap.updated_at, p.title, p.difficulty +SELECT ap.id, ap.assignment_id, ap.problem_id, ap.status, ap.solution_link, ap.notes, ap.completed_at, ap.created_at, ap.updated_at, ap.resources, ap.app_progress_status, p.title, p.difficulty FROM assignment_problems ap JOIN problems p ON ap.problem_id = p.id WHERE ap.assignment_id = $1 @@ -572,17 +578,19 @@ ORDER BY ap.created_at ASC ` type ListAssignmentProblemsStatusRow struct { - ID pgtype.UUID `db:"id" json:"id"` - AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` - ProblemID pgtype.UUID `db:"problem_id" json:"problem_id"` - Status AssignmentProblemStatus `db:"status" json:"status"` - SolutionLink pgtype.Text `db:"solution_link" json:"solution_link"` - Notes pgtype.Text `db:"notes" json:"notes"` - CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completed_at"` - CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"` - UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"` - Title string `db:"title" json:"title"` - Difficulty DifficultyLevel `db:"difficulty" json:"difficulty"` + ID pgtype.UUID `db:"id" json:"id"` + AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` + ProblemID pgtype.UUID `db:"problem_id" json:"problem_id"` + Status AssignmentProblemStatus `db:"status" json:"status"` + SolutionLink pgtype.Text `db:"solution_link" json:"solution_link"` + Notes pgtype.Text `db:"notes" json:"notes"` + CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completed_at"` + CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"` + UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"` + Resources pgtype.Text `db:"resources" json:"resources"` + AppProgressStatus string `db:"app_progress_status" json:"app_progress_status"` + Title string `db:"title" json:"title"` + Difficulty DifficultyLevel `db:"difficulty" json:"difficulty"` } func (q *Queries) ListAssignmentProblemsStatus(ctx context.Context, assignmentID pgtype.UUID) ([]ListAssignmentProblemsStatusRow, error) { @@ -604,6 +612,8 @@ func (q *Queries) ListAssignmentProblemsStatus(ctx context.Context, assignmentID &i.CompletedAt, &i.CreatedAt, &i.UpdatedAt, + &i.Resources, + &i.AppProgressStatus, &i.Title, &i.Difficulty, ); err != nil { @@ -838,7 +848,7 @@ SET completed_at = COALESCE($6, completed_at), updated_at = CURRENT_TIMESTAMP WHERE assignment_id = $1 AND problem_id = $2 -RETURNING id, assignment_id, problem_id, status, solution_link, notes, completed_at, created_at, updated_at +RETURNING id, assignment_id, problem_id, status, solution_link, notes, completed_at, created_at, updated_at, resources, app_progress_status ` type UpdateAssignmentProblemProgressParams struct { @@ -870,6 +880,8 @@ func (q *Queries) UpdateAssignmentProblemProgress(ctx context.Context, arg Updat &i.CompletedAt, &i.CreatedAt, &i.UpdatedAt, + &i.Resources, + &i.AppProgressStatus, ) return i, err } diff --git a/apps/server/internal/db/sqlc/problem.sql.go b/apps/server/internal/db/sqlc/problem.sql.go index ab85fa8..fcfd1c4 100644 --- a/apps/server/internal/db/sqlc/problem.sql.go +++ b/apps/server/internal/db/sqlc/problem.sql.go @@ -68,6 +68,35 @@ func (q *Queries) ArchiveProblem(ctx context.Context, id pgtype.UUID) error { return err } +const checkProblemInActiveAssignments = `-- name: CheckProblemInActiveAssignments :one +SELECT COUNT(*) +FROM assignment_problems ap +JOIN assignments a ON ap.assignment_id = a.id +WHERE ap.problem_id = $1 + AND a.status = 'active' + AND a.archived_at IS NULL +` + +func (q *Queries) CheckProblemInActiveAssignments(ctx context.Context, problemID pgtype.UUID) (int64, error) { + row := q.db.QueryRow(ctx, checkProblemInActiveAssignments, problemID) + var count int64 + err := row.Scan(&count) + return count, err +} + +const checkProblemInAssignmentGroups = `-- name: CheckProblemInAssignmentGroups :one +SELECT COUNT(*) +FROM assignment_group_problems +WHERE problem_id = $1 +` + +func (q *Queries) CheckProblemInAssignmentGroups(ctx context.Context, problemID pgtype.UUID) (int64, error) { + row := q.db.QueryRow(ctx, checkProblemInAssignmentGroups, problemID) + var count int64 + err := row.Scan(&count) + return count, err +} + const countAllProblems = `-- name: CountAllProblems :one SELECT COUNT(*) FROM problems WHERE archived_at IS NULL diff --git a/apps/server/internal/db/sqlc/querier.go b/apps/server/internal/db/sqlc/querier.go index 51f8cc5..4fa3f18 100644 --- a/apps/server/internal/db/sqlc/querier.go +++ b/apps/server/internal/db/sqlc/querier.go @@ -24,6 +24,8 @@ type Querier interface { AssignGroupToMentee(ctx context.Context, arg AssignGroupToMenteeParams) (Assignment, error) CastPollVote(ctx context.Context, arg CastPollVoteParams) (PollVote, error) CheckDuplicateActiveAssignment(ctx context.Context, arg CheckDuplicateActiveAssignmentParams) (int64, error) + CheckProblemInActiveAssignments(ctx context.Context, problemID pgtype.UUID) (int64, error) + CheckProblemInAssignmentGroups(ctx context.Context, problemID pgtype.UUID) (int64, error) CheckVoteExists(ctx context.Context, arg CheckVoteExistsParams) (bool, error) ClearAssignmentGroupProblems(ctx context.Context, assignmentGroupID pgtype.UUID) error ClearExpiredRefreshTokens(ctx context.Context) error diff --git a/apps/server/internal/modules/problem/service.go b/apps/server/internal/modules/problem/service.go index f45f1f3..7cf0c9d 100644 --- a/apps/server/internal/modules/problem/service.go +++ b/apps/server/internal/modules/problem/service.go @@ -128,8 +128,24 @@ func (s *Service) UpdateProblem(ctx context.Context, req UpdateProblemRequest, p } func (s *Service) DeleteProblem(ctx context.Context, problemID pgtype.UUID) error { - // TODO: Check if problem is referenced by assignments (requires assignment queries) - // For now, just archive the problem + // Check if problem is referenced by active assignments + activeCount, err := s.queries.CheckProblemInActiveAssignments(ctx, problemID) + if err != nil { + return err + } + if activeCount > 0 { + return errors.New("cannot delete problem: referenced by active assignments") + } + + // Check if problem is referenced by assignment groups + groupCount, err := s.queries.CheckProblemInAssignmentGroups(ctx, problemID) + if err != nil { + return err + } + if groupCount > 0 { + return errors.New("cannot delete problem: referenced by assignment groups") + } + return s.queries.ArchiveProblem(ctx, problemID) } From e5dea78d15069e3a48cdbfe7614af2826c90bcf3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2026 21:12:49 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=B9=20code=20health:=20Prevent=20d?= =?UTF-8?q?eletion=20of=20problems=20referenced=20by=20assignments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/server/db/query/assignment.sql | 2 +- apps/server/db/query/problem.sql | 1 + apps/server/go.mod | 2 +- .../server/internal/db/sqlc/assignment.sql.go | 98 ++++++++----------- apps/server/internal/db/sqlc/problem.sql.go | 58 +++++------ apps/server/internal/db/sqlc/querier.go | 2 - 6 files changed, 75 insertions(+), 88 deletions(-) diff --git a/apps/server/db/query/assignment.sql b/apps/server/db/query/assignment.sql index 1b94a5e..4f06b31 100644 --- a/apps/server/db/query/assignment.sql +++ b/apps/server/db/query/assignment.sql @@ -149,7 +149,7 @@ RETURNING *; INSERT INTO assignment_problems ( assignment_id, problem_id, status ) -SELECT $1, unnest(sqlc.arg('problem_IDs')::uuid[]), 'pending'; +SELECT $1, unnest($2::uuid[]), 'pending'; -- name: UpdateAssignmentProblemProgress :one UPDATE assignment_problems diff --git a/apps/server/db/query/problem.sql b/apps/server/db/query/problem.sql index e0cc600..3fae95a 100644 --- a/apps/server/db/query/problem.sql +++ b/apps/server/db/query/problem.sql @@ -142,6 +142,7 @@ JOIN assignments a ON ap.assignment_id = a.id WHERE ap.problem_id = $1 AND a.status = 'active' AND a.archived_at IS NULL; + -- name: CheckProblemInAssignmentGroups :one SELECT COUNT(*) FROM assignment_group_problems diff --git a/apps/server/go.mod b/apps/server/go.mod index f8d76d9..0c09ae6 100644 --- a/apps/server/go.mod +++ b/apps/server/go.mod @@ -1,6 +1,6 @@ module github.com/coderz-space/coderz.space -go 1.24.3 +go 1.25.0 require ( github.com/go-playground/validator/v10 v10.30.1 diff --git a/apps/server/internal/db/sqlc/assignment.sql.go b/apps/server/internal/db/sqlc/assignment.sql.go index b9292f3..805558b 100644 --- a/apps/server/internal/db/sqlc/assignment.sql.go +++ b/apps/server/internal/db/sqlc/assignment.sql.go @@ -85,6 +85,23 @@ func (q *Queries) AssignGroupToMentee(ctx context.Context, arg AssignGroupToMent return i, err } +const initializeAssignmentProblems = `-- name: InitializeAssignmentProblems :exec +INSERT INTO assignment_problems ( + assignment_id, problem_id, status +) +SELECT $1, unnest($2::uuid[]), 'pending' +` + +type InitializeAssignmentProblemsParams struct { + AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` + ProblemIDs []pgtype.UUID `db:"problem_ids" json:"problem_ids"` +} + +func (q *Queries) InitializeAssignmentProblems(ctx context.Context, arg InitializeAssignmentProblemsParams) error { + _, err := q.db.Exec(ctx, initializeAssignmentProblems, arg.AssignmentID, arg.ProblemIDs) + return err +} + const checkDuplicateActiveAssignment = `-- name: CheckDuplicateActiveAssignment :one SELECT COUNT(*) FROM assignments WHERE assignment_group_id = $1 @@ -262,7 +279,7 @@ func (q *Queries) GetAssignmentGroup(ctx context.Context, id pgtype.UUID) (Assig } const getAssignmentProblem = `-- name: GetAssignmentProblem :one -SELECT ap.id, ap.assignment_id, ap.problem_id, ap.status, ap.solution_link, ap.notes, ap.completed_at, ap.created_at, ap.updated_at, ap.resources, ap.app_progress_status, p.title, p.difficulty +SELECT ap.id, ap.assignment_id, ap.problem_id, ap.status, ap.solution_link, ap.notes, ap.completed_at, ap.created_at, ap.updated_at, p.title, p.difficulty FROM assignment_problems ap JOIN problems p ON ap.problem_id = p.id WHERE ap.assignment_id = $1 AND ap.problem_id = $2 @@ -275,19 +292,17 @@ type GetAssignmentProblemParams struct { } type GetAssignmentProblemRow struct { - ID pgtype.UUID `db:"id" json:"id"` - AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` - ProblemID pgtype.UUID `db:"problem_id" json:"problem_id"` - Status AssignmentProblemStatus `db:"status" json:"status"` - SolutionLink pgtype.Text `db:"solution_link" json:"solution_link"` - Notes pgtype.Text `db:"notes" json:"notes"` - CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completed_at"` - CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"` - UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"` - Resources pgtype.Text `db:"resources" json:"resources"` - AppProgressStatus string `db:"app_progress_status" json:"app_progress_status"` - Title string `db:"title" json:"title"` - Difficulty DifficultyLevel `db:"difficulty" json:"difficulty"` + ID pgtype.UUID `db:"id" json:"id"` + AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` + ProblemID pgtype.UUID `db:"problem_id" json:"problem_id"` + Status AssignmentProblemStatus `db:"status" json:"status"` + SolutionLink pgtype.Text `db:"solution_link" json:"solution_link"` + Notes pgtype.Text `db:"notes" json:"notes"` + CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completed_at"` + CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"` + UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"` + Title string `db:"title" json:"title"` + Difficulty DifficultyLevel `db:"difficulty" json:"difficulty"` } func (q *Queries) GetAssignmentProblem(ctx context.Context, arg GetAssignmentProblemParams) (GetAssignmentProblemRow, error) { @@ -303,8 +318,6 @@ func (q *Queries) GetAssignmentProblem(ctx context.Context, arg GetAssignmentPro &i.CompletedAt, &i.CreatedAt, &i.UpdatedAt, - &i.Resources, - &i.AppProgressStatus, &i.Title, &i.Difficulty, ) @@ -420,7 +433,7 @@ INSERT INTO assignment_problems ( ) VALUES ( $1, $2, 'pending' ) -RETURNING id, assignment_id, problem_id, status, solution_link, notes, completed_at, created_at, updated_at, resources, app_progress_status +RETURNING id, assignment_id, problem_id, status, solution_link, notes, completed_at, created_at, updated_at ` type InitializeAssignmentProblemParams struct { @@ -442,29 +455,10 @@ func (q *Queries) InitializeAssignmentProblem(ctx context.Context, arg Initializ &i.CompletedAt, &i.CreatedAt, &i.UpdatedAt, - &i.Resources, - &i.AppProgressStatus, ) return i, err } -const initializeAssignmentProblems = `-- name: InitializeAssignmentProblems :exec -INSERT INTO assignment_problems ( - assignment_id, problem_id, status -) -SELECT $1, unnest($2::uuid[]), 'pending' -` - -type InitializeAssignmentProblemsParams struct { - AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` - ProblemIDs []pgtype.UUID `db:"problem_IDs" json:"problem_IDs"` -} - -func (q *Queries) InitializeAssignmentProblems(ctx context.Context, arg InitializeAssignmentProblemsParams) error { - _, err := q.db.Exec(ctx, initializeAssignmentProblems, arg.AssignmentID, arg.ProblemIDs) - return err -} - const listAssignmentGroupProblems = `-- name: ListAssignmentGroupProblems :many SELECT p.id, p.organization_id, p.created_by, p.title, p.description, p.difficulty, p.external_link, p.archived_at, p.created_at, p.updated_at, agp.position FROM problems p @@ -570,7 +564,7 @@ func (q *Queries) ListAssignmentGroupsByBootcamp(ctx context.Context, arg ListAs } const listAssignmentProblemsStatus = `-- name: ListAssignmentProblemsStatus :many -SELECT ap.id, ap.assignment_id, ap.problem_id, ap.status, ap.solution_link, ap.notes, ap.completed_at, ap.created_at, ap.updated_at, ap.resources, ap.app_progress_status, p.title, p.difficulty +SELECT ap.id, ap.assignment_id, ap.problem_id, ap.status, ap.solution_link, ap.notes, ap.completed_at, ap.created_at, ap.updated_at, p.title, p.difficulty FROM assignment_problems ap JOIN problems p ON ap.problem_id = p.id WHERE ap.assignment_id = $1 @@ -578,19 +572,17 @@ ORDER BY ap.created_at ASC ` type ListAssignmentProblemsStatusRow struct { - ID pgtype.UUID `db:"id" json:"id"` - AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` - ProblemID pgtype.UUID `db:"problem_id" json:"problem_id"` - Status AssignmentProblemStatus `db:"status" json:"status"` - SolutionLink pgtype.Text `db:"solution_link" json:"solution_link"` - Notes pgtype.Text `db:"notes" json:"notes"` - CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completed_at"` - CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"` - UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"` - Resources pgtype.Text `db:"resources" json:"resources"` - AppProgressStatus string `db:"app_progress_status" json:"app_progress_status"` - Title string `db:"title" json:"title"` - Difficulty DifficultyLevel `db:"difficulty" json:"difficulty"` + ID pgtype.UUID `db:"id" json:"id"` + AssignmentID pgtype.UUID `db:"assignment_id" json:"assignment_id"` + ProblemID pgtype.UUID `db:"problem_id" json:"problem_id"` + Status AssignmentProblemStatus `db:"status" json:"status"` + SolutionLink pgtype.Text `db:"solution_link" json:"solution_link"` + Notes pgtype.Text `db:"notes" json:"notes"` + CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completed_at"` + CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"` + UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"` + Title string `db:"title" json:"title"` + Difficulty DifficultyLevel `db:"difficulty" json:"difficulty"` } func (q *Queries) ListAssignmentProblemsStatus(ctx context.Context, assignmentID pgtype.UUID) ([]ListAssignmentProblemsStatusRow, error) { @@ -612,8 +604,6 @@ func (q *Queries) ListAssignmentProblemsStatus(ctx context.Context, assignmentID &i.CompletedAt, &i.CreatedAt, &i.UpdatedAt, - &i.Resources, - &i.AppProgressStatus, &i.Title, &i.Difficulty, ); err != nil { @@ -848,7 +838,7 @@ SET completed_at = COALESCE($6, completed_at), updated_at = CURRENT_TIMESTAMP WHERE assignment_id = $1 AND problem_id = $2 -RETURNING id, assignment_id, problem_id, status, solution_link, notes, completed_at, created_at, updated_at, resources, app_progress_status +RETURNING id, assignment_id, problem_id, status, solution_link, notes, completed_at, created_at, updated_at ` type UpdateAssignmentProblemProgressParams struct { @@ -880,8 +870,6 @@ func (q *Queries) UpdateAssignmentProblemProgress(ctx context.Context, arg Updat &i.CompletedAt, &i.CreatedAt, &i.UpdatedAt, - &i.Resources, - &i.AppProgressStatus, ) return i, err } diff --git a/apps/server/internal/db/sqlc/problem.sql.go b/apps/server/internal/db/sqlc/problem.sql.go index fcfd1c4..c926bac 100644 --- a/apps/server/internal/db/sqlc/problem.sql.go +++ b/apps/server/internal/db/sqlc/problem.sql.go @@ -68,35 +68,6 @@ func (q *Queries) ArchiveProblem(ctx context.Context, id pgtype.UUID) error { return err } -const checkProblemInActiveAssignments = `-- name: CheckProblemInActiveAssignments :one -SELECT COUNT(*) -FROM assignment_problems ap -JOIN assignments a ON ap.assignment_id = a.id -WHERE ap.problem_id = $1 - AND a.status = 'active' - AND a.archived_at IS NULL -` - -func (q *Queries) CheckProblemInActiveAssignments(ctx context.Context, problemID pgtype.UUID) (int64, error) { - row := q.db.QueryRow(ctx, checkProblemInActiveAssignments, problemID) - var count int64 - err := row.Scan(&count) - return count, err -} - -const checkProblemInAssignmentGroups = `-- name: CheckProblemInAssignmentGroups :one -SELECT COUNT(*) -FROM assignment_group_problems -WHERE problem_id = $1 -` - -func (q *Queries) CheckProblemInAssignmentGroups(ctx context.Context, problemID pgtype.UUID) (int64, error) { - row := q.db.QueryRow(ctx, checkProblemInAssignmentGroups, problemID) - var count int64 - err := row.Scan(&count) - return count, err -} - const countAllProblems = `-- name: CountAllProblems :one SELECT COUNT(*) FROM problems WHERE archived_at IS NULL @@ -672,3 +643,32 @@ func (q *Queries) UpdateTag(ctx context.Context, arg UpdateTagParams) (Tag, erro ) return i, err } + +const checkProblemInActiveAssignments = `-- name: CheckProblemInActiveAssignments :one +SELECT COUNT(*) +FROM assignment_problems ap +JOIN assignments a ON ap.assignment_id = a.id +WHERE ap.problem_id = $1 + AND a.status = 'active' + AND a.archived_at IS NULL +` + +func (q *Queries) CheckProblemInActiveAssignments(ctx context.Context, problemID pgtype.UUID) (int64, error) { + row := q.db.QueryRow(ctx, checkProblemInActiveAssignments, problemID) + var count int64 + err := row.Scan(&count) + return count, err +} + +const checkProblemInAssignmentGroups = `-- name: CheckProblemInAssignmentGroups :one +SELECT COUNT(*) +FROM assignment_group_problems +WHERE problem_id = $1 +` + +func (q *Queries) CheckProblemInAssignmentGroups(ctx context.Context, problemID pgtype.UUID) (int64, error) { + row := q.db.QueryRow(ctx, checkProblemInAssignmentGroups, problemID) + var count int64 + err := row.Scan(&count) + return count, err +} diff --git a/apps/server/internal/db/sqlc/querier.go b/apps/server/internal/db/sqlc/querier.go index 4fa3f18..51f8cc5 100644 --- a/apps/server/internal/db/sqlc/querier.go +++ b/apps/server/internal/db/sqlc/querier.go @@ -24,8 +24,6 @@ type Querier interface { AssignGroupToMentee(ctx context.Context, arg AssignGroupToMenteeParams) (Assignment, error) CastPollVote(ctx context.Context, arg CastPollVoteParams) (PollVote, error) CheckDuplicateActiveAssignment(ctx context.Context, arg CheckDuplicateActiveAssignmentParams) (int64, error) - CheckProblemInActiveAssignments(ctx context.Context, problemID pgtype.UUID) (int64, error) - CheckProblemInAssignmentGroups(ctx context.Context, problemID pgtype.UUID) (int64, error) CheckVoteExists(ctx context.Context, arg CheckVoteExistsParams) (bool, error) ClearAssignmentGroupProblems(ctx context.Context, assignmentGroupID pgtype.UUID) error ClearExpiredRefreshTokens(ctx context.Context) error