count data for course
This commit is contained in:
parent
7e26f15bed
commit
5857fce9a0
|
|
@ -39,7 +39,29 @@ SELECT
|
||||||
c.thumbnail,
|
c.thumbnail,
|
||||||
c.sort_order,
|
c.sort_order,
|
||||||
c.created_at,
|
c.created_at,
|
||||||
c.updated_at
|
c.updated_at,
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
COUNT(*)::bigint
|
||||||
|
FROM
|
||||||
|
modules m
|
||||||
|
WHERE
|
||||||
|
m.course_id = c.id) AS module_count,
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
COUNT(*)::bigint
|
||||||
|
FROM
|
||||||
|
lessons l
|
||||||
|
INNER JOIN modules m ON l.module_id = m.id
|
||||||
|
WHERE
|
||||||
|
m.course_id = c.id) AS lesson_count,
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
COUNT(*)::bigint
|
||||||
|
FROM
|
||||||
|
lms_practices p
|
||||||
|
WHERE
|
||||||
|
p.course_id = c.id) AS practice_count
|
||||||
FROM
|
FROM
|
||||||
courses c
|
courses c
|
||||||
WHERE
|
WHERE
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,29 @@ SELECT
|
||||||
c.thumbnail,
|
c.thumbnail,
|
||||||
c.sort_order,
|
c.sort_order,
|
||||||
c.created_at,
|
c.created_at,
|
||||||
c.updated_at
|
c.updated_at,
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
COUNT(*)::bigint
|
||||||
|
FROM
|
||||||
|
modules m
|
||||||
|
WHERE
|
||||||
|
m.course_id = c.id) AS module_count,
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
COUNT(*)::bigint
|
||||||
|
FROM
|
||||||
|
lessons l
|
||||||
|
INNER JOIN modules m ON l.module_id = m.id
|
||||||
|
WHERE
|
||||||
|
m.course_id = c.id) AS lesson_count,
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
COUNT(*)::bigint
|
||||||
|
FROM
|
||||||
|
lms_practices p
|
||||||
|
WHERE
|
||||||
|
p.course_id = c.id) AS practice_count
|
||||||
FROM
|
FROM
|
||||||
courses c
|
courses c
|
||||||
WHERE
|
WHERE
|
||||||
|
|
@ -147,15 +169,18 @@ type ListCoursesByProgramIDParams struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListCoursesByProgramIDRow struct {
|
type ListCoursesByProgramIDRow struct {
|
||||||
TotalCount int64 `json:"total_count"`
|
TotalCount int64 `json:"total_count"`
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
ProgramID int64 `json:"program_id"`
|
ProgramID int64 `json:"program_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"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
|
ModuleCount int64 `json:"module_count"`
|
||||||
|
LessonCount int64 `json:"lesson_count"`
|
||||||
|
PracticeCount int64 `json:"practice_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) ListCoursesByProgramID(ctx context.Context, arg ListCoursesByProgramIDParams) ([]ListCoursesByProgramIDRow, error) {
|
func (q *Queries) ListCoursesByProgramID(ctx context.Context, arg ListCoursesByProgramIDParams) ([]ListCoursesByProgramIDRow, error) {
|
||||||
|
|
@ -177,6 +202,9 @@ func (q *Queries) ListCoursesByProgramID(ctx context.Context, arg ListCoursesByP
|
||||||
&i.SortOrder,
|
&i.SortOrder,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
&i.ModuleCount,
|
||||||
|
&i.LessonCount,
|
||||||
|
&i.PracticeCount,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,11 @@ type Course struct {
|
||||||
SortOrder int `json:"sort_order"`
|
SortOrder int `json:"sort_order"`
|
||||||
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"`
|
||||||
Access *LMSEntityAccess `json:"access,omitempty"`
|
// Populated on list-by-program; practices with course_id set (direct course practice only).
|
||||||
|
ModuleCount int `json:"module_count"`
|
||||||
|
LessonCount int `json:"lesson_count"`
|
||||||
|
PracticeCount int `json:"practice_count"`
|
||||||
|
Access *LMSEntityAccess `json:"access,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateCourseInput struct {
|
type CreateCourseInput struct {
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ func (s *Store) ListCoursesByProgramID(ctx context.Context, programID int64, lim
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
total = r.TotalCount
|
total = r.TotalCount
|
||||||
}
|
}
|
||||||
out = append(out, courseToDomain(dbgen.Course{
|
co := courseToDomain(dbgen.Course{
|
||||||
ID: r.ID,
|
ID: r.ID,
|
||||||
ProgramID: r.ProgramID,
|
ProgramID: r.ProgramID,
|
||||||
Name: r.Name,
|
Name: r.Name,
|
||||||
|
|
@ -83,7 +83,11 @@ func (s *Store) ListCoursesByProgramID(ctx context.Context, programID int64, lim
|
||||||
CreatedAt: r.CreatedAt,
|
CreatedAt: r.CreatedAt,
|
||||||
UpdatedAt: r.UpdatedAt,
|
UpdatedAt: r.UpdatedAt,
|
||||||
SortOrder: r.SortOrder,
|
SortOrder: r.SortOrder,
|
||||||
}))
|
})
|
||||||
|
co.ModuleCount = int(r.ModuleCount)
|
||||||
|
co.LessonCount = int(r.LessonCount)
|
||||||
|
co.PracticeCount = int(r.PracticeCount)
|
||||||
|
out = append(out, co)
|
||||||
}
|
}
|
||||||
return out, total, nil
|
return out, total, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user