Adds DELETE /practices/:id/parents/:parentKind/:parentId and exam-prep equivalent so admins can remove one location link without replacing the full parents array. Includes admin panel integration guide and parent kind parse tests. Co-authored-by: Cursor <cursoragent@cursor.com>
210 lines
5.9 KiB
Go
210 lines
5.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: lms_practice_parents.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const CountLmsPracticesByParent = `-- name: CountLmsPracticesByParent :one
|
|
SELECT COUNT(*)::bigint
|
|
FROM lms_practice_parents
|
|
WHERE parent_kind = $1
|
|
AND parent_id = $2
|
|
`
|
|
|
|
type CountLmsPracticesByParentParams struct {
|
|
ParentKind string `json:"parent_kind"`
|
|
ParentID int64 `json:"parent_id"`
|
|
}
|
|
|
|
func (q *Queries) CountLmsPracticesByParent(ctx context.Context, arg CountLmsPracticesByParentParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, CountLmsPracticesByParent, arg.ParentKind, arg.ParentID)
|
|
var column_1 int64
|
|
err := row.Scan(&column_1)
|
|
return column_1, err
|
|
}
|
|
|
|
const CountLmsPracticesByParentExcludingPractice = `-- name: CountLmsPracticesByParentExcludingPractice :one
|
|
SELECT COUNT(*)::bigint
|
|
FROM lms_practice_parents
|
|
WHERE parent_kind = $1
|
|
AND parent_id = $2
|
|
AND practice_id <> $3
|
|
`
|
|
|
|
type CountLmsPracticesByParentExcludingPracticeParams struct {
|
|
ParentKind string `json:"parent_kind"`
|
|
ParentID int64 `json:"parent_id"`
|
|
PracticeID int64 `json:"practice_id"`
|
|
}
|
|
|
|
func (q *Queries) CountLmsPracticesByParentExcludingPractice(ctx context.Context, arg CountLmsPracticesByParentExcludingPracticeParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, CountLmsPracticesByParentExcludingPractice, arg.ParentKind, arg.ParentID, arg.PracticeID)
|
|
var column_1 int64
|
|
err := row.Scan(&column_1)
|
|
return column_1, err
|
|
}
|
|
|
|
const DeleteLmsPracticeParent = `-- name: DeleteLmsPracticeParent :execrows
|
|
DELETE FROM lms_practice_parents
|
|
WHERE practice_id = $1
|
|
AND parent_kind = $2
|
|
AND parent_id = $3
|
|
`
|
|
|
|
type DeleteLmsPracticeParentParams struct {
|
|
PracticeID int64 `json:"practice_id"`
|
|
ParentKind string `json:"parent_kind"`
|
|
ParentID int64 `json:"parent_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteLmsPracticeParent(ctx context.Context, arg DeleteLmsPracticeParentParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, DeleteLmsPracticeParent, arg.PracticeID, arg.ParentKind, arg.ParentID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const DeleteLmsPracticeParentsByPracticeID = `-- name: DeleteLmsPracticeParentsByPracticeID :exec
|
|
DELETE FROM lms_practice_parents
|
|
WHERE practice_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteLmsPracticeParentsByPracticeID(ctx context.Context, practiceID int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteLmsPracticeParentsByPracticeID, practiceID)
|
|
return err
|
|
}
|
|
|
|
const InsertLmsPracticeParent = `-- name: InsertLmsPracticeParent :one
|
|
INSERT INTO lms_practice_parents (practice_id, parent_kind, parent_id)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING id, practice_id, parent_kind, parent_id, created_at
|
|
`
|
|
|
|
type InsertLmsPracticeParentParams struct {
|
|
PracticeID int64 `json:"practice_id"`
|
|
ParentKind string `json:"parent_kind"`
|
|
ParentID int64 `json:"parent_id"`
|
|
}
|
|
|
|
func (q *Queries) InsertLmsPracticeParent(ctx context.Context, arg InsertLmsPracticeParentParams) (LmsPracticeParent, error) {
|
|
row := q.db.QueryRow(ctx, InsertLmsPracticeParent, arg.PracticeID, arg.ParentKind, arg.ParentID)
|
|
var i LmsPracticeParent
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.PracticeID,
|
|
&i.ParentKind,
|
|
&i.ParentID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListLmsPracticeParentsByPracticeID = `-- name: ListLmsPracticeParentsByPracticeID :many
|
|
SELECT id, practice_id, parent_kind, parent_id, created_at
|
|
FROM lms_practice_parents
|
|
WHERE practice_id = $1
|
|
ORDER BY id ASC
|
|
`
|
|
|
|
func (q *Queries) ListLmsPracticeParentsByPracticeID(ctx context.Context, practiceID int64) ([]LmsPracticeParent, error) {
|
|
rows, err := q.db.Query(ctx, ListLmsPracticeParentsByPracticeID, practiceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []LmsPracticeParent
|
|
for rows.Next() {
|
|
var i LmsPracticeParent
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PracticeID,
|
|
&i.ParentKind,
|
|
&i.ParentID,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListLmsPracticeParentsByPracticeIDs = `-- name: ListLmsPracticeParentsByPracticeIDs :many
|
|
SELECT id, practice_id, parent_kind, parent_id, created_at
|
|
FROM lms_practice_parents
|
|
WHERE practice_id = ANY ($1::bigint[])
|
|
ORDER BY practice_id ASC, id ASC
|
|
`
|
|
|
|
func (q *Queries) ListLmsPracticeParentsByPracticeIDs(ctx context.Context, practiceIds []int64) ([]LmsPracticeParent, error) {
|
|
rows, err := q.db.Query(ctx, ListLmsPracticeParentsByPracticeIDs, practiceIds)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []LmsPracticeParent
|
|
for rows.Next() {
|
|
var i LmsPracticeParent
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PracticeID,
|
|
&i.ParentKind,
|
|
&i.ParentID,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListLmsPracticeParentsByQuestionSetID = `-- name: ListLmsPracticeParentsByQuestionSetID :many
|
|
SELECT
|
|
lpp.parent_kind,
|
|
lpp.parent_id,
|
|
lpp.practice_id
|
|
FROM lms_practice_parents lpp
|
|
INNER JOIN lms_practices lp ON lp.id = lpp.practice_id
|
|
WHERE lp.question_set_id = $1
|
|
ORDER BY lp.id DESC, lpp.id ASC
|
|
`
|
|
|
|
type ListLmsPracticeParentsByQuestionSetIDRow struct {
|
|
ParentKind string `json:"parent_kind"`
|
|
ParentID int64 `json:"parent_id"`
|
|
PracticeID int64 `json:"practice_id"`
|
|
}
|
|
|
|
func (q *Queries) ListLmsPracticeParentsByQuestionSetID(ctx context.Context, questionSetID int64) ([]ListLmsPracticeParentsByQuestionSetIDRow, error) {
|
|
rows, err := q.db.Query(ctx, ListLmsPracticeParentsByQuestionSetID, questionSetID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListLmsPracticeParentsByQuestionSetIDRow
|
|
for rows.Next() {
|
|
var i ListLmsPracticeParentsByQuestionSetIDRow
|
|
if err := rows.Scan(&i.ParentKind, &i.ParentID, &i.PracticeID); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|