-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (36 loc) · 1.33 KB
/
app.py
File metadata and controls
50 lines (36 loc) · 1.33 KB
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
import os
import json
from flask import Flask, render_template
from flask import Response
from flask_cors import CORS
from model.todo import Todo
from flask import request
app = Flask(__name__)
#app = Flask(__name__, template_folder="static/dist", static_folder="static/dist", static_url_path="")
CORS(app)
@app.route('/')
def hello_method():
return render_template('content.html')
@app.route('/api/getlist')
def getall_method():
res = Todo.get_all()
for r in res:
if "_id" in r: del r["_id"]
return Response(json.dumps(res), mimetype='application/json')
@app.route('/api/deletelist/<string:id>', methods=['DELETE'])
def delete_method(id):
Todo.delete_one(id)
return Response(json.dumps({"result": "ok"}), mimetype='application/json')
@app.route('/api/addlist', methods=['POST'])
def post_method():
data = request.get_json(silent=True)
obj = Todo(data.get("task"), data.get("author"))
obj.save_to_db()
return Response(json.dumps({"result": "ok"}), mimetype='application/json')
@app.route('/api/updatelist', methods=['PUT'])
def update_method():
data = request.get_json(silent=True)
Todo.update_one(data.get("id"),data.get("done"))
return Response(json.dumps({"result": "ok"}), mimetype='application/json')
if __name__ == '__main__':
app.run(host= '0.0.0.0',port=os.getenv('PORT'))