Changes to doc and to API, a bit more stable

This commit is contained in:
2019-10-31 11:35:16 +01:00
parent ea9f7b6436
commit 9de38014be
6 changed files with 71 additions and 23 deletions

21
api.py
View File

@@ -1,5 +1,5 @@
#!/usr/bin/python3
BUILD = 20
BUILD = 21
API_VER = 1
##It can be run directly with "waitress-serve --port=3333 api:api"
import falcon
@@ -91,22 +91,27 @@ class getGroups(object): #Get local groups of a Computer
else:
data = sql.select("SELECT * FROM GROUPS WHERE ID_G IN (SELECT ID_G FROM COMPUTER_GROUP WHERE ID_C = '"+ComputerID+"') ORDER BY Name ASC")
response.media = data
##
# getComputers: List all computers with data
# /get/computers?
# @param ComputerID/ComputerName -> To see all data only for one computer
##
class getComputers(object):
def on_get(self,request, response):
logit(request)
ComputerID=None
for key, value in request.params.items():
if key == "ComputerName":
ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"'")[0]['ID_C'])
ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"' LIMIT 1")[0]['ID_C'])
if key == "ComputerID":
ComputerID = value
if ComputerID is None:
data = sql.select("SELECT * FROM COMPUTERS ORDER BY Name ASC")
if ComputerID is not None: # One computer
data = sql.select("SELECT * FROM COMPUTERS WHERE ID_C = '"+ComputerID+"') ORDER BY Name ASC LIMIT 1")
response.media = data
else:
data = sql.select("SELECT * FROM COMPUTERS WHERE ID_C = '"+ComputerID+"') ORDER BY Name ASC")
else: # All computers
data = sql.select("SELECT * FROM COMPUTERS ORDER BY Name ASC")
response.media = data
@@ -794,7 +799,7 @@ api.add_route('/del/groupscook', delGroupsCook()) #Delete all groups of a cook
api.add_route('/del/cleancook', delCleanCook()) #Delete status of a cook for all computers (Restart cook). No delete groups
api.add_route('/get/computerexists', getComputerExists()) #Returns 0 or 1 (name status)
api.add_route('/get/computers', getComputers()) #Get list of computer
api.add_route('/get/computers', getComputers()) #Get list of computer and all data in array
api.add_route('/get/cookall', getCookAll()) #Get all cooks implemented in one group at least
api.add_route('/get/cookgrp', getCookGrp()) # See cooks that have a determinated group
api.add_route('/get/cookpend', getCookPend()) #Get cooks pending to implement to a computer