forked from cti-unipar/parking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (40 loc) · 1.22 KB
/
app.py
File metadata and controls
54 lines (40 loc) · 1.22 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
from http import HTTPStatus
from flask import Flask, request
from model import *
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World! UNIPARKING"
@app.route("/types", methods=["GET"])
def list_types():
return Types.objects().to_json()
@app.route("/types/<string:type_id>", methods=['GET'])
def get_type(type_id):
try:
type = Types.objects.get(id=type_id)
return type.to_json()
except DoesNotExist:
return '', HTTPStatus.NOT_FOUND
@app.route("/types", methods=['POST'])
def create_type():
data = request.get_json()
new_type = Types(**data)
new_type.save()
return new_type.to_json(), HTTPStatus.CREATED
@app.route("/types/<string:type_id>", methods=['PUT'])
def update_type(type_id):
data = request.get_json()
try:
type = Types.objects.get(id=type_id)
type.update(**data)
return '', HTTPStatus.ACCEPTED
except DoesNotExist:
return '', HTTPStatus.NOT_FOUND
@app.route("/types/<string:type_id>", methods=['DELETE'])
def delete_type(type_id):
try:
type = Types.objects.get(id=type_id)
type.delete()
return "", HTTPStatus.NO_CONTENT
except DoesNotExist:
return "", HTTPStatus.NOT_FOUND