Exemple #1
0
 def on_get(self, req, resp, lesson_id):
     """obtiene las preguntas de una leccion"""
     try:
         result = self.lesson_service.get_questions(lesson_id, req.context['user'], self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", 'created', 'get', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages, str("Validation Error"), 'get', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error({}, "Internal Error. Contact the Admin.", 'get', req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(str(exc), 'Error', 'get', req.path)
Exemple #2
0
 def on_post(self, req, resp, lesson_id):
     """Valida las respuestas, calcula el score y si el usuario ha pasado lo añade"""
     try:
         result = self.lesson_service.take_lesson(req.context['data'], req.context['user'], lesson_id, self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", 'created', 'post', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages, str("Validation Error"), 'post', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error({}, "Internal Error. Contact the Admin.", 'post', req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(str(exc), 'Error', 'post', req.path)
Exemple #3
0
 def on_post(self, req, resp, uuid):
     """crea lecciones"""
     try:
         result = self.lesson_service.create(req.context['data'], req.context['user'], uuid, self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", 'created', 'post', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages, str("Validation Error"), 'post', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error({}, "Error interno", 'post', req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(str(exc), 'Error', 'post', req.path)
Exemple #4
0
 def on_get(self, req, resp, uuid):
     """devuelve las lecciones y si el usuario es estudiante las marca"""
     try:
         result = self.lesson_service.get_all(uuid, req.context['user'], self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", 'created', 'get', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages, str("Validation Error"), 'get', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error({}, "Internal Error. Contact the Admin.", 'get', req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(str(exc), 'Error', 'get', req.path)
Exemple #5
0
 def on_post(self, req, resp):
     """Genera un token sin las credenciales pero pasando el token de refresh"""
     try:
         result = self.token_service.refresh_token(req.context['data'],
                                                   self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", "token created",
                                              'post', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500  # This is the default status
         resp.context['result'] = response_error(
             str(exc), "Internal Error. Contact the Admin.", 'post',
             req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_401  # This is the default status
         result = {'error': str(exc)}
         resp.context['result'] = response_error(result,
                                                 "authentication failed",
                                                 'post', req.path)
Exemple #6
0
 def on_post(self, req, resp):
     """Genera un token si las credenciales son las adecuadas"""
     try:
         result = self.token_service.create_token(req.context['data'],
                                                  self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", "token created",
                                              'post', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_401  # This is the default status
         resp.context['result'] = response_error(err.messages,
                                                 "authentication failed",
                                                 'post', req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_401  # This is the default status
         result = {'error': str(exc)}
         resp.context['result'] = response_error(result,
                                                 "authentication failed",
                                                 'post', req.path)
Exemple #7
0
 def on_get(self, req, resp, uuid):
     """Obtiene un curso por su id"""
     try:
         result = self.course_service.get_by_id(uuid, self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", 'created',
                                              'get', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages,
                                                 str("Validation Error"),
                                                 'get', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error({}, "Error interno", 'get',
                                                 req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error({}, str(exc), 'get',
                                                 req.path)
Exemple #8
0
 def on_get(self, req, resp):
     """obtiene los roles disponibles en el sistema"""
     try:
         result = self.role_service.get_all(self.session)
         resp.status = falcon.HTTP_200  # This is the default status
         resp.context['result'] = response_ok(result, "ok", 'list of roles',
                                              'post', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages,
                                                 str("Validation Error"),
                                                 'get', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error(
             {}, "Internal Error. Contact the Admin.", 'get', req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(str(exc), 'Error', 'get',
                                                 req.path)
Exemple #9
0
 def on_post(self, req, resp):
     """crea un usuario para el sistema con su rol"""
     try:
         result = self.user_service.create(req.context['data'],
                                           self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", 'created',
                                              'post', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages,
                                                 str("Validation Error"),
                                                 'post', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error(
             {}, "Internal Error. Contact the Admin.", 'post', req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error({}, str(exc), 'post',
                                                 req.path)
Exemple #10
0
 def on_get(self, req, resp):
     """Obtiene los cursos y si es un estudiante marca a cuales tiene acceso"""
     try:
         result = self.course_service.get_all(req.context['user'],
                                              self.session)
         resp.status = falcon.HTTP_200  # This is the default status
         resp.context['result'] = response_ok(result, "ok",
                                              'list of courses', 'get',
                                              req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages,
                                                 str("Validation Error"),
                                                 'get', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error(
             {}, "Internal Error. Contact the Admin.", 'get', req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error({}, str(exc), 'post',
                                                 req.path)
Exemple #11
0
 def on_put(self, req, resp):
     """Actualiza un curso"""
     try:
         result = self.course_service.create(req.context['data'],
                                             req.context['user'],
                                             self.session)
         resp.status = falcon.HTTP_201  # This is the default status
         resp.context['result'] = response_ok(result, "ok", 'created',
                                              'put', req.path)
     except ValidationError as err:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(err.messages,
                                                 str("Validation Error"),
                                                 'put', req.path)
     except SerializerException as exc:
         resp.status = falcon.HTTP_500
         resp.context['result'] = response_error(
             str(exc), "Internal Error. Contact the Admin.", 'put',
             req.path)
     except Exception as exc:
         resp.status = falcon.HTTP_400
         resp.context['result'] = response_error(str(exc), "Error", 'put',
                                                 req.path)
Exemple #12
0
 def on_get(self, req, resp):
     resp.context['result'] = response_ok({'response': 'pong'}, "ok",
                                          'pong', 'get', req.path)