Example #1
0
    def post(self):

        data = Booking.parser.parse_args()

        userid = data['userid']
        bikeid = data['bikeid']

        user = AccountsModel.find_by_id(userid)
        bike = MotosModel.find_by_id(bikeid)

        if user is None:
            return "User not found", 404

        if bike is None:
            return "Bike not found", 404

        moto_active = MotosModel.is_active(bikeid)

        try:
            if user.availableMoney > 5:
                if moto_active is True:
                    new_rent = BookingModel(userid, bikeid, None, None, None)
                    new_rent.startDate = datetime.now()
                    MotosModel.change_status(bikeid)

                    new_rent.save_to_db()

                    return {"new_rent": new_rent.json()}, 201
                return "Moto selected is not active", 400
            return "Not money enough", 400
        except:
            return "Something went wrong", 500
Example #2
0
    def put(self):

        data = Booking.parser.parse_args()

        userid = data['userid']
        bikeid = data['bikeid']

        user = AccountsModel.find_by_id(userid)
        bike = MotosModel.find_by_id(bikeid)

        if user is None:
            return "User not found", 404
        if bike is None:
            return "Bike not found", 404

        try:
            admin_user = AccountsModel.find_by_username('admin')

            if admin_user:
                book = BookingModel.finalize_book(userid, bikeid)
                if book is None:
                    return "No renting found", 404
                MotosModel.change_status(bikeid)

                admin_user.availableMoney += book.price
                user.availableMoney -= book.price

                return {"finalized_rent": book.json()}, 201
            return "Admin user not found", 404
        except:
            return "Something went wrong", 500
Example #3
0
    def put(self, id):
        parser = reqparse.RequestParser()

        parser.add_argument('firstname',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('surname',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('email',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('dni',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('dataEndDrivePermission',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('creditCard',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")

        data = parser.parse_args()

        account = AccountsModel.find_by_id(id)
        if account:

            modified_account = AccountsModel(
                data['firstname'], data['surname'], data['email'],
                account.username, data['dni'], data['dataEndDrivePermission'],
                data['creditCard'], account.type, account.latitude,
                account.longitude)
            if account.firstname == modified_account.firstname and account.surname == modified_account.surname and account.email == modified_account.email and account.dni == modified_account.dni and account.dataEndDrivePermission == modified_account.dataEndDrivePermission and account.creditCard == modified_account.creditCard:
                return {
                    "Error": "User {} is up to date".format(account.username)
                }, 400
            AccountsModel.modify_account(id, modified_account)
            return {"account": account.json()}, 200
        return {
            "Error": "Account with identifier {} not found".format(id)
        }, 404