Skip to content

Commit 1e25311

Browse files
committed
Retreive course catalog endpoint
1 parent 7b65f34 commit 1e25311

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

v3/services/coursesvc/internal/courseservice.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,46 @@ func (c CourseServer) ListCoursesForAccesscode(w http.ResponseWriter, r *http.Re
525525
util.ReturnHTTPContent(w, r, 200, "success", encodedCourses)
526526
}
527527

528+
func (c CourseServer) ListCourseCatalog(w http.ResponseWriter, r *http.Request) {
529+
_, err := rbac.AuthenticateRequest(r, c.authnClient)
530+
if err != nil {
531+
util.ReturnHTTPMessage(w, r, 401, "unauthorized", "authentication failed")
532+
return
533+
}
534+
535+
tempCoursList, err := c.internalCourseServer.ListCourse(r.Context(), &generalpb.ListOptions{})
536+
if err != nil {
537+
glog.Errorf("error listing courses: %v", err)
538+
util.ReturnHTTPMessage(w, r, 500, "internalerror", "error listing courses")
539+
return
540+
}
541+
tempCourses := tempCoursList.GetCourses()
542+
543+
courses := make([]PreparedCourse, 0, len(tempCourses))
544+
for _, course := range tempCourses {
545+
if course.InCatalog {
546+
course.Scenarios = util.AppendDynamicScenariosByCategories(
547+
r.Context(),
548+
course.Scenarios,
549+
course.Categories,
550+
c.listScenarios,
551+
)
552+
courses = append(courses, convertToPreparedCourse(course))
553+
}
554+
}
555+
556+
encodedCourses, err := json.Marshal(courses)
557+
if err != nil {
558+
glog.Errorf("error marshalling prepared courses: %v", err)
559+
util.ReturnHTTPMessage(w, r, 500, "internalerror", "error listing courses")
560+
return
561+
}
562+
563+
util.ReturnHTTPContent(w, r, 200, "success", encodedCourses)
564+
565+
glog.V(4).Infof("listed courses")
566+
}
567+
528568
func (c CourseServer) previewDynamicScenarios(w http.ResponseWriter, r *http.Request) {
529569
user, err := rbac.AuthenticateRequest(r, c.authnClient)
530570
if err != nil {

v3/services/coursesvc/internal/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func NewCourseServer(
4141
}
4242

4343
func (c CourseServer) SetupRoutes(r *mux.Router) {
44+
r.HandleFunc("/course/list/catalog", c.ListCourseCatalog).Methods("GET")
4445
r.HandleFunc("/course/list/{access_code}", c.ListCoursesForAccesscode).Methods("GET")
4546
r.HandleFunc("/course/{course_id}", c.GetCourse).Methods("GET")
4647
r.HandleFunc("/a/course/list", c.ListFunc).Methods("GET")

0 commit comments

Comments
 (0)