Torma Kristóf
70c473dc76
All checks were successful
continuous-integration/drone/push Build is passing
29 lines
725 B
Python
29 lines
725 B
Python
#!/usr/bin/env python3
|
|
from flask_restful import Resource
|
|
from flask import request, current_app, abort
|
|
from marshmallow import ValidationError
|
|
|
|
from model import db, Meal
|
|
from schemas import MealSchema
|
|
|
|
|
|
class MealBaseResource(Resource):
|
|
|
|
mealschema = MealSchema(many=False)
|
|
mealschemas = MealSchema(many=True)
|
|
|
|
def post(self):
|
|
body = request.get_json()
|
|
|
|
try:
|
|
loadedobj = self.mealschema.load(body)
|
|
db.session.add(loadedobj)
|
|
db.session.commit()
|
|
return '', 204
|
|
except ValidationError as error:
|
|
abort(406, error.messages)
|
|
|
|
def get(self):
|
|
meals = Meal.query.all()
|
|
return self.mealschemas.dump(list(meals)), 200
|