def get(self):
     data_companies = Company.get_all()
     if data_companies:
         return Utilities.response_services(True, 200, "Successful action",
                                            data_companies)
     else:
         return Utilities.response_services(False, 404,
                                            "There are no companies")
Exemplo n.º 2
0
def verificacion():
    if request.method != 'OPTIONS' and request.endpoint != "welcome":
        if request.headers.get('Authorization'):
            if not Utilities.isTokenIntegration(
                    request.headers.get('Authorization')):
                return Utilities.response_services(False, 403, "Access denied")
        else:
            return Utilities.response_services(
                False, 403, "Access denied, send authorization")
 def delete(self, _id):
     company_exists = Company.get_data(_id)
     if company_exists is None:
         return Utilities.response_services(False, 404,
                                            "The company not found")
     else:
         delete_company = Company.delete_data(_id)
         if delete_company is not None:
             return Utilities.response_services(
                 True, 202, "Company successfully eliminated")
         else:
             return Utilities.response_services(
                 True, 500, "An error occurred while deleting the company")
Exemplo n.º 4
0
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('km', type=int, required=False)
     params = parser.parse_args()
     try:
         km = randint(0, 2000) if params["km"] is None else params["km"]
         days = Utilities.fibonacciDelivery(km)
         message = "time for delivery for a distance of " + str(
             km) + " km is " + str(days) + " days"
         return Utilities.response_services(True, 200, message)
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' linea: ' + str(
                 exc_tb.tb_lineno)
         print(str(msj))
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred")
 def get(self, _id):
     try:
         data_company = Company.get_data(_id)
         if data_company:
             return Utilities.response_services(True, 200,
                                                "Successful action",
                                                data_company)
         else:
             return Utilities.response_services(False, 404,
                                                "Company not found")
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' line: ' + str(
                 exc_tb.tb_lineno)
         print(msj)
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred", None)
Exemplo n.º 6
0
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('divisors', type=int, required=False)
     params = parser.parse_args()
     try:
         limit_divisors = 1000 if params["divisors"] is None else params[
             "divisors"]
         return Utilities.response_services(
             True, 200,
             "The first number in the fibonacci sequence with more than " +
             str(limit_divisors) + " divisors is : " +
             str(Utilities.fibonacciDivisors(limit_divisors)))
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' linea: ' + str(
                 exc_tb.tb_lineno)
         print(str(msj))
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred")
Exemplo n.º 7
0
 def insert_data(cls, dataJson):
     query = Company(
         identification=dataJson['identification'],
         name=dataJson['name'],
         address=dataJson['address'],
         status=dataJson['status'] if "status" in dataJson else 1,
         phone=dataJson['phone'] if "phone" in dataJson else None,
         mail=dataJson['mail'] if "mail" in dataJson else None)
     Company.save(query)
     if query.id:
         return Utilities.get_structure(query)
     return None
 def post(self):
     data = request.get_json()
     try:
         validate = Utilities.validateStructureJson(
             data, CompanyCreateResource.required_company_create)
         if not validate["error"]:
             company_exists = Company.get_data_by_identification(
                 data["identification"])
             if company_exists is None:
                 insert_company = Company.insert_data(data)
                 if insert_company:
                     return Utilities.response_services(
                         True, 201, "Company successfully inserted",
                         insert_company)
                 else:
                     return Utilities.response_services(
                         False, 500,
                         "An error occurred while inserting the company")
             else:
                 return Utilities.response_services(
                     False, 400,
                     "There is already a company with the identification sent"
                 )
         else:
             return Utilities.response_services(False, 400,
                                                validate["message"])
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' linea: ' + str(
                 exc_tb.tb_lineno)
         print(str(msj))
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred", None)
Exemplo n.º 9
0
 def update_data(cls, _id, dataJson):
     query = cls.query.filter_by(id=_id).first()
     if query:
         if 'identification' in dataJson:
             query.identification = dataJson['identification']
         if 'name' in dataJson:
             query.name = dataJson['name']
         if 'address' in dataJson:
             query.address = dataJson['address']
         if 'status' in dataJson:
             query.status = dataJson['status']
         if 'phone' in dataJson:
             query.phone = dataJson['phone']
         if 'mail' in dataJson:
             query.mail = dataJson['mail']
         db.session.commit()
         if query.id:
             return Utilities.get_structure(query)
     return None
Exemplo n.º 10
0
 def get_data_by_identification(cls, _identification):
     query = cls.query.filter_by(identification=_identification).first()
     return Utilities.get_structure(query) if query is not None else None