diff --git a/database_manager.py b/database_manager.py index b0f7cf1..92af1d9 100644 --- a/database_manager.py +++ b/database_manager.py @@ -61,6 +61,8 @@ def authenticate(self, database): else: config_bank = 'config_bank_api' + print(config_bank) + address_bank = config.get(config_bank, 'address_bank') name_bank = config.get(config_bank, 'name_bank') user_bank = config.get(config_bank, 'user_bank') diff --git a/model.py b/model.py index f36b686..1e60385 100644 --- a/model.py +++ b/model.py @@ -95,20 +95,20 @@ def confirm_token(self, data): def active_token(self, token, user_id): try: query = f'select id from tokens where token = {token} and user = {user_id}' - token_id = self.database.commit_with_return(query, database = 2)[0][0] - - if len(id) > 0: + token_id = self.database.commit_with_return(query, database = 2)[0] + + if len(token_id) > 0: query = self.gera_query.alterar_dados_da_tabela('connections', ['active'], [1], where=True, - valor_where=token_id, coluna_verificacao='id') + valor_where=token_id[0], coluna_verificacao='id') self.database.commit_without_return(query, database = 2) else: - query = self.gera_query.inserir_na_tabela('connections', ['token'], [token_id]) + query = self.gera_query.inserir_na_tabela('connections', ['token'], [token_id[0]]) self.database.commit_without_return(query, database = 2) self.r = { 'Message' : { 'token' : token, - 'token_id' : token_id + 'token_id' : token_id[0] }, 'Status' : 200 } @@ -124,14 +124,14 @@ def active_token(self, token, user_id): def deactive_token(self, token): try: query = f'select id from tokens where token = {token}' - token_id = self.database.commit_with_return(query, database = 2)[0][0] + token_id = self.database.commit_with_return(query, database = 2)[0] - if len(id) > 0: + if len(token_id) > 0: query = self.gera_query.alterar_dados_da_tabela('connections', ['active'], [0], where=True, - valor_where=token_id, coluna_verificacao='id') + valor_where=token_id[0], coluna_verificacao='id') self.database.commit_without_return(query, database = 2) else: - query = self.gera_query.inserir_na_tabela('connections', ['token', 'active'], [token_id, 0]) + query = self.gera_query.inserir_na_tabela('connections', ['token', 'active'], [token_id[0], 0]) self.database.commit_without_return(query, database = 2) self.r = { @@ -236,7 +236,6 @@ def novo_veiculo(self, data): username = data['Username'] user_type = data['UserType'] license_plate = data['LicensePlate'] - username = data['Username'] user_id = self.database.return_user_id(username) columns = self.database.return_columns('carros') @@ -419,7 +418,7 @@ def autenticar_usuario(self, data): user_id = self.database.return_user_id(username) - if len(user_id) == 0: + if not user_id: raise Exception('Usuário não encontrado no banco de dados') token = self.search_token(user_id) diff --git a/rotas.py b/rotas.py index cf091d6..1718ce0 100644 --- a/rotas.py +++ b/rotas.py @@ -21,7 +21,6 @@ def novo_veiculo(): raise Exception('Invalid Token') response = backend.novo_veiculo(data) - except Exception as e: response = { 'Message' : { @@ -29,7 +28,8 @@ def novo_veiculo(): }, 'Status' : 401 } - status = int(response['status']) + + status = int(response['Status']) return jsonify(response), 200 #adicionar novo usuario - FUNCIONANDO @@ -39,24 +39,19 @@ def novo_usuario(): data = request.get_json() if len(data) > 5: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + + response = backend.novo_usuario(data) - response = jsonify(backend.novo_usuario(data)) - status = int(response['status']) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 #usuario solicita nova limpeza - FUNCIONANDO @app.route('/nova_limpeza', methods=['POST']) @@ -64,29 +59,24 @@ def nova_limpeza(): try: data = request.get_json() if len(data) > 5: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.nova_limpeza(data)) - status = int(response['status']) + response = backend.nova_limpeza(data) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 #avalicao do cliente a respeito de UM carro(QRcode) - FUNCIONANDO @app.route('/nova_avaliacao', methods=['POST']) @@ -94,29 +84,25 @@ def nova_avaliacao(): try: data = request.get_json() if len(data) > 6: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.nova_avaliacao(data)) - status = int(response['status']) - + response = backend.nova_avaliacao(data) + + except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/recusa_notificacao', methods=['POST']) @@ -124,29 +110,24 @@ def recusa_notificacao(): try: data = request.get_json() if len(data) > 6: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.recusa_notificacao(data)) - status = int(response['status']) + response = backend.recusa_notificacao(data) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/grava_envio_notificao', methods=['POST']) @@ -154,29 +135,24 @@ def grava_envio_notificao(): try: data = request.get_json() if len(data) > 4: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.grava_envio_notificao(data)) - status = int(response['status']) - + response = backend.grava_envio_notificao(data) + except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/solicitar_limpeza', methods=['POST']) @@ -184,55 +160,45 @@ def solicitar_limpeza(): try: data = request.get_json() if len(data) > 5: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.solicitar_limpeza(data)) - status = int(response['status']) - + response = backend.solicitar_limpeza(data) + except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/autenticar_usuario', methods=['POST']) def autenticar_usuario(): try: - data = request.json() + data = request.get_json() if len(data) > 3: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + - response = jsonify(backend.autenticar_usuario(data)) - status = int(response['status']) + response = backend.autenticar_usuario(data) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/buscar_notificacoes', methods=['POST']) @@ -240,29 +206,24 @@ def buscar_notificacoes(): try: data = request.get_json() if len(data) > 3: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.buscar_notificacoes(data)) - status = int(response['status']) + response = backend.buscar_notificacoes(data) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/buscar_limpezas_veiculo', methods=['POST']) @@ -270,29 +231,23 @@ def buscar_limpezas_veiculo(): try: data = request.get_json() if len(data) > 4: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.buscar_limpezas_veiculo(data)) - status = int(response['status']) - + response = backend.buscar_limpezas_veiculo(data) + except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/buscar_resumo_veiculo', methods=['POST']) @@ -300,29 +255,24 @@ def buscar_resumo_veiculo(): try: data = request.get_json() if len(data) > 4: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.buscar_resumo_veiculo(data)) - status = int(response['status']) + response = backend.buscar_resumo_veiculo(data) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/buscar_ultima_limpeza_veiculo', methods=['POST']) @@ -330,29 +280,24 @@ def buscar_ultima_limpeza_veiculo(): try: data = request.get_json() if len(data) > 4: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.buscar_ultima_limpeza_veiculo(data)) - status = int(response['status']) + response = backend.buscar_ultima_limpeza_veiculo(data) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/buscar_limpeza', methods=['POST']) @@ -360,29 +305,24 @@ def buscar_limpeza(): try: data = request.get_json() if len(data) > 4: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.buscar_limpeza(data)) - status = int(response['status']) + response = backend.buscar_limpeza(data) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 @app.route ('/realizar_logoff', methods=['POST']) @@ -390,29 +330,24 @@ def realizar_logoff(): try: data = request.get_json() if len(data) > 4: - e = jsonify({ - 'Message' : { - 'Error' : 'Request out of params' - }, - 'Status' : 401 - }) - raise Exception(e) + raise Exception('Request out of params') + response = backend.confirm_token(data) if response['Message'] != 'OK': raise Exception('Invalid Token') - response = jsonify(backend.realizar_logoff(data)) - status = int(response['status']) + response = backend.realizar_logoff(data) except Exception as e: - response = jsonify({ + response = { 'Message' : { 'Error' : str(e) }, 'Status' : 401 - }) - return response, status + } + status = int(response['Status']) + return jsonify(response), 200 if __name__ == "__main__":