diff options
author | ngharo <nick@ngha.ro> | 2017-12-28 00:48:34 -0600 |
---|---|---|
committer | ngharo <nick@ngha.ro> | 2017-12-28 00:48:34 -0600 |
commit | 67c7dbdd19afcc17816e43ff66873e76101704a5 (patch) | |
tree | 46fb4285199570de63cc593c67198686f6a54a2d /server/buttonDispatcher.py | |
parent | df3f5844ea334a83955efbab7f58861ae6ccd763 (diff) | |
download | imOk-www-67c7dbdd19afcc17816e43ff66873e76101704a5.tar.xz imOk-www-67c7dbdd19afcc17816e43ff66873e76101704a5.zip |
Got CRU part of CRUD working decently
Diffstat (limited to 'server/buttonDispatcher.py')
-rw-r--r-- | server/buttonDispatcher.py | 38 |
1 files changed, 38 insertions, 0 deletions
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' |