-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapi_mock.py
More file actions
73 lines (63 loc) · 2.14 KB
/
api_mock.py
File metadata and controls
73 lines (63 loc) · 2.14 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from flask import Flask, request
from flask_cors import CORS
import json
import os
import datetime
import uuid
app = Flask("Bubbly API Mock")
CORS(app)
uuid1 = str(uuid.uuid4())
uuid2 = str(uuid.uuid4())
notes = {
uuid1: {
'noteid': uuid1,
'title': 'This is a title',
'lastModifiedDate': datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S"),
'content': '## This is the note content\n\nIn *markdown* format.'
},
uuid2: {
'noteid': uuid2,
'title': 'This is a another title',
'lastModifiedDate': datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S"),
'content': '## This is the note content\n\nIn *markdown* format.'
}
}
@app.route("/getNotes", methods=["get"])
def getNotes():
return json.dumps(list(notes.values()))
@app.route("/getNote", methods=["post"])
def getNote():
noteid = request.json['noteid']
if noteid in notes:
return json.dumps(notes[noteid])
else:
return "{}"
@app.route("/createNote", methods=["post"])
def createNote():
title = request.json['title']
content = request.json['content']
noteid = str(uuid.uuid4())
notes[noteid] = {'noteid': noteid, 'title': title, 'content': content,
'lastModifiedDate': datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S")}
return noteid
@app.route("/updateNote", methods=["post"])
def updateNote():
noteid = request.json['noteid']
title = request.json['title']
content = request.json['content']
if noteid in notes:
notes[noteid] = {'noteid': noteid, 'title': title, 'content': content,
'lastModifiedDate': datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S")}
return "OK"
else:
return "Not found"
@app.route("/deleteNote", methods=["post"])
def deleteNote():
noteid = request.json['noteid']
if noteid in notes:
del notes[noteid]
return "OK"
else:
return "Not found"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=os.environ['PORT'])