def put(self): userDetails = UserModel.find_by_username(get_jwt_identity()) if not userDetails: return {'message': 'Unauthorized'}, 400 currentUser = get_jwt_identity() _editNote_parser = reqparse.RequestParser() _editNote_parser.add_argument('item', type=str, required=True, help='Item name required') _editNote_parser.add_argument('Note', type=str, required=False) data = _editNote_parser.parse_args() checkItem = CartModel.find_by_username_item_cart( str(currentUser).lower().strip(), str(data['item']).title().strip()) if not checkItem: return {'message': 'Requested item not in your cart'}, 400 try: checkItem.note = data['Note'] checkItem.save_to_db() return {'message': 'Note Saved Successfully'}, 200 except Exception as e: print(f'Error while Saving note {e}') return {'message': 'Something went wrong'}, 500
def post(self): _userlogin = reqparse.RequestParser() _userlogin.add_argument('username', type=str, required=True, help='Username is required') _userlogin.add_argument('password', type=str, required=True, help='Password is required') data = _userlogin.parse_args() userCheck = UserModel.find_by_username( str(data['username']).lower().strip()) if userCheck: access_token = create_access_token(identity=userCheck.username, fresh=True) refresh_token = create_refresh_token(userCheck.username) return { 'access_token': access_token, 'refresh_token': refresh_token }, 200 return {'message': 'Invalid credentials'}, 400
def post(self): check_user = UserModel.find_by_username(get_jwt_identity()) if not check_user: return {'message': 'Unauthorized'}, 401 identity = get_jwt_identity() access_token = create_access_token(identity=identity, fresh=True) return {'access_token': access_token}, 200
def get(self): userDetails = UserModel.find_by_username(get_jwt_identity()) if not userDetails: return {'message': 'Unauthorized'}, 400 currentUser = get_jwt_identity() if currentUser: return {'user': currentUser}, 200 return {'message': 'Unauthorized'}, 400
def post(self): data = _customer_parser.parse_args() if len(str(data['name']).strip()) > 16: return { 'message': 'Customer name length exceeding than 16 characters' }, 400 if len(str(data['username']).strip()) > 16: return { 'message': 'Customer username length exceeding than 16 characters' }, 400 if len(str(data['username']).strip()) < 6: return { 'message': 'username must have six or more than six characters' }, 400 if len(str(data['password']).strip()) < 6: return { 'message': 'Password must have six or more than six characters' }, 400 if len(str(data['password']).strip()) > 16: return { 'message': 'Password length exceeding than 16 characters' }, 400 if UserModel.find_by_username(str(data['username']).lower().strip()): return {'message': 'username not available'}, 400 if data['password'] != data['confirm_password']: return {'message': 'Password and confirm password not same'}, 400 try: new_user = UserModel( str(data['name']).title().strip(), str(data['username']).lower().strip(), str(data['password'])) new_user.save_to_db() return {'message': 'You are successfully registered'}, 200 except Exception as e: print(f'Exception in adding new user {e}') return {'message': 'Something went wrong'}, 500
def delete(self, item): userDetails = UserModel.find_by_username(get_jwt_identity()) if not userDetails: return {'message': 'Unauthorized'}, 400 currentUser = get_jwt_identity() checkItem = CartModel.find_by_username_item_cart( str(currentUser).lower().strip(), str(item).title().strip()) if not checkItem: return {'message': 'Requested item not in your cart'}, 400 checkItem.delete_from_db() return {'message': f'{item} deleted successfully from your cart'}, 200
def get(self): userDetails = UserModel.find_by_username(get_jwt_identity()) if not userDetails: return {'message': 'Unauthorized'}, 400 currentUser = get_jwt_identity() cartItemsExists = CartModel.find_by_username_cart(currentUser) if cartItemsExists: return { 'cart': list( map(lambda x: x.cart_json(), CartModel.find_by_username_cart(currentUser))) }, 200 return {'message': 'Items not found'}, 400
def post(self): userDetails = UserModel.find_by_username(get_jwt_identity()) if not userDetails: return {'message': 'Unauthorized'}, 400 currentUser = get_jwt_identity() data = _add_cart_parser.parse_args() inDbCheck = DatabaseModel.find_all_by_name( str(data['item']).title().strip()) if not inDbCheck: return {'message': 'Requested item not in database'}, 400 if str(data['qty']).isnumeric(): print('true, Is numeric') else: return {'message': 'Quantity must be in numerical'}, 400 checkItem = CartModel.find_by_username_item_cart( str(currentUser).lower().strip(), str(data['item']).title().strip()) if checkItem: return {'message': 'Item already in your database'}, 400 discountedPrice = int(inDbCheck.price_per_kg) - ( (int(inDbCheck.discount_percentage) / 100) * (int(inDbCheck.price_per_kg))) try: addItemToCart = CartModel( str(currentUser).lower().strip(), str(data['item']).title().strip(), data['qty'], data['kg'], str(round(discountedPrice)), ) addItemToCart.save_to_db() return {'message': 'Item added to your cart'}, 200 except Exception as e: print(f'Exception while adding to cart {e}') return {'message': 'Something went wrong'}, 500
def put(self, item, qty): userDetails = UserModel.find_by_username(get_jwt_identity()) if not userDetails: return {'message': 'Unauthorized'}, 400 currentUser = get_jwt_identity() checkItem = CartModel.find_by_username_item_cart( str(currentUser).lower().strip(), str(item).title().strip()) if not checkItem: return {'message': 'Requested item not in your cart'}, 400 if qty.isnumeric(): print('true, Is numeric') else: return {'message': 'Quantity must be in numerical'}, 400 try: checkItem.qty = str(qty) checkItem.save_to_db() return {'message': 'Quantity updated'}, 200 except Exception as e: print(f'Exception while updating quantity {e}') return {'message': 'Something went wrong'}, 500