From 54bbaef5428cbe14c1cde6a4eed08350952bcde6 Mon Sep 17 00:00:00 2001 From: mahroo12 Date: Tue, 8 Feb 2022 14:06:01 -0500 Subject: [PATCH 1/2] added the endpoint for create task --- backend/app/meal_delivery_task/routes.py | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/backend/app/meal_delivery_task/routes.py b/backend/app/meal_delivery_task/routes.py index 436b731..0b6d810 100644 --- a/backend/app/meal_delivery_task/routes.py +++ b/backend/app/meal_delivery_task/routes.py @@ -14,3 +14,35 @@ def delete_meal_delivery_task(id): db.session.commit() return jsonify(m.serialize) + +# create a mealDeliveryTask +@meal_delivery_task.route("", methods=["POST"]) +def create_meal_delivery_task(): + data = request.get_json(force=True) + id = data.get("id") + address = data.get("address") + date = data.get("date") + time = data.get("time") + is_complete = data.get("is_complete") + + # check if all fields are empty, if so it's a garbage post + if ( + id == "" + and address == "" + and date == "" + and time == "" + and (is_complete == False or is_complete == True) + ): + abort(400, "Cannot have all empty fields for a new task") + + new_meal_delivery_task = MealDeliveryTask( + id = id, + address = address, + date = date, + time = time, + is_complete = is_complete, + ) + + db.session.add(new_meal_delivery_task) + db.session.commit() + return jsonify(new_meal_delivery_task.serialize) \ No newline at end of file From 7a12b19520b19a8cd9eb7106adb9ff97ff5c16af Mon Sep 17 00:00:00 2001 From: mahroo12 Date: Tue, 22 Mar 2022 15:54:35 -0400 Subject: [PATCH 2/2] added a package --- backend/app/meal_delivery_task/routes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/app/meal_delivery_task/routes.py b/backend/app/meal_delivery_task/routes.py index 0b6d810..5701745 100644 --- a/backend/app/meal_delivery_task/routes.py +++ b/backend/app/meal_delivery_task/routes.py @@ -1,5 +1,6 @@ from . import meal_delivery_task from flask import Flask, jsonify, abort +from flask import request from app import db from app.models import MealDeliveryTask