-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
50 lines (40 loc) · 1.42 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# save this as app.py
import json
from flask import Flask
from flask import jsonify
from flask_cors import CORS # needs pip install Flask-CORS
from user_handling import get_user as user_get_user
from user_handling import get_characteristics as user_get_characteristics
from task_handling import set_done as task_set_done
from task_handling import set_do_later as task_set_later
from task_handling import add_task as task_add_task
from task_handling import get_tasks as task_get_tasks
from db_controller import get_task_collection, get_user_collection
app = Flask(__name__)
CORS(app)
# call like this: http://127.0.0.1:5000/gettasks/foo
@app.route("/<search>", defaults={'search': None})
@app.route("/get-tasks/<search>", methods=["GET"])
def get_tasks(search):
return task_get_tasks(search, sorting="importance-deadline")
@app.route("/add-task", methods=["POST"])
def add_tasks(tasks: list):
for task in tasks:
task_add_task(task)
return
@app.route("/set-done/<int:task_id>", methods=["POST"])
def set_done(task_id: int):
task_set_done(task_id)
return
@app.route("/set-do-later/<int:task_id>", methods=["POST"])
def do_later(task_id: int):
task_set_later(task_id)
return
@app.route("/get-user", methods=["GET"])
def get_user():
return user_get_user()
@app.route("/get-characteristics", methods=["GET"])
def get_characteristics():
return user_get_characteristics()
if __name__ == "__main__":
app.run()