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 (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,13 @@ type createCourseCategoryReq struct {
|
|||
}
|
||||
|
||||
type createCourseReq struct {
|
||||
CategoryID int64 `json:"category_id"`
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
Thumbnail *string `json:"thumbnail"`
|
||||
CategoryID int64 `json:"category_id"`
|
||||
SubCategoryID *int64 `json:"sub_category_id"`
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
Thumbnail *string `json:"thumbnail"`
|
||||
IntroVideoURL *string `json:"intro_video_url"`
|
||||
IsActive *bool `json:"is_active"`
|
||||
IsActive *bool `json:"is_active"`
|
||||
}
|
||||
|
||||
type updateCourseReq struct {
|
||||
|
|
@ -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"})
|
||||
}
|
||||
|
||||
created, err := h.analyticsDB.CreateCourse(c.Context(), dbgen.CreateCourseParams{
|
||||
CategoryID: req.CategoryID,
|
||||
Title: req.Title,
|
||||
Description: toText(req.Description),
|
||||
Thumbnail: toText(req.Thumbnail),
|
||||
IntroVideoUrl: toText(req.IntroVideoURL),
|
||||
Column6: boolOrNil(req.IsActive),
|
||||
})
|
||||
isActive := true
|
||||
if req.IsActive != nil {
|
||||
isActive = *req.IsActive
|
||||
}
|
||||
description := ""
|
||||
if req.Description != nil {
|
||||
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 {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{Message: "Failed to create course", Error: err.Error()})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user