def api_get_pagamentos(): try: return resposta(Pagamento.get_by_user_id(g.usuario.usu_id)) except KnownError as e: return resposta(e) except Exception as e: logger.exception(e) return resposta("Um erro desconhecido ocorreu", 400)
def api_get_usuario(usu_id): try: return resposta(Usuario.get_by_id(usu_id)) except KnownError as e: return resposta(e) except Exception as e: logger.exception(e) return resposta("Um erro desconhecido ocorreu", 400)
def api_get_me(): try: return resposta(g.usuario) except KnownError as e: return resposta(e) except Exception as e: logger.exception(e) return resposta("Um erro desconhecido ocorreu", 400)
def api_atualizar_usuario(): try: request_data = request.form.to_dict() or request.get_json(force=True, silent=True) or {} return resposta(Usuario.update(usuario=g.usuario, **request_data), 202) except KnownError as e: return resposta(e) except Exception as e: logger.exception(e) return resposta("Um erro desconhecido ocorreu", 400)
def api_cadastrar_pagamento(): try: request_data = request.form.to_dict() or request.get_json(force=True, silent=True) or {} return resposta(Pagamento.new(**request_data), 201) except KnownError as e: return resposta(e) except Exception as e: logger.exception(e) return resposta("Um erro desconhecido ocorreu", 400)
def api_sair(): try: logger.debug("Logged out") return resposta("Sucesso ao sair") except KnownError as e: return resposta(e) except Exception as e: logger.exception(e) return resposta("Um erro desconhecido ocorreu", 400)
def auth_api_wrapper(*args, **kwargs): try: if "usu_id" in session: g.usuario = Usuario.get_by_id(session["usu_id"]) else: raise UserNotLoggedInError() except KnownError as e: return resposta(e) except Exception as e: logger.exception(e) return resposta("Um erro desconhecido ocorreu", 400) else: return f(*args, **kwargs)
def api_entrar(): try: request_data = request.form.to_dict() or request.get_json(force=True, silent=True) or {} usu_email = request_data.get("usu_email", None) usu_senha = request_data.get("usu_senha", None) if usu_email and usu_senha: usuario = Usuario.authenticate_login(usu_email, usu_senha) session["usu_id"] = usuario.usu_id return resposta(usuario) else: raise MissingParamsError() except KnownError as e: return resposta(e) except Exception as e: logger.exception(e) return resposta("Um erro desconhecido ocorreu", 400)