count data for course
This commit is contained in:
parent
7e26f15bed
commit
5857fce9a0
|
|
@ -39,7 +39,29 @@ SELECT
|
|||
c.thumbnail,
|
||||
c.sort_order,
|
||||
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
|
||||
courses c
|
||||
WHERE
|
||||
|
|
|
|||
|
|
@ -129,7 +129,29 @@ SELECT
|
|||
c.thumbnail,
|
||||
c.sort_order,
|
||||
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
|
||||
courses c
|
||||
WHERE
|
||||
|
|
@ -147,15 +169,18 @@ type ListCoursesByProgramIDParams struct {
|
|||
}
|
||||
|
||||
type ListCoursesByProgramIDRow struct {
|
||||
TotalCount int64 `json:"total_count"`
|
||||
ID int64 `json:"id"`
|
||||
ProgramID int64 `json:"program_id"`
|
||||
Name string `json:"name"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
Thumbnail pgtype.Text `json:"thumbnail"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
TotalCount int64 `json:"total_count"`
|
||||
ID int64 `json:"id"`
|
||||
ProgramID int64 `json:"program_id"`
|
||||
Name string `json:"name"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
Thumbnail pgtype.Text `json:"thumbnail"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_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) {
|
||||
|
|
@ -177,6 +202,9 @@ func (q *Queries) ListCoursesByProgramID(ctx context.Context, arg ListCoursesByP
|
|||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ModuleCount,
|
||||
&i.LessonCount,
|
||||
&i.PracticeCount,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ type Course struct {
|
|||
SortOrder int `json:"sort_order"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func (s *Store) ListCoursesByProgramID(ctx context.Context, programID int64, lim
|
|||
if i == 0 {
|
||||
total = r.TotalCount
|
||||
}
|
||||
out = append(out, courseToDomain(dbgen.Course{
|
||||
co := courseToDomain(dbgen.Course{
|
||||
ID: r.ID,
|
||||
ProgramID: r.ProgramID,
|
||||
Name: r.Name,
|
||||
|
|
@ -83,7 +83,11 @@ func (s *Store) ListCoursesByProgramID(ctx context.Context, programID int64, lim
|
|||
CreatedAt: r.CreatedAt,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user