Beispiel #1
0
def update_pet_with_form(pet_id):  # noqa: E501
    """Updates a pet in the store with form data

     # noqa: E501

    :param pet_id: ID of pet that needs to be updated
    :type pet_id: int
    :param name: Updated name of the pet
    :type name: str
    :param status: Updated status of the pet
    :type status: str

    :rtype: None
    """
    pet = Pet.query.get(pet_id)
    pet_name = request.form['pet_name']
    category_value = request.form['category_value']
    status_value = request.form['status_value']
    dis = 'pet status in the store'

    status = Status.query.filter_by(value=status_value, dis=dis).first()
    status_id = status.id
    category = Category.query.filter_by(cat_name=category_value).first()
    category_id = category.id

    pet.pet_name = pet_name
    pet.category_id = category_id
    pet.status_id = status_id

    db.session.commit()

    return pet_schema.jsonify(pet)
Beispiel #2
0
def update_pet():  # noqa: E501
    """Update an existing pet

     # noqa: E501

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    :rtype: None
    """
    pet_id = request.json['pet_id']
    pet_name = request.json['pet_name']
    category_value = request.json['category_value']
    status_value = request.json['status_value']
    dis = 'pet status in the store'

    status = Status.query.filter_by(value=status_value, dis=dis).first()
    status_id = status.id
    category = Category.query.filter_by(cat_name=category_value).first()
    category_id = category.id

    pet = Pet.query.get(pet_id)
    pet.pet_name = pet_name
    pet.category_id = category_id
    pet.status_id = status_id

    db.session.commit()
    return pet_schema.jsonify(pet)
Beispiel #3
0
def get_pet_by_id(pet_id):  # noqa: E501
    """Find pet by ID

    Returns a single pet # noqa: E501

    :param pet_id: ID of pet to return
    :type pet_id: int

    :rtype: Pet
    """
    pet = Pet.query.get(pet_id)

    return pet_schema.jsonify(pet)
Beispiel #4
0
def delete_pet(pet_id):  # noqa: E501
    """Deletes a pet

     # noqa: E501
    :param pet_id: Pet id to delete
    :type pet_id: int
    :param api_key: 
    :type api_key: str

    :rtype: None
    """
    pet = Pet.query.get(pet_id)
    photourls = PhotoURL.query.filter_by(pet_id=pet_id).all()
    for i in photourls:
        db.session.delete(i)
    db.session.delete(pet)
    db.session.commit()

    return pet_schema.jsonify(pet)
Beispiel #5
0
def add_pet():  # noqa: E501
    """Add a new pet to the store

     # noqa: E501

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    :rtype: None
    """
    pet_name = request.json['pet_name']
    category_value = request.json['category']
    status_value = request.json['status']
    dis = 'pet status in the store'
    status = Status.query.filter_by(value=status_value, dis=dis).first()
    status_id = status.id
    category = Category.query.filter_by(cat_name=category_value).first()
    cat_id = category.id
    new_pet = Pet(pet_name, cat_id, status_id)
    db.session.add(new_pet)
    db.session.commit()

    return pet_schema.jsonify(new_pet)