From 67c7dbdd19afcc17816e43ff66873e76101704a5 Mon Sep 17 00:00:00 2001 From: ngharo Date: Thu, 28 Dec 2017 00:48:34 -0600 Subject: Got CRU part of CRUD working decently --- server/buttonDispatcher.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 server/buttonDispatcher.py (limited to 'server/buttonDispatcher.py') diff --git a/server/buttonDispatcher.py b/server/buttonDispatcher.py new file mode 100644 index 0000000..5dac61c --- /dev/null +++ b/server/buttonDispatcher.py @@ -0,0 +1,38 @@ +import json +import cherrypy +from button import loadAll, Button +from lib import uuid + +@cherrypy.expose +class ButtonDispatcher(object): + def GET(self, id=None): + if id is None: + return json.dumps(loadAll()) + elif uuid.validate(id): + button = Button() + return button.loadById(id).toJSON() + else: + raise cherrypy.HTTPError(400, 'Invalid ID') + + def POST(self, id, status): + if not uuid.validate(id): + raise cherrypy.HTTPError(401) + + button = Button() + button.loadById(id) + + cherrypy.log("Updating status to " + str(status)) + button.status = status + button.save() + + return button.toJSON() + + def PUT(self): + cherrypy.log('Generating new button') + button = Button() + button.id = uuid.gen() + + return button.save().toJSON() + + def DELETE(self): + return 'DELETE BUTTON' -- cgit v1.2.3