69 lines
2.9 KiB
Go
69 lines
2.9 KiB
Go
package handlers
|
|
|
|
import (
|
|
"Rezina-Backend/internal/domain"
|
|
"Rezina-Backend/internal/services/examprep"
|
|
"errors"
|
|
"github.com/gofiber/fiber/v2"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// ListPublicCourses godoc
|
|
// @Summary Browse published course highlights without signing in
|
|
// @Description Public discovery only: titles, descriptions, thumbnails, access tiers and published content counts. Draft courses are excluded. Playback, quiz questions and progress use authenticated learning endpoints.
|
|
// @Tags public-catalog
|
|
// @Produce json
|
|
// @Param q query string false "Search course name or description (maximum 200 characters)"
|
|
// @Param limit query int false "Page size (1-100)" default(20)
|
|
// @Param offset query int false "Non-negative offset" default(0)
|
|
// @Success 200 {object} domain.Response{data=domain.PublicCatalogPage}
|
|
// @Failure 400 {object} domain.ErrorResponse
|
|
// @Failure 500 {object} domain.ErrorResponse
|
|
// @Router /api/v1/catalog/courses [get]
|
|
func (h *Handler) ListPublicCourses(c *fiber.Ctx) error {
|
|
q := strings.TrimSpace(c.Query("q"))
|
|
limit, err := strconv.Atoi(c.Query("limit", "20"))
|
|
if err != nil || limit < 1 || limit > 100 {
|
|
return fiber.NewError(400, "limit must be between 1 and 100")
|
|
}
|
|
offset, err := strconv.ParseInt(c.Query("offset", "0"), 10, 32)
|
|
if err != nil || offset < 0 {
|
|
return fiber.NewError(400, "offset must be non-negative")
|
|
}
|
|
if len([]rune(q)) > 200 {
|
|
return fiber.NewError(400, "Search must be at most 200 characters")
|
|
}
|
|
page, err := h.examPrepSvc.PublicCatalogCourses(c.Context(), q, int32(limit), int32(offset))
|
|
if err != nil {
|
|
return fiber.NewError(500, "Unable to load course catalog")
|
|
}
|
|
return c.JSON(domain.Response{Success: true, StatusCode: 200, Message: "Course highlights retrieved", Data: page})
|
|
}
|
|
|
|
// GetPublicCourse godoc
|
|
// @Summary Preview a published course outline without signing in
|
|
// @Description Returns published chapters, lesson highlights and quiz titles/counts. No video URLs, questions, answers or learner information are included. Unpublished courses return 404, even for staff tokens.
|
|
// @Tags public-catalog
|
|
// @Produce json
|
|
// @Param id path int true "Published course ID"
|
|
// @Success 200 {object} domain.Response{data=domain.PublicCourseOutline}
|
|
// @Failure 400 {object} domain.ErrorResponse
|
|
// @Failure 404 {object} domain.ErrorResponse
|
|
// @Failure 500 {object} domain.ErrorResponse
|
|
// @Router /api/v1/catalog/courses/{id} [get]
|
|
func (h *Handler) GetPublicCourse(c *fiber.Ctx) error {
|
|
id, err := parseAssessmentID(c.Params("id"))
|
|
if err != nil {
|
|
return fiber.NewError(400, "Invalid course ID")
|
|
}
|
|
out, err := h.examPrepSvc.PublicCatalogCourse(c.Context(), id)
|
|
if errors.Is(err, examprep.ErrCatalogCourseNotFound) {
|
|
return fiber.NewError(404, "Course not found")
|
|
}
|
|
if err != nil {
|
|
return fiber.NewError(500, "Unable to load course outline")
|
|
}
|
|
return c.JSON(domain.Response{Success: true, StatusCode: 200, Message: "Course outline retrieved", Data: out})
|
|
}
|