def create_goal(): try: # This portion is the POST request request_body = request.get_json() new_goal = Goal(title=request_body["title"]) db.session.add(new_goal) db.session.commit() return {"goal": new_goal.to_json_goal()}, 201 except KeyError: return {"details": "Invalid data"}, 400
def create_goal(): request_body = request.get_json() if "title" not in request_body: return ({"details": "Invalid data"}), 400 else: add_goal = Goal(title=request_body["title"]) db.session.add(add_goal) db.session.commit() return make_response({"goal": add_goal.to_json_goal()}, 201)