def init_motos(self): moto1 = MotosModel('1234AAA', 99, 42.1, 2.1) moto2 = MotosModel('4321AAA', 10, 42.0, 2.1) moto3 = MotosModel('5678AAA', 9, 42.1, 2.0) moto4 = MotosModel('8765AAA', 32, 42.0, 2.0) moto1.save_to_db() moto2.save_to_db() moto3.save_to_db() moto4.save_to_db()
def post(self): """ POST method Adds a new account Return: dict (account created / message) """ data = parser.parse_args() if not data['license_number']: return {'message': {"license_number": "Name cant be empty"}}, 400 if not data['battery']: return {'message': {"battery": "Battery cant be empty"}}, 400 if not data['longitude']: return {'message': {"longitude": "Longitude cant be empty"}}, 400 if not data['latitude']: return {'message': {"latitude": "Latitude cant be empty"}}, 400 if MotosModel.find_by_license_number( license_number=data['license_number']): return { 'message': "Account with license number [{}] already exists".format( data['license_number']) }, 409 moto = MotosModel(license_number=data['license_number'], battery=data['battery'], latitude=data['latitude'], longitude=data['longitude']) try: moto.save_to_db() return {'moto': MotosModel.find_by_id(moto.id).json()}, 201 except: return {"message": "Something went wrong"}, 500