Torma Kristóf
00cacf77b7
All checks were successful
continuous-integration/drone/push Build is passing
33 lines
920 B
Python
33 lines
920 B
Python
#!/usr/bin/env python3
|
|
from flask_restful import Resource
|
|
from flask import request, abort
|
|
from marshmallow import ValidationError
|
|
|
|
from model import db, Meal
|
|
from schemas import MealSchema
|
|
|
|
|
|
class MealIndividualResource(Resource):
|
|
|
|
mealschema = MealSchema(many=False)
|
|
|
|
def put(self, mealid):
|
|
body = request.get_json()
|
|
|
|
try:
|
|
self.mealschema.load(body, instance=Meal.query.get(mealid).first_or_404())
|
|
db.session.commit()
|
|
return '', 200
|
|
except ValidationError as error:
|
|
abort(406, error.messages)
|
|
|
|
def get(self, mealid):
|
|
meals = Meal.query.filter_by(id=mealid).first_or_404()
|
|
return self.mealschema.dump(list(meals)), 200
|
|
|
|
def delete(self, mealid):
|
|
meal = Meal.query.filter_by(id=mealid).first_or_404()
|
|
db.session.delete(meal)
|
|
db.session.commit()
|
|
return self.mealschema.dump(meal), 200
|