def new_request(self, data): """ create new course watch request, after validation :param data: :return: """ course = CourseRequest.fromJSON(data['course_request']) user = User.fromJSON(data['user']) order = data['order'] try: self.request_service.is_valid_request(course) self.request_service.add_course_request(course, user) except InvalidRequestException as e: response = self.response_util.build_error_response( code=400, message="Course request not valid: " + e.message) logging.warning(e.message) return response except Exception as e: response = self.response_util.build_error_response( code=500, message="An Error Occurred: " + e.message) logging.error(e.message) return response response = self.response_util.build_success_response( code=200, message="Request Added", data={}) logging.info(response) return response
def get_current_requests(self, data): """ Simply returns a list of all the course watch requests in firebase. :return: """ logging.info("getting current requests for {0}".format(data)) try: user = User.fromJSON(data) current_courses = self.request_service.get_requests_for_user(user) data = [course.toJSON() for course in current_courses] except Exception as e: response = self.response_util.build_error_response( code=500, message="An Error Occurred: " + e.message) return response return self.response_util.build_success_response( code=200, message="Retrieved current requests", data=data)