Example #1
0
 def post(self):
     session = Session()
     args = user_put_args.parse_args()
     exist = User(username=args['username'],
                  password=hash_password(args['password']))
     session.add(exist)
     session.commit()
     return exist, 201
Example #2
0
    def post(self):
        session = Session()
        args = wallets_put_args.parse_args()
        user = auth.current_user()
        user_id = user.user_id

        wallet = Wallets(user_id=user_id, name=args['name'], uah=args['uah'])
        session.add(wallet)
        session.commit()
        return wallet, 200
Example #3
0
def delete_wallet(user_id):
    session = Session()
    try:
        wallet = session.query(Wallets).filter_by(user_id=int(user_id)).one()
    except:
        abort(404, description="Wallet not found")

    session.delete(wallet)

    session.commit()

    return jsonify({"Success": "Wallet has been deleted"}), 200
Example #4
0
    def delete(self):
        session = Session()
        # result = session.query(User).filter_by(id=user_id).first()
        exist = auth.current_user()
        if exist:
            print("User has been deleted")
        if not exist:
            abort(500, message="User doesn't exist, cannot delete")

        exist = session.merge(exist)
        session.delete(exist)
        session.commit()
        return "User deleted", 204
Example #5
0
def create_wallet():
    session = Session()

    data = request.get_json()

    try:
        wallet = Wallets(**data)
    except:
        return jsonify({"Message": "Invalid input"}), 405
    #  if not "owner_uid" != User.user_id:
    #     abort(404, description="Wallet owner not found")

    session.add(wallet)
    session.commit()

    return jsonify({"Success": "Wallet has been created"}), 200
Example #6
0
    def put(self):
        session = Session()
        args = user_update_args.parse_args()
        # result = session.query(User).filter_by(id=user_id).first()
        exist = auth.current_user()
        if not exist:
            abort(404, message="User doesn't exist, cannot update")
        if args['username']:
            exist.username = args['username']
        if args['password']:
            exist.password = hash_password(args['password'])

        exist = session.merge(exist)
        session.add(exist)
        session.commit()

        return exist
Example #7
0
def update_wallet(user_id):
    session = Session()

    try:
        wallet = session.query(Wallets).filter_by(user_id=int(user_id)).one()
    except:
        abort(404, description="Wallet not found")

    data = request.get_json()
    try:

        if data.get('name', None):
            wallet.name = data['name']

    except:
        abort(405, description="Invalid input")

    session.commit()

    return jsonify({"Success": "Wallet has been changed"}), 200