Exemple #1
0
def delete_pet(id):

    pet = Pet.find(id)
    if pet is None:
        return jsonify({'message': 'pet doesn\'t exist'}), 404

    if pet.delete():
        return jsonify({'message': 'pet has been successfully deleted'}), 200
    return jsonify({'message': 'oops! something went wrong'}), 500
Exemple #2
0
def update_pet(id):
    #check = reqparse.RequestParser()	#checks are missing
    data = request.get_json()
    pet = Pet.find(id)

    if pet is None:
        return jsonify({'message': 'pet doesn\'t exist'}), 404

    pet.name = data['name']
    pet.type = data['type']
    pet.age = data['age']
    pet.specie = data['specie']
    if pet.update():
        return jsonify({'message': 'pet has been successfully updated'}), 200
    return jsonify({'message': 'oops! something went wrong'}), 500
Exemple #3
0
def get_pet(id):

    pet = Pet.find(id)
    if pet is None:
        return jsonify({'message': 'pet is not present'}), 404
    return pet.to_json()