Esempio n. 1
0
    async def get(self):

        group_id = self.request.match_info.get('id')

        if group_id:
            data = serialize(Host.get(Host.id == group_id))
        else:
            data = serialize(Host.select())

        return json_response({'data': data})
Esempio n. 2
0
    async def patch(self):

        data = await self.request.post()
        group_name = data.get('name')
        group_id = self.request.match_info.get('group_id')
        group = Host.get(Host.id == group_id)

        if group and group_name == group.name:
            raise HTTPBadRequest()

        if Host.filter(Host.name == group_name).exists():
            raise HTTPBadRequest()

        group.name = group_name
        
        if group.save():
            return HTTPOk()
        
        return HTTPInternalServerError()