fix course creation linkage to sub-categories
Allow course creation payloads to include sub_category_id and persist it so newly created language paths appear in unified hierarchy views. Made-with: Cursor
This commit is contained in:
parent
a4d1f395da
commit
0cc813d224
|
|
@ -2,6 +2,8 @@ package dbgen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (q *Queries) GetSubModuleByIDCompat(ctx context.Context, id int64) (SubModule, error) {
|
func (q *Queries) GetSubModuleByIDCompat(ctx context.Context, id int64) (SubModule, error) {
|
||||||
|
|
@ -111,3 +113,56 @@ func (q *Queries) DeletePracticeCompat(ctx context.Context, id int64) error {
|
||||||
_, err := q.db.Exec(ctx, `DELETE FROM question_sets WHERE id = $1`, id)
|
_, err := q.db.Exec(ctx, `DELETE FROM question_sets WHERE id = $1`, id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateCourseCompat(
|
||||||
|
ctx context.Context,
|
||||||
|
categoryID int64,
|
||||||
|
subCategoryID *int64,
|
||||||
|
title string,
|
||||||
|
description string,
|
||||||
|
thumbnail string,
|
||||||
|
introVideoURL string,
|
||||||
|
isActive bool,
|
||||||
|
) (Course, error) {
|
||||||
|
row := q.db.QueryRow(ctx, `
|
||||||
|
INSERT INTO courses (
|
||||||
|
category_id,
|
||||||
|
sub_category_id,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
thumbnail,
|
||||||
|
intro_video_url,
|
||||||
|
is_active
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
$1,
|
||||||
|
$2,
|
||||||
|
$3,
|
||||||
|
NULLIF($4, ''),
|
||||||
|
NULLIF($5, ''),
|
||||||
|
NULLIF($6, ''),
|
||||||
|
$7
|
||||||
|
)
|
||||||
|
RETURNING id, category_id, title, description, is_active, thumbnail, intro_video_url, display_order, sub_category_id
|
||||||
|
`, categoryID, subCategoryID, title, description, thumbnail, introVideoURL, isActive)
|
||||||
|
|
||||||
|
var i Course
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.CategoryID,
|
||||||
|
&i.Title,
|
||||||
|
&i.Description,
|
||||||
|
&i.IsActive,
|
||||||
|
&i.Thumbnail,
|
||||||
|
&i.IntroVideoUrl,
|
||||||
|
&i.DisplayOrder,
|
||||||
|
&i.SubCategoryID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return Course{}, err
|
||||||
|
}
|
||||||
|
if !i.SubCategoryID.Valid {
|
||||||
|
i.SubCategoryID = pgtype.Int8{Valid: false}
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ type createCourseCategoryReq struct {
|
||||||
|
|
||||||
type createCourseReq struct {
|
type createCourseReq struct {
|
||||||
CategoryID int64 `json:"category_id"`
|
CategoryID int64 `json:"category_id"`
|
||||||
|
SubCategoryID *int64 `json:"sub_category_id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
Thumbnail *string `json:"thumbnail"`
|
Thumbnail *string `json:"thumbnail"`
|
||||||
|
|
@ -238,14 +239,33 @@ func (h *Handler) CreateCourse(c *fiber.Ctx) error {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "category_id and title are required"})
|
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "category_id and title are required"})
|
||||||
}
|
}
|
||||||
|
|
||||||
created, err := h.analyticsDB.CreateCourse(c.Context(), dbgen.CreateCourseParams{
|
isActive := true
|
||||||
CategoryID: req.CategoryID,
|
if req.IsActive != nil {
|
||||||
Title: req.Title,
|
isActive = *req.IsActive
|
||||||
Description: toText(req.Description),
|
}
|
||||||
Thumbnail: toText(req.Thumbnail),
|
description := ""
|
||||||
IntroVideoUrl: toText(req.IntroVideoURL),
|
if req.Description != nil {
|
||||||
Column6: boolOrNil(req.IsActive),
|
description = *req.Description
|
||||||
})
|
}
|
||||||
|
thumbnail := ""
|
||||||
|
if req.Thumbnail != nil {
|
||||||
|
thumbnail = *req.Thumbnail
|
||||||
|
}
|
||||||
|
introVideoURL := ""
|
||||||
|
if req.IntroVideoURL != nil {
|
||||||
|
introVideoURL = *req.IntroVideoURL
|
||||||
|
}
|
||||||
|
|
||||||
|
created, err := h.analyticsDB.CreateCourseCompat(
|
||||||
|
c.Context(),
|
||||||
|
req.CategoryID,
|
||||||
|
req.SubCategoryID,
|
||||||
|
req.Title,
|
||||||
|
description,
|
||||||
|
thumbnail,
|
||||||
|
introVideoURL,
|
||||||
|
isActive,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{Message: "Failed to create course", Error: err.Error()})
|
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{Message: "Failed to create course", Error: err.Error()})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user