Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mahroo #54

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion backend/app/meal_delivery_task/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import meal_delivery_task
from flask import jsonify, abort, request
from flask import Flask, jsonify, abort, request

from app import db
from app.models import MealDeliveryTask

Expand Down Expand Up @@ -57,3 +58,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)