filter by learning_types and course_thematics
This commit is contained in:
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.loyso.art/frx/kurious/assets/kurious"
|
||||
@ -13,6 +14,23 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const (
|
||||
pathParamLearningType = "learning_type"
|
||||
pathParamThematicType = "thematic_type"
|
||||
)
|
||||
|
||||
func makePathTemplate(params ...string) string {
|
||||
var sb strings.Builder
|
||||
for _, param := range params {
|
||||
sb.WriteRune('/')
|
||||
sb.WriteRune('{')
|
||||
sb.WriteString(param)
|
||||
sb.WriteRune('}')
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func setupHTTP(cfg config.HTTP, srv xhttp.Server, log *slog.Logger) *http.Server {
|
||||
router := mux.NewRouter()
|
||||
|
||||
@ -23,8 +41,12 @@ func setupHTTP(cfg config.HTTP, srv xhttp.Server, log *slog.Logger) *http.Server
|
||||
router.HandleFunc("/updatedesc", coursesAPI.UdpateDescription).Methods(http.MethodPost)
|
||||
coursesRouter := router.PathPrefix("/courses").Subrouter()
|
||||
coursesRouter.HandleFunc("/", coursesAPI.List).Methods(http.MethodGet)
|
||||
coursesListLearningOnlyPath := makePathTemplate(pathParamLearningType)
|
||||
coursesRouter.HandleFunc(coursesListLearningOnlyPath, coursesAPI.List).Methods(http.MethodGet)
|
||||
coursesListFullPath := makePathTemplate(pathParamLearningType, pathParamThematicType)
|
||||
coursesRouter.HandleFunc(coursesListFullPath, coursesAPI.List).Methods(http.MethodGet)
|
||||
|
||||
courseRouter := coursesRouter.PathPrefix("/{course_id}").Subrouter()
|
||||
courseRouter := router.PathPrefix("/course").PathPrefix("/{course_id}").Subrouter()
|
||||
courseRouter.HandleFunc("/", coursesAPI.Get).Methods(http.MethodGet)
|
||||
courseRouter.HandleFunc("/short", coursesAPI.GetShort).Methods(http.MethodGet)
|
||||
courseRouter.HandleFunc("/editdesc", coursesAPI.RenderEditDescription).Methods(http.MethodGet)
|
||||
|
||||
Reference in New Issue
Block a user