Skip to content

Commit

Permalink
Retreive course catalog endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jggoebel committed Sep 10, 2024
1 parent 7b65f34 commit 1e25311
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions v3/services/coursesvc/internal/courseservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,46 @@ func (c CourseServer) ListCoursesForAccesscode(w http.ResponseWriter, r *http.Re
util.ReturnHTTPContent(w, r, 200, "success", encodedCourses)
}

func (c CourseServer) ListCourseCatalog(w http.ResponseWriter, r *http.Request) {
_, err := rbac.AuthenticateRequest(r, c.authnClient)
if err != nil {
util.ReturnHTTPMessage(w, r, 401, "unauthorized", "authentication failed")
return
}

tempCoursList, err := c.internalCourseServer.ListCourse(r.Context(), &generalpb.ListOptions{})
if err != nil {
glog.Errorf("error listing courses: %v", err)
util.ReturnHTTPMessage(w, r, 500, "internalerror", "error listing courses")
return
}
tempCourses := tempCoursList.GetCourses()

courses := make([]PreparedCourse, 0, len(tempCourses))
for _, course := range tempCourses {
if course.InCatalog {
course.Scenarios = util.AppendDynamicScenariosByCategories(
r.Context(),
course.Scenarios,
course.Categories,
c.listScenarios,
)
courses = append(courses, convertToPreparedCourse(course))
}
}

encodedCourses, err := json.Marshal(courses)
if err != nil {
glog.Errorf("error marshalling prepared courses: %v", err)
util.ReturnHTTPMessage(w, r, 500, "internalerror", "error listing courses")
return
}

util.ReturnHTTPContent(w, r, 200, "success", encodedCourses)

glog.V(4).Infof("listed courses")
}

func (c CourseServer) previewDynamicScenarios(w http.ResponseWriter, r *http.Request) {
user, err := rbac.AuthenticateRequest(r, c.authnClient)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions v3/services/coursesvc/internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewCourseServer(
}

func (c CourseServer) SetupRoutes(r *mux.Router) {
r.HandleFunc("/course/list/catalog", c.ListCourseCatalog).Methods("GET")
r.HandleFunc("/course/list/{access_code}", c.ListCoursesForAccesscode).Methods("GET")
r.HandleFunc("/course/{course_id}", c.GetCourse).Methods("GET")
r.HandleFunc("/a/course/list", c.ListFunc).Methods("GET")
Expand Down

0 comments on commit 1e25311

Please sign in to comment.