Compare commits

..

No commits in common. "73370633ced922ec14881770c46de77b32437bca" and "10954d88b087a5e6a98299dd291669c2701c3766" have entirely different histories.

13 changed files with 47 additions and 169 deletions

View File

@ -17,17 +17,6 @@ FROM exam_prep.catalog_courses
WHERE id = $1; WHERE id = $1;
-- name: ExamPrepListCatalogCourses :many -- name: ExamPrepListCatalogCourses :many
WITH catalog_course_counts AS (
SELECT
u.catalog_course_id,
COUNT(DISTINCT u.id)::BIGINT AS units_count,
COUNT(DISTINCT m.id)::BIGINT AS modules_count,
COUNT(DISTINCT l.id)::BIGINT AS lessons_count
FROM exam_prep.units u
LEFT JOIN exam_prep.unit_modules m ON m.unit_id = u.id
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
GROUP BY u.catalog_course_id
)
SELECT SELECT
COUNT(*) OVER () AS total_count, COUNT(*) OVER () AS total_count,
c.id, c.id,
@ -35,13 +24,9 @@ SELECT
c.description, c.description,
c.thumbnail, c.thumbnail,
c.sort_order, c.sort_order,
COALESCE(cc.units_count, 0)::BIGINT AS units_count,
COALESCE(cc.modules_count, 0)::BIGINT AS modules_count,
COALESCE(cc.lessons_count, 0)::BIGINT AS lessons_count,
c.created_at, c.created_at,
c.updated_at c.updated_at
FROM exam_prep.catalog_courses c FROM exam_prep.catalog_courses c
LEFT JOIN catalog_course_counts cc ON cc.catalog_course_id = c.id
ORDER BY c.sort_order ASC, c.id ASC ORDER BY c.sort_order ASC, c.id ASC
LIMIT $1 OFFSET $2; LIMIT $1 OFFSET $2;

View File

@ -30,16 +30,6 @@ ORDER BY
m.id; m.id;
-- name: ExamPrepListUnitModulesByUnit :many -- name: ExamPrepListUnitModulesByUnit :many
WITH module_counts AS (
SELECT
m.id AS module_id,
COUNT(DISTINCT l.id)::BIGINT AS lessons_count,
COUNT(DISTINCT p.id)::BIGINT AS practices_count
FROM exam_prep.unit_modules m
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
GROUP BY m.id
)
SELECT SELECT
COUNT(*) OVER () AS total_count, COUNT(*) OVER () AS total_count,
m.id, m.id,
@ -49,12 +39,9 @@ SELECT
m.thumbnail, m.thumbnail,
m.icon, m.icon,
m.sort_order, m.sort_order,
COALESCE(mc.lessons_count, 0)::BIGINT AS lessons_count,
COALESCE(mc.practices_count, 0)::BIGINT AS practices_count,
m.created_at, m.created_at,
m.updated_at m.updated_at
FROM exam_prep.unit_modules m FROM exam_prep.unit_modules m
LEFT JOIN module_counts mc ON mc.module_id = m.id
WHERE WHERE
m.unit_id = $1 m.unit_id = $1
ORDER BY ORDER BY

View File

@ -29,18 +29,6 @@ ORDER BY
u.id; u.id;
-- name: ExamPrepListUnitsByCatalogCourse :many -- name: ExamPrepListUnitsByCatalogCourse :many
WITH unit_counts AS (
SELECT
u.id AS unit_id,
COUNT(DISTINCT m.id)::BIGINT AS modules_count,
COUNT(DISTINCT l.id)::BIGINT AS lessons_count,
COUNT(DISTINCT p.id)::BIGINT AS practices_count
FROM exam_prep.units u
LEFT JOIN exam_prep.unit_modules m ON m.unit_id = u.id
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
GROUP BY u.id
)
SELECT SELECT
COUNT(*) OVER () AS total_count, COUNT(*) OVER () AS total_count,
u.id, u.id,
@ -49,13 +37,9 @@ SELECT
u.description, u.description,
u.thumbnail, u.thumbnail,
u.sort_order, u.sort_order,
COALESCE(uc.modules_count, 0)::BIGINT AS modules_count,
COALESCE(uc.lessons_count, 0)::BIGINT AS lessons_count,
COALESCE(uc.practices_count, 0)::BIGINT AS practices_count,
u.created_at, u.created_at,
u.updated_at u.updated_at
FROM exam_prep.units u FROM exam_prep.units u
LEFT JOIN unit_counts uc ON uc.unit_id = u.id
WHERE WHERE
u.catalog_course_id = $1 u.catalog_course_id = $1
ORDER BY ORDER BY

View File

@ -105,17 +105,6 @@ func (q *Queries) ExamPrepListAllCatalogCourseIDs(ctx context.Context) ([]int64,
} }
const ExamPrepListCatalogCourses = `-- name: ExamPrepListCatalogCourses :many const ExamPrepListCatalogCourses = `-- name: ExamPrepListCatalogCourses :many
WITH catalog_course_counts AS (
SELECT
u.catalog_course_id,
COUNT(DISTINCT u.id)::BIGINT AS units_count,
COUNT(DISTINCT m.id)::BIGINT AS modules_count,
COUNT(DISTINCT l.id)::BIGINT AS lessons_count
FROM exam_prep.units u
LEFT JOIN exam_prep.unit_modules m ON m.unit_id = u.id
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
GROUP BY u.catalog_course_id
)
SELECT SELECT
COUNT(*) OVER () AS total_count, COUNT(*) OVER () AS total_count,
c.id, c.id,
@ -123,13 +112,9 @@ SELECT
c.description, c.description,
c.thumbnail, c.thumbnail,
c.sort_order, c.sort_order,
COALESCE(cc.units_count, 0)::BIGINT AS units_count,
COALESCE(cc.modules_count, 0)::BIGINT AS modules_count,
COALESCE(cc.lessons_count, 0)::BIGINT AS lessons_count,
c.created_at, c.created_at,
c.updated_at c.updated_at
FROM exam_prep.catalog_courses c FROM exam_prep.catalog_courses c
LEFT JOIN catalog_course_counts cc ON cc.catalog_course_id = c.id
ORDER BY c.sort_order ASC, c.id ASC ORDER BY c.sort_order ASC, c.id ASC
LIMIT $1 OFFSET $2 LIMIT $1 OFFSET $2
` `
@ -140,17 +125,14 @@ type ExamPrepListCatalogCoursesParams struct {
} }
type ExamPrepListCatalogCoursesRow struct { type ExamPrepListCatalogCoursesRow struct {
TotalCount int64 `json:"total_count"` TotalCount int64 `json:"total_count"`
ID int64 `json:"id"` ID int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Description pgtype.Text `json:"description"` Description pgtype.Text `json:"description"`
Thumbnail pgtype.Text `json:"thumbnail"` Thumbnail pgtype.Text `json:"thumbnail"`
SortOrder int32 `json:"sort_order"` SortOrder int32 `json:"sort_order"`
UnitsCount int64 `json:"units_count"` CreatedAt pgtype.Timestamptz `json:"created_at"`
ModulesCount int64 `json:"modules_count"` UpdatedAt pgtype.Timestamptz `json:"updated_at"`
LessonsCount int64 `json:"lessons_count"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
} }
func (q *Queries) ExamPrepListCatalogCourses(ctx context.Context, arg ExamPrepListCatalogCoursesParams) ([]ExamPrepListCatalogCoursesRow, error) { func (q *Queries) ExamPrepListCatalogCourses(ctx context.Context, arg ExamPrepListCatalogCoursesParams) ([]ExamPrepListCatalogCoursesRow, error) {
@ -169,9 +151,6 @@ func (q *Queries) ExamPrepListCatalogCourses(ctx context.Context, arg ExamPrepLi
&i.Description, &i.Description,
&i.Thumbnail, &i.Thumbnail,
&i.SortOrder, &i.SortOrder,
&i.UnitsCount,
&i.ModulesCount,
&i.LessonsCount,
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
); err != nil { ); err != nil {

View File

@ -124,16 +124,6 @@ func (q *Queries) ExamPrepListUnitModuleIDsByUnit(ctx context.Context, unitID in
} }
const ExamPrepListUnitModulesByUnit = `-- name: ExamPrepListUnitModulesByUnit :many const ExamPrepListUnitModulesByUnit = `-- name: ExamPrepListUnitModulesByUnit :many
WITH module_counts AS (
SELECT
m.id AS module_id,
COUNT(DISTINCT l.id)::BIGINT AS lessons_count,
COUNT(DISTINCT p.id)::BIGINT AS practices_count
FROM exam_prep.unit_modules m
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
GROUP BY m.id
)
SELECT SELECT
COUNT(*) OVER () AS total_count, COUNT(*) OVER () AS total_count,
m.id, m.id,
@ -143,12 +133,9 @@ SELECT
m.thumbnail, m.thumbnail,
m.icon, m.icon,
m.sort_order, m.sort_order,
COALESCE(mc.lessons_count, 0)::BIGINT AS lessons_count,
COALESCE(mc.practices_count, 0)::BIGINT AS practices_count,
m.created_at, m.created_at,
m.updated_at m.updated_at
FROM exam_prep.unit_modules m FROM exam_prep.unit_modules m
LEFT JOIN module_counts mc ON mc.module_id = m.id
WHERE WHERE
m.unit_id = $1 m.unit_id = $1
ORDER BY ORDER BY
@ -165,18 +152,16 @@ type ExamPrepListUnitModulesByUnitParams struct {
} }
type ExamPrepListUnitModulesByUnitRow struct { type ExamPrepListUnitModulesByUnitRow struct {
TotalCount int64 `json:"total_count"` TotalCount int64 `json:"total_count"`
ID int64 `json:"id"` ID int64 `json:"id"`
UnitID int64 `json:"unit_id"` UnitID int64 `json:"unit_id"`
Name string `json:"name"` Name string `json:"name"`
Description pgtype.Text `json:"description"` Description pgtype.Text `json:"description"`
Thumbnail pgtype.Text `json:"thumbnail"` Thumbnail pgtype.Text `json:"thumbnail"`
Icon pgtype.Text `json:"icon"` Icon pgtype.Text `json:"icon"`
SortOrder int32 `json:"sort_order"` SortOrder int32 `json:"sort_order"`
LessonsCount int64 `json:"lessons_count"` CreatedAt pgtype.Timestamptz `json:"created_at"`
PracticesCount int64 `json:"practices_count"` UpdatedAt pgtype.Timestamptz `json:"updated_at"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
} }
func (q *Queries) ExamPrepListUnitModulesByUnit(ctx context.Context, arg ExamPrepListUnitModulesByUnitParams) ([]ExamPrepListUnitModulesByUnitRow, error) { func (q *Queries) ExamPrepListUnitModulesByUnit(ctx context.Context, arg ExamPrepListUnitModulesByUnitParams) ([]ExamPrepListUnitModulesByUnitRow, error) {
@ -197,8 +182,6 @@ func (q *Queries) ExamPrepListUnitModulesByUnit(ctx context.Context, arg ExamPre
&i.Thumbnail, &i.Thumbnail,
&i.Icon, &i.Icon,
&i.SortOrder, &i.SortOrder,
&i.LessonsCount,
&i.PracticesCount,
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
); err != nil { ); err != nil {

View File

@ -119,18 +119,6 @@ func (q *Queries) ExamPrepListUnitIDsByCatalogCourse(ctx context.Context, catalo
} }
const ExamPrepListUnitsByCatalogCourse = `-- name: ExamPrepListUnitsByCatalogCourse :many const ExamPrepListUnitsByCatalogCourse = `-- name: ExamPrepListUnitsByCatalogCourse :many
WITH unit_counts AS (
SELECT
u.id AS unit_id,
COUNT(DISTINCT m.id)::BIGINT AS modules_count,
COUNT(DISTINCT l.id)::BIGINT AS lessons_count,
COUNT(DISTINCT p.id)::BIGINT AS practices_count
FROM exam_prep.units u
LEFT JOIN exam_prep.unit_modules m ON m.unit_id = u.id
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
GROUP BY u.id
)
SELECT SELECT
COUNT(*) OVER () AS total_count, COUNT(*) OVER () AS total_count,
u.id, u.id,
@ -139,13 +127,9 @@ SELECT
u.description, u.description,
u.thumbnail, u.thumbnail,
u.sort_order, u.sort_order,
COALESCE(uc.modules_count, 0)::BIGINT AS modules_count,
COALESCE(uc.lessons_count, 0)::BIGINT AS lessons_count,
COALESCE(uc.practices_count, 0)::BIGINT AS practices_count,
u.created_at, u.created_at,
u.updated_at u.updated_at
FROM exam_prep.units u FROM exam_prep.units u
LEFT JOIN unit_counts uc ON uc.unit_id = u.id
WHERE WHERE
u.catalog_course_id = $1 u.catalog_course_id = $1
ORDER BY ORDER BY
@ -169,9 +153,6 @@ type ExamPrepListUnitsByCatalogCourseRow struct {
Description pgtype.Text `json:"description"` Description pgtype.Text `json:"description"`
Thumbnail pgtype.Text `json:"thumbnail"` Thumbnail pgtype.Text `json:"thumbnail"`
SortOrder int32 `json:"sort_order"` SortOrder int32 `json:"sort_order"`
ModulesCount int64 `json:"modules_count"`
LessonsCount int64 `json:"lessons_count"`
PracticesCount int64 `json:"practices_count"`
CreatedAt pgtype.Timestamptz `json:"created_at"` CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"`
} }
@ -193,9 +174,6 @@ func (q *Queries) ExamPrepListUnitsByCatalogCourse(ctx context.Context, arg Exam
&i.Description, &i.Description,
&i.Thumbnail, &i.Thumbnail,
&i.SortOrder, &i.SortOrder,
&i.ModulesCount,
&i.LessonsCount,
&i.PracticesCount,
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
); err != nil { ); err != nil {

View File

@ -4,16 +4,13 @@ import "time"
// ExamPrepCatalogCourse is a top-level exam-prep track (e.g. DET, IELTS) in schema exam_prep — separate from LMS Learn English courses. // ExamPrepCatalogCourse is a top-level exam-prep track (e.g. DET, IELTS) in schema exam_prep — separate from LMS Learn English courses.
type ExamPrepCatalogCourse struct { type ExamPrepCatalogCourse struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
Thumbnail *string `json:"thumbnail,omitempty"` Thumbnail *string `json:"thumbnail,omitempty"`
SortOrder int `json:"sort_order"` SortOrder int `json:"sort_order"`
UnitsCount *int64 `json:"units_count,omitempty"` CreatedAt time.Time `json:"created_at"`
ModulesCount *int64 `json:"modules_count,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"`
LessonsCount *int64 `json:"lessons_count,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
} }
type CreateExamPrepCatalogCourseInput struct { type CreateExamPrepCatalogCourseInput struct {

View File

@ -4,17 +4,15 @@ import "time"
// ExamPrepModule is a module under an exam-prep unit (stored in exam_prep.unit_modules). // ExamPrepModule is a module under an exam-prep unit (stored in exam_prep.unit_modules).
type ExamPrepModule struct { type ExamPrepModule struct {
ID int64 `json:"id"` ID int64 `json:"id"`
UnitID int64 `json:"unit_id"` UnitID int64 `json:"unit_id"`
Name string `json:"name"` Name string `json:"name"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
Thumbnail *string `json:"thumbnail,omitempty"` Thumbnail *string `json:"thumbnail,omitempty"`
Icon *string `json:"icon,omitempty"` Icon *string `json:"icon,omitempty"`
SortOrder int `json:"sort_order"` SortOrder int `json:"sort_order"`
LessonsCount *int64 `json:"lessons_count,omitempty"` CreatedAt time.Time `json:"created_at"`
PracticesCount *int64 `json:"practices_count,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
} }
type CreateExamPrepModuleInput struct { type CreateExamPrepModuleInput struct {

View File

@ -5,14 +5,11 @@ import "time"
// ExamPrepUnit is a chapter-like grouping under an exam-prep catalog course (schema exam_prep.units). // ExamPrepUnit is a chapter-like grouping under an exam-prep catalog course (schema exam_prep.units).
type ExamPrepUnit struct { type ExamPrepUnit struct {
ID int64 `json:"id"` ID int64 `json:"id"`
CatalogCourseID int64 `json:"catalog_course_id"` CatalogCourseID int64 `json:"catalog_course_id"`
Name string `json:"name"` Name string `json:"name"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
Thumbnail *string `json:"thumbnail,omitempty"` Thumbnail *string `json:"thumbnail,omitempty"`
SortOrder int `json:"sort_order"` SortOrder int `json:"sort_order"`
ModulesCount *int64 `json:"modules_count,omitempty"`
LessonsCount *int64 `json:"lessons_count,omitempty"`
PracticesCount *int64 `json:"practices_count,omitempty"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"`
} }

View File

@ -67,7 +67,7 @@ func (s *Store) ListExamPrepCatalogCourses(ctx context.Context, limit, offset in
if i == 0 { if i == 0 {
total = r.TotalCount total = r.TotalCount
} }
item := examPrepCatalogCourseToDomain(dbgen.ExamPrepCatalogCourse{ out = append(out, examPrepCatalogCourseToDomain(dbgen.ExamPrepCatalogCourse{
ID: r.ID, ID: r.ID,
Name: r.Name, Name: r.Name,
Description: r.Description, Description: r.Description,
@ -75,11 +75,7 @@ func (s *Store) ListExamPrepCatalogCourses(ctx context.Context, limit, offset in
SortOrder: r.SortOrder, SortOrder: r.SortOrder,
CreatedAt: r.CreatedAt, CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt, UpdatedAt: r.UpdatedAt,
}) }))
item.UnitsCount = &r.UnitsCount
item.ModulesCount = &r.ModulesCount
item.LessonsCount = &r.LessonsCount
out = append(out, item)
} }
return out, total, nil return out, total, nil
} }

View File

@ -72,7 +72,7 @@ func (s *Store) ListExamPrepUnitModulesByUnit(ctx context.Context, unitID int64,
if i == 0 { if i == 0 {
total = r.TotalCount total = r.TotalCount
} }
item := examPrepModuleToDomain(dbgen.ExamPrepUnitModule{ out = append(out, examPrepModuleToDomain(dbgen.ExamPrepUnitModule{
ID: r.ID, ID: r.ID,
UnitID: r.UnitID, UnitID: r.UnitID,
Name: r.Name, Name: r.Name,
@ -82,10 +82,7 @@ func (s *Store) ListExamPrepUnitModulesByUnit(ctx context.Context, unitID int64,
SortOrder: r.SortOrder, SortOrder: r.SortOrder,
CreatedAt: r.CreatedAt, CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt, UpdatedAt: r.UpdatedAt,
}) }))
item.LessonsCount = &r.LessonsCount
item.PracticesCount = &r.PracticesCount
out = append(out, item)
} }
return out, total, nil return out, total, nil
} }

View File

@ -55,8 +55,8 @@ func (s *Store) GetExamPrepUnitByID(ctx context.Context, id int64) (domain.ExamP
func (s *Store) ListExamPrepUnitsByCatalogCourse(ctx context.Context, catalogCourseID int64, limit, offset int32) ([]domain.ExamPrepUnit, int64, error) { func (s *Store) ListExamPrepUnitsByCatalogCourse(ctx context.Context, catalogCourseID int64, limit, offset int32) ([]domain.ExamPrepUnit, int64, error) {
rows, err := s.queries.ExamPrepListUnitsByCatalogCourse(ctx, dbgen.ExamPrepListUnitsByCatalogCourseParams{ rows, err := s.queries.ExamPrepListUnitsByCatalogCourse(ctx, dbgen.ExamPrepListUnitsByCatalogCourseParams{
CatalogCourseID: catalogCourseID, CatalogCourseID: catalogCourseID,
Limit: limit, Limit: limit,
Offset: offset, Offset: offset,
}) })
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
@ -70,7 +70,7 @@ func (s *Store) ListExamPrepUnitsByCatalogCourse(ctx context.Context, catalogCou
if i == 0 { if i == 0 {
total = r.TotalCount total = r.TotalCount
} }
item := examPrepUnitToDomain(dbgen.ExamPrepUnit{ out = append(out, examPrepUnitToDomain(dbgen.ExamPrepUnit{
ID: r.ID, ID: r.ID,
CatalogCourseID: r.CatalogCourseID, CatalogCourseID: r.CatalogCourseID,
Name: r.Name, Name: r.Name,
@ -79,11 +79,7 @@ func (s *Store) ListExamPrepUnitsByCatalogCourse(ctx context.Context, catalogCou
SortOrder: r.SortOrder, SortOrder: r.SortOrder,
CreatedAt: r.CreatedAt, CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt, UpdatedAt: r.UpdatedAt,
}) }))
item.ModulesCount = &r.ModulesCount
item.LessonsCount = &r.LessonsCount
item.PracticesCount = &r.PracticesCount
out = append(out, item)
} }
return out, total, nil return out, total, nil
} }

View File

@ -199,9 +199,10 @@ func (a *App) RequireActiveSubscription() fiber.Handler {
return fiber.NewError(fiber.StatusInternalServerError, "Failed to verify subscription") return fiber.NewError(fiber.StatusInternalServerError, "Failed to verify subscription")
} }
if !active { if !active {
// Temporary bypass: allow unsubscribed learners to access content. return c.Status(fiber.StatusForbidden).JSON(domain.ErrorResponse{
// Re-enable the previous 403 response when subscription gating is turned back on. Message: "Active subscription required to access this content",
return c.Next() Error: "subscription_required",
})
} }
return c.Next() return c.Next()
default: default: