def register_garbage_can(): """route: /garbage/register POST: Register a company garbage bin params: id: company_id, req_id, latitude, longitude, volume """ company_id = str(request.data.get('company_id', '')) req_id = str(request.data.get('req_id', '')) volume = str(request.data.get('volume', '')) latitude = (request.data.get('latitude', '')) longitude = str(request.data.get('longitude', '')) if len(company_id) > 0 and Company.check_if_exists(company_id): can = GarbageCanRequest.objects(req_id=req_id).first() if can: can.delete() Company.add_garbage_can(company_id, req_id, volume, latitude, longitude) return common.to_json({}, "Can successfully added", 200) else: return common.to_json({}, "No such can addition request", 400) else: return common.to_json({}, "No such company", 400)
async def render_put(self, request): print('PUT payload: %s' % request.payload) company_id = str(request.data.get('company_id', '')) req_id = str(request.data.get('req_id', '')) volume = str(request.data.get('volume', '')) latitude = (request.data.get('latitude', '')) longitude = str(request.data.get('longitude', '')) if len(company_id) > 0 and Company.check_if_exists(company_id): can = GarbageCanRequest.objects(req_id=req_id).first() if can: can.delete() Company.add_garbage_can(company_id, req_id, volume, latitude, longitude) self.set_content(request.payload) return aiocoap.Message(code=aiocoap.CHANGED, payload=self.content)