def get_one_garden(self, id): DB = GardensDB() garden = DB.get_one_garden(id) if garden != None: self.response(200, True) self.wfile.write(bytes(json.dumps(garden), "utf-8")) else: self.response(404)
def delete_garden(self, id): DB = GardensDB() if 'uid' not in self.session_data: self.no_auth(401) return garden = DB.get_one_garden(id) if garden != None: # If they are not the owner of this garden if self.session_data['uid'] != garden['author_id']: self.no_auth(403) return DB.delete_garden(id) self.response(204) else: self.response(404)
def update_garden(self, id): DB = GardensDB() if 'uid' not in self.session_data: self.no_auth(401) return garden = DB.get_one_garden(id) if garden != None: # If they are not the owner of this garden if self.session_data['uid'] != garden['author_id']: self.no_auth(403) return body = self.decode() name = body['name'] DB.update_garden(id, name) self.response(204) else: self.response(404)