280 lines
8.3 KiB
Go
280 lines
8.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: user_sub_course_progress.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CompleteSubCourse = `-- name: CompleteSubCourse :exec
|
|
UPDATE user_sub_course_progress
|
|
SET
|
|
status = 'COMPLETED',
|
|
progress_percentage = 100,
|
|
completed_at = CURRENT_TIMESTAMP,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE user_id = $1 AND sub_course_id = $2
|
|
`
|
|
|
|
type CompleteSubCourseParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
SubCourseID int64 `json:"sub_course_id"`
|
|
}
|
|
|
|
func (q *Queries) CompleteSubCourse(ctx context.Context, arg CompleteSubCourseParams) error {
|
|
_, err := q.db.Exec(ctx, CompleteSubCourse, arg.UserID, arg.SubCourseID)
|
|
return err
|
|
}
|
|
|
|
const DeleteUserSubCourseProgress = `-- name: DeleteUserSubCourseProgress :exec
|
|
DELETE FROM user_sub_course_progress
|
|
WHERE user_id = $1 AND sub_course_id = $2
|
|
`
|
|
|
|
type DeleteUserSubCourseProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
SubCourseID int64 `json:"sub_course_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteUserSubCourseProgress(ctx context.Context, arg DeleteUserSubCourseProgressParams) error {
|
|
_, err := q.db.Exec(ctx, DeleteUserSubCourseProgress, arg.UserID, arg.SubCourseID)
|
|
return err
|
|
}
|
|
|
|
const GetSubCoursesWithProgressByCourse = `-- name: GetSubCoursesWithProgressByCourse :many
|
|
SELECT
|
|
sc.id AS sub_course_id,
|
|
sc.title,
|
|
sc.description,
|
|
sc.thumbnail,
|
|
sc.display_order,
|
|
sc.level,
|
|
sc.is_active,
|
|
COALESCE(usp.status, 'NOT_STARTED') AS progress_status,
|
|
COALESCE(usp.progress_percentage, 0)::smallint AS progress_percentage,
|
|
usp.started_at,
|
|
usp.completed_at,
|
|
(SELECT COUNT(*)::bigint
|
|
FROM sub_course_prerequisites p
|
|
WHERE p.sub_course_id = sc.id
|
|
AND p.prerequisite_sub_course_id NOT IN (
|
|
SELECT usp2.sub_course_id
|
|
FROM user_sub_course_progress usp2
|
|
WHERE usp2.user_id = $1
|
|
AND usp2.status = 'COMPLETED'
|
|
)
|
|
) AS unmet_prerequisites_count
|
|
FROM sub_courses sc
|
|
LEFT JOIN user_sub_course_progress usp
|
|
ON usp.sub_course_id = sc.id AND usp.user_id = $1
|
|
WHERE sc.course_id = $2
|
|
AND sc.is_active = true
|
|
ORDER BY sc.display_order
|
|
`
|
|
|
|
type GetSubCoursesWithProgressByCourseParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
CourseID int64 `json:"course_id"`
|
|
}
|
|
|
|
type GetSubCoursesWithProgressByCourseRow struct {
|
|
SubCourseID int64 `json:"sub_course_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
DisplayOrder int32 `json:"display_order"`
|
|
Level string `json:"level"`
|
|
IsActive bool `json:"is_active"`
|
|
ProgressStatus string `json:"progress_status"`
|
|
ProgressPercentage int16 `json:"progress_percentage"`
|
|
StartedAt pgtype.Timestamptz `json:"started_at"`
|
|
CompletedAt pgtype.Timestamptz `json:"completed_at"`
|
|
UnmetPrerequisitesCount int64 `json:"unmet_prerequisites_count"`
|
|
}
|
|
|
|
func (q *Queries) GetSubCoursesWithProgressByCourse(ctx context.Context, arg GetSubCoursesWithProgressByCourseParams) ([]GetSubCoursesWithProgressByCourseRow, error) {
|
|
rows, err := q.db.Query(ctx, GetSubCoursesWithProgressByCourse, arg.UserID, arg.CourseID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetSubCoursesWithProgressByCourseRow
|
|
for rows.Next() {
|
|
var i GetSubCoursesWithProgressByCourseRow
|
|
if err := rows.Scan(
|
|
&i.SubCourseID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.DisplayOrder,
|
|
&i.Level,
|
|
&i.IsActive,
|
|
&i.ProgressStatus,
|
|
&i.ProgressPercentage,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&i.UnmetPrerequisitesCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetUserCourseProgress = `-- name: GetUserCourseProgress :many
|
|
SELECT
|
|
usp.id,
|
|
usp.user_id,
|
|
usp.sub_course_id,
|
|
usp.status,
|
|
usp.progress_percentage,
|
|
usp.started_at,
|
|
usp.completed_at,
|
|
usp.created_at,
|
|
usp.updated_at,
|
|
sc.title AS sub_course_title,
|
|
sc.level AS sub_course_level,
|
|
sc.display_order AS sub_course_display_order
|
|
FROM user_sub_course_progress usp
|
|
JOIN sub_courses sc ON sc.id = usp.sub_course_id
|
|
WHERE usp.user_id = $1 AND sc.course_id = $2
|
|
ORDER BY sc.display_order
|
|
`
|
|
|
|
type GetUserCourseProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
CourseID int64 `json:"course_id"`
|
|
}
|
|
|
|
type GetUserCourseProgressRow struct {
|
|
ID int64 `json:"id"`
|
|
UserID int64 `json:"user_id"`
|
|
SubCourseID int64 `json:"sub_course_id"`
|
|
Status string `json:"status"`
|
|
ProgressPercentage int16 `json:"progress_percentage"`
|
|
StartedAt pgtype.Timestamptz `json:"started_at"`
|
|
CompletedAt pgtype.Timestamptz `json:"completed_at"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
SubCourseTitle string `json:"sub_course_title"`
|
|
SubCourseLevel string `json:"sub_course_level"`
|
|
SubCourseDisplayOrder int32 `json:"sub_course_display_order"`
|
|
}
|
|
|
|
func (q *Queries) GetUserCourseProgress(ctx context.Context, arg GetUserCourseProgressParams) ([]GetUserCourseProgressRow, error) {
|
|
rows, err := q.db.Query(ctx, GetUserCourseProgress, arg.UserID, arg.CourseID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetUserCourseProgressRow
|
|
for rows.Next() {
|
|
var i GetUserCourseProgressRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.SubCourseID,
|
|
&i.Status,
|
|
&i.ProgressPercentage,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SubCourseTitle,
|
|
&i.SubCourseLevel,
|
|
&i.SubCourseDisplayOrder,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetUserSubCourseProgress = `-- name: GetUserSubCourseProgress :one
|
|
SELECT id, user_id, sub_course_id, status, progress_percentage, started_at, completed_at, created_at, updated_at FROM user_sub_course_progress
|
|
WHERE user_id = $1 AND sub_course_id = $2
|
|
`
|
|
|
|
type GetUserSubCourseProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
SubCourseID int64 `json:"sub_course_id"`
|
|
}
|
|
|
|
func (q *Queries) GetUserSubCourseProgress(ctx context.Context, arg GetUserSubCourseProgressParams) (UserSubCourseProgress, error) {
|
|
row := q.db.QueryRow(ctx, GetUserSubCourseProgress, arg.UserID, arg.SubCourseID)
|
|
var i UserSubCourseProgress
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.SubCourseID,
|
|
&i.Status,
|
|
&i.ProgressPercentage,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const StartSubCourseProgress = `-- name: StartSubCourseProgress :one
|
|
INSERT INTO user_sub_course_progress (user_id, sub_course_id)
|
|
VALUES ($1, $2)
|
|
ON CONFLICT (user_id, sub_course_id) DO NOTHING
|
|
RETURNING id, user_id, sub_course_id, status, progress_percentage, started_at, completed_at, created_at, updated_at
|
|
`
|
|
|
|
type StartSubCourseProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
SubCourseID int64 `json:"sub_course_id"`
|
|
}
|
|
|
|
func (q *Queries) StartSubCourseProgress(ctx context.Context, arg StartSubCourseProgressParams) (UserSubCourseProgress, error) {
|
|
row := q.db.QueryRow(ctx, StartSubCourseProgress, arg.UserID, arg.SubCourseID)
|
|
var i UserSubCourseProgress
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.SubCourseID,
|
|
&i.Status,
|
|
&i.ProgressPercentage,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const UpdateSubCourseProgress = `-- name: UpdateSubCourseProgress :exec
|
|
UPDATE user_sub_course_progress
|
|
SET
|
|
progress_percentage = $1,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE user_id = $2 AND sub_course_id = $3
|
|
`
|
|
|
|
type UpdateSubCourseProgressParams struct {
|
|
ProgressPercentage int16 `json:"progress_percentage"`
|
|
UserID int64 `json:"user_id"`
|
|
SubCourseID int64 `json:"sub_course_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateSubCourseProgress(ctx context.Context, arg UpdateSubCourseProgressParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateSubCourseProgress, arg.ProgressPercentage, arg.UserID, arg.SubCourseID)
|
|
return err
|
|
}
|