From f920c7da0618fd9f4181c2c78ef054e324185355 Mon Sep 17 00:00:00 2001 From: ngharo Date: Sun, 31 Dec 2017 22:16:32 -0600 Subject: Makefile: compile Babel and Sass source files to index.* --- server/buttonDispatcher.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'server/buttonDispatcher.py') diff --git a/server/buttonDispatcher.py b/server/buttonDispatcher.py index 59672d6..8938288 100644 --- a/server/buttonDispatcher.py +++ b/server/buttonDispatcher.py @@ -8,38 +8,26 @@ from lib import uuid @cherrypy.expose class ButtonDispatcher(Dispatcher): + @cherrypy.tools.json_out() def GET(self, id=None): # GET /button - return all buttons if id is None: - return self.response(loadAll()) + return loadAll() # GET /button/{id} - return single button self.validate_uuid(id) button = Button() - return self.response(button.loadById(id).toJSON()) + return button.loadById(id).toDict() - def POST(self, id, status): - # POST /button/{id}?status={} - updates button status - self.validate_uuid(id) - - button = Button() - button.loadById(id) - - cherrypy.log("Updating status to " + str(status)) - # TODO validate status - button.status = int(status) - button.save() - - return self.response(button.toJSON()) - - def PUT(self, id=None): + @cherrypy.tools.json_out() + def POST(self, id=None): button = Button() # PUT /button - creates button if id is None: button.id = uuid.gen() - return self.response(button.save().toJSON()) + return button.save().toDict() # PUT /button/{id} - presses button else: @@ -48,12 +36,28 @@ class ButtonDispatcher(Dispatcher): button.save() - return self.response(button.toJSON()) + return button.toDict() + + @cherrypy.tools.json_out() + def PUT(self, id, status): + # POST /button/{id}?status={} - updates button status + self.validate_uuid(id) + + button = Button() + button.loadById(id) + + cherrypy.log("Updating status to " + str(status)) + # TODO validate status + button.status = int(status) + button.save() + + return button.toDict() + @cherrypy.tools.json_out() def DELETE(self, id): # DELETE /button/{id} - deletes button button = Button() button.loadById(id) button.delete() - return self.response(True) + return True -- cgit v1.2.3