-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGate.py
More file actions
executable file
·61 lines (48 loc) · 2.03 KB
/
Gate.py
File metadata and controls
executable file
·61 lines (48 loc) · 2.03 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
from flask import Flask, jsonify, abort, request
from Server import *
import ApiFunctions
class Gate:
def __init__(self, id, name, airport_id):
self.id = id
self.name = name
self.airport_id = airport_id
def to_json(self):
return {'id': self.id, 'name': self.name,
'airport_id': self.airport_id}
@app.route('/goshna/api/gates', methods=['GET'])
def get_gates():
gates = []
results = ApiFunctions.query_db("SELECT * FROM gates")
for row in results:
gate = Gate(row['id'], row['name'], row['airport_id'])
gates.append(gate.to_json())
return jsonify({'gates': gates})
@app.route('/goshna/api/gates', methods=['POST'])
def create_gate():
if not request.json or not 'name' in request.json or not 'airport_id' in request.json:
abort(400)
name = request.json['name']
airport_id = request.json['airport_id']
if not name:
abort(400)
result = ApiFunctions.post_db("INSERT INTO gates VALUES (NULL, ?, ?)",
[name, airport_id]);
inserted_id = c.lastrowid
print u'Inserted new gate at row ' + str(inserted_id)
return jsonify({'id': str(inserted_id)}), 201
@app.route('/goshna/api/gates/find', methods=['POST'])
def find_gates():
if not request.json or not 'id' in request.json:
abort(400)
airport_id = request.json['id']
gates = []
results = ApiFunctions.query_db("SELECT * FROM gates where airport_id=?", [airport_id]);
for row in results:
gate = Gate(row['id'], row['name'], row['airport_id'])
gates.append(gate.to_json())
return jsonify({'gates': gates})
@app.route('/goshna/api/gates/<int:gate_id>', methods=['DELETE'])
def delete_gate(gate_id):
ApiFunctions.post_db("DELETE FROM gates WHERE id=?", [gate_id])
print u'Deleted listening_user with ID ' + str(inserted_id)
return jsonify({'result': True})