예제 #1
0
파일: app.py 프로젝트: mauhftw/pets-api
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
예제 #2
0
파일: app.py 프로젝트: mauhftw/pets-api
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
예제 #3
0
파일: app.py 프로젝트: mauhftw/pets-api
def get_pet(id):

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