Cancel a booking by Booking ID """ @jwt_required def delete(self, booking_id): """ :param int booking_id: required as url paramemter - JWT required. - Header: `\"Authorization\": \"Bearer {access_token}\"` """ try: result_booking = bookings.BookingModel.query.filter_by( booking_id=booking_id).delete() db.session.commit() return ( { 'message': "Your booking {} has been canceled.".format(booking_id) }, 200, ) except SQLAlchemyError as e: error = str(e.__dict__['orig']) return {'message': error}, 500 api.add_resource(MyBookedCars, '/bookings/me') api.add_resource(NewBooking, '/bookings/new') api.add_resource(CancelBooking, '/bookings/cancel/<int:booking_id>')
class Profile(Resource): """ View current user profile. """ @jwt_required def get(self): """ - JWT required. - Header: `\"Authorization\": \"Bearer {access_token}\"` """ current_user = get_jwt_identity() username = current_user['username'] try: result = users.UserModel.query.filter_by(username=username).first() if result is None: return {'Error': 'User not found'}, 404 return { 'username': result.username, 'first_name': result.first_name, 'last_name': result.last_name, 'email': result.email, #'role': result.role } except SQLAlchemyError as se: error = str(se.__dict__['orig']) return {"Error": error}, 500 api.add_resource(Register, '/users/register') api.add_resource(Profile, '/users/me')
""" current_user = get_jwt_identity() username = current_user['username'] args = parser_change_password.parse_args() old_password = args['old_password'] new_password = args['new_password'] result = check_user_exists(username) # password string stored_password = result.password verify_password(old_password, stored_password) try: # user = users.UserModel.query.filter_by(username=current_user).first() result.password = sha256.hash(new_password) db.session.commit() identity = {'username': result.username, 'role': result.role} access_token = create_access_token(identity=identity) refresh_token = create_refresh_token(identity=identity) return { 'access_token': access_token, "refresh_token": refresh_token }, 201 except SQLAlchemyError as e: error = str(e.__dict__['orig']) return {"Error": error}, 500 api.add_resource(AccessToken, '/auth/new') api.add_resource(TokenRefresh, '/auth/refresh') api.add_resource(ChangePassword, '/auth/password')
from master import api from master.resources.null import Null from master.resources.instance import Instance from master.resources.authenticate import Authenticate from master.resources.version import Version from master.resources.history_graph import HistoryGraph api.add_resource(Null, '/null') api.add_resource(Instance, '/instance/', '/instance/<string:id>') api.add_resource(Version, '/version') api.add_resource(Authenticate, '/authenticate') api.add_resource(HistoryGraph, '/history/', '/history/<int:history_count>')
from master import api from master.resources.null import Null from master.resources.instance import Instance from master.resources.authenticate import Authenticate from master.resources.version import Version from master.resources.history_graph import HistoryGraph from master.resources.localization import Localization from master.resources.server import Server api.add_resource(Null, '/null') api.add_resource(Instance, '/instance/', '/instance/<string:id>') api.add_resource(Version, '/version') api.add_resource(Authenticate, '/authenticate') api.add_resource(HistoryGraph, '/history/', '/history/<int:history_count>') api.add_resource(Localization, '/localization/', '/localization/<string:language_tag>') api.add_resource(Server, '/server')
} all_bookings = bookings.BookingModel.query.filter_by( car_number=item.car_number).all() if len(all_bookings) > 0: booking_list = list( map( lambda i: { 'booking_id': i.booking_id, 'username': i.username, 'departure_time': i.departure_time.isoformat(), 'return_time': i.return_time.isoformat(), 'created_at': i.created_at.isoformat(), }, all_bookings, )) car_item['bookings'] = booking_list car_list.append(car_item) return car_list, 200 except SQLAlchemyError as e: error = str(e.__dict__['orig']) return {'message': error}, 500 api.add_resource(NewCar, '/cars/new') api.add_resource(CarDetail, '/cars/detail/<string:car_number>') api.add_resource(AvailableCars, '/cars/available') api.add_resource(SearchCars, '/cars/search') api.add_resource(AllCars, '/cars/all')