Exemplo n.º 1
0
def delete(dog_id: int):
    dog = verify_auth(dog_id)
    if not dog:
        return build_api_response(HTTPStatus.UNAUTHORIZED)

    Dog.query.filter_by(id=dog.id).delete()
    db.session.commit()
    return build_api_response(HTTPStatus.OK)
Exemplo n.º 2
0
def delete(dog_id: int):
    dog = verify_auth(dog_id)

    if not dog:
        return build_api_response(HTTPStatus.UNAUTHORIZED)

    dog.delete()
    db.session.commit()

    return build_api_response(HTTPStatus.OK)
Exemplo n.º 3
0
def get_interests(dog_id: int):

    dog_verify = verify_auth(dog_id)

    if not dog_verify:
        return build_api_response(HTTPStatus.UNAUTHORIZED)

    interest = Interest.query.filter_by(dog_id=dog_id).first()

    if not interest:
        return build_api_response(HTTPStatus.NOT_FOUND)

    return {'data': InterestSchema().dump(interest)}, HTTPStatus.OK
Exemplo n.º 4
0
def get_dog_id(interest_id: int):

    dog_verify = verify_auth(interest_id)

    if not dog_verify:
        return build_api_response(HTTPStatus.UNAUTHORIZED)

    dog = Interest.query.get(interest_id)

    if not dog:
        return build_api_response(HTTPStatus.NOT_FOUND)

    return {'data': InterestSchema().dump(dog)}, HTTPStatus.OK
Exemplo n.º 5
0
def update(dog_id: int):
    data = request.get_json()
    dog = verify_auth(dog_id)

    if not dog:
        return build_api_response(HTTPStatus.UNAUTHORIZED)

    dog.name = data['name'] if data.get('name') else dog.name
    dog.details = data['details'] if data.get('details') else dog.details
    dog.breed_id = data['breed_id'] if data.get('breed_id') else dog.breed_id
    dog.gender = data['gender'] if data.get('gender') else dog.gender

    db.session.commit()
    return {'data': dog_schema.dump(dog)}, HTTPStatus.OK
Exemplo n.º 6
0
def update_interest(dog_id: int):

    dog_verify = verify_auth(dog_id)

    if not dog_verify:
        return build_api_response(HTTPStatus.UNAUTHORIZED)

    data = request.get_json()

    dog = Interest.query.filter_by(dog_id=dog_id)

    if not dog:
        return build_api_response(HTTPStatus.NOT_FOUND)

    dog.breed_id = data['breed_id'] if data.get('breed_id') else dog.breed_id
    dog.gender_interest = data['gender_interest'] if data.get(
        'gender_interest') else dog.gender_interest

    try:
        db.session.commit()
        return build_api_response(HTTPStatus.OK)
    except IntegrityError:
        return build_api_response(HTTPStatus.NOT_FOUND)