Ejemplo n.º 1
0
 def handle_request(self, id):
     """Common code between booking and withdrawing a user
     from a presentation. POST request signify a booking and
     DELETE mean to withdraw a user from that presentation.
     Other methods handle the service layer interactions.
     """
     service = CourseService.from_context()
     oauth = OAuth1Service.from_context()
     if oauth.authorized:
         if request.method == "POST":
             result = self.book(id, service, oauth)
             # returning the presentation that has just been booked
             # can be used to display the status of the booking
             if result:
                 return HALCourseRepresentation(result, request.url_rule.endpoint).as_json()
         elif request.method == "DELETE":
             result = self.withdraw(id, service, oauth)
         if result:
             return {"success": True}
         else:
             # TODO better response in case of failure (not possible atm)
             raise ApplicationException(
                 message="Error in response from the provider", status_code=409, payload={"success": False}
             )
     else:
         raise ApplicationException(message="Not authorised", status_code=401)
Ejemplo n.º 2
0
 def handle_request(self):
     courses = CourseService.from_context()
     oauth = OAuth1Service.from_context()
     return courses.my_courses(signer=oauth.signer)