Exemplo n.º 1
0
def update_landlord_data(landlord_id: int, args: dict):
    landlord = Landlord.query.get_or_404(
        landlord_id, description=f"Landlord with id {landlord_id} not found")

    landlord_with_this_identifier = Landlord.query.filter(
        Landlord.identifier == args["identifier"]).first()
    if (landlord_with_this_identifier is not None and
            landlord_with_this_identifier.identifier != landlord.identifier):
        abort(
            409,
            description=f'Landlord with identifier {args["identifier"]}'
            " already exists",
        )

    landlord_with_this_email = Landlord.query.filter(
        Landlord.email == args["email"]).first()
    if (landlord_with_this_email is not None
            and landlord_with_this_email.email != landlord.email):
        abort(409,
              description=f'Landlord with email {args["email"]}'
              " already exists")

    landlord.identifier = args["identifier"]
    landlord.email = args["email"]
    landlord.first_name = args["first_name"]
    landlord.last_name = args["last_name"]
    landlord.phone = args["phone"]
    landlord.address = args["address"]
    description = args.get("description")
    if description is not None:
        landlord.description = description
    db.session.commit()

    return jsonify({"success": True, "data": landlord_schema.dump(landlord)})
Exemplo n.º 2
0
def update_landlord_data(landlord_id: int, args: dict):
    landlord = Landlord.query.get_or_404(
        landlord_id, description=f'Landlord with id {landlord_id} not found')

    landlord_with_this_identifier = Landlord.query.filter(
        Landlord.identifier == args['identifier']).first()
    if landlord_with_this_identifier is not None and \
        landlord_with_this_identifier.identifier != landlord.identifier:
        abort(409,
              description=f'Landlord with identifier {args["identifier"]}'
              ' already exists')

    landlord_with_this_email = Landlord.query.filter(
        Landlord.email == args['email']).first()
    if landlord_with_this_email is not None and \
        landlord_with_this_email.email != landlord.email:
        abort(409,
              description=f'Landlord with email {args["email"]}'
              ' already exists')

    landlord.identifier = args['identifier']
    landlord.email = args['email']
    landlord.first_name = args['first_name']
    landlord.last_name = args['last_name']
    landlord.phone = args['phone']
    landlord.address = args['address']
    description = args.get('description')
    if description is not None:
        landlord.description = description
    db.session.commit()

    return jsonify({'success': True, 'data': landlord_schema.dump(landlord)})
Exemplo n.º 3
0
def update_landlord_password(landlord_id: str, args: dict):
    landlord = Landlord.query.get_or_404(
        landlord_id, description=f"Landlord with id {landlord_id} not found")

    if not landlord.is_password_valid(args["current_password"]):
        abort(401, description="Invalid password")

    landlord.password = generate_hashed_password(args["new_password"])
    db.session.commit()

    return jsonify({"success": True, "data": landlord_schema.dump(landlord)})
Exemplo n.º 4
0
def update_landlord_password(landlord_id: str, args: dict):
    landlord = Landlord.query.get_or_404(
        landlord_id, description=f'Landlord with id {landlord_id} not found')

    if not landlord.is_password_valid(args['current_password']):
        abort(401, description='Invalid password')

    landlord.password = generate_hashed_password(args['new_password'])
    db.session.commit()

    return jsonify({'success': True, 'data': landlord_schema.dump(landlord)})
Exemplo n.º 5
0
def get_one_landlord(landlord_id: int):
    landlord = Landlord.query.get_or_404(
        landlord_id, description=f"Landlord with id {landlord_id} not found")

    return jsonify({"success": True, "data": landlord_schema.dump(landlord)})
Exemplo n.º 6
0
def get_current_landlord(landlord_id: str):
    landlord = Landlord.query.get_or_404(
        landlord_id, description=f'Landlord with id {landlord_id} not found')

    return jsonify({'success': True, 'data': landlord_schema.dump(landlord)})