def add_employee_account(id_account): """This function adds the type of user employed to an already created account.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": id_account}): account_status = Account() account_status.id_member_ate = id_account account_status.member_ate_type = AccountRole.CLIENT_EMPLOYEE.value result = account_status.add_employee_account() if result == ResponsesREST.SUCCESSFUL.value: response = Response(status=result) else: response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") return response
def get_state_by_id(state_id): """This function returns a status according to its ID.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": state_id}): state_get = State() state_get.id_state = state_id result = state_get.get_state() if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: response = Response(json.dumps(result.json_state()), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def get_report_by_id(report_id): """This function get a report according to its ID.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": report_id}): report_get = Report() report_get.id_report = report_id result = report_get.consult_report() if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: response = Response(json.dumps(result.json_report()), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def get_country_by_id(country_id): """This function gets a country according to its ID.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": country_id}): country_get = Country() country_get.id_country = country_id result = country_get.get_country() if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: response = Response(json.dumps(result.json_country()), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def find_resource_main_member_ate(member_ate_id): """This function retrieves the main resource of a memberATE.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({'id': member_ate_id}): get_resources_member = Resource() get_resources_member.id_member_ate = member_ate_id result = get_resources_member.get_main_resource_account() if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: response = Response(json.dumps(result.json_resource()), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def get_states(id_country): """This function returns all the states of a city.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": id_country}): get_state = State() get_state.id_country = id_country result = get_state.find_states() if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: list_states = [] for states_found in result: list_states.append(states_found.json_state()) response = Response(json.dumps(list_states), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def find_services_employee(id_member_ate): """This function gets the list of services for an employee.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": id_member_ate}): get_services = Service() get_services.id_member_ate = id_member_ate result = get_services.get_services_employee() if result in (ResponsesREST.SERVER_ERROR.value, ResponsesREST.NOT_FOUND.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: list_services = [] for service_found in result: list_services.append(service_found.json_service()) response = Response(json.dumps(list_services), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def get_messages(id_chat): """This function get a messages from a chat.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": id_chat}): get_message = Message() get_message.id_chat = id_chat result = get_message.get_messages_list() if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: list_chat = [] for message_found in result: list_chat.append(message_found.json_message()) response = Response(json.dumps(list_chat), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def find_resources(service_id): """This function retrieves the resources of a service.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({'id': service_id}): get_resources_service = Resource() get_resources_service.id_service = service_id result = get_resources_service.get_resource_list() if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: list_resources = [] for resource_found in result: list_resources.append(resource_found.json_resource()) response = Response(json.dumps(list_resources), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def get_cities(id_state): """This function gets all the cities in a state.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": id_state}): get_city = City() get_city.id_state = id_state result = get_city.find_cities() if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: list_cities = [] for cities_found in result: list_cities.append(cities_found.json_city()) response = Response(json.dumps(list_cities), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response
def find_requests_service(service_id): """This function retrieves the list of requests from the service.""" response = Response(json.dumps( json_error(ResponsesREST.INVALID_INPUT.value)), status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json") if validator_id.is_valid({"id": service_id}): get_request = Request() result = get_request.find_request_service(service_id) if result in (ResponsesREST.NOT_FOUND.value, ResponsesREST.SERVER_ERROR.value, ResponsesREST.INVALID_INPUT.value): response = Response(json.dumps(json_error(result)), status=result, mimetype="application/json") else: list_requests = [] for request_found in result: list_requests.append(request_found.json_request()) response = Response(json.dumps(list_requests), status=ResponsesREST.SUCCESSFUL.value, mimetype="application/json") return response