Source code for luna_configurator.app.handlers.group_handler
# -*- coding: utf-8 -*-
"""Group handler
Module realize group handler.
"""
from sanic.response import HTTPResponse
from app.handlers.base_handler import BaseRequestHandler
from app.handlers.schemas import UPDATE_GROUP_SCHEMA
from crutches_on_wheels.errors.errors import Error
from crutches_on_wheels.errors.exception import VLException
[docs]class GroupHandler(BaseRequestHandler):
"""
Handler for group.
"""
[docs] async def get(self, groupName: str) -> HTTPResponse:
"""
Get group by name. See `spec getGroup`_.
.. _`spec getGroup`:
_static/api.html#operation/getGroup
"""
groupList = await self.dbContext.getGroups(groupList=[groupName])
if not groupList:
raise VLException(Error.GroupNotFound.format(groupName), 404, False)
return self.success(200, outputJson=groupList[0])
[docs] async def patch(self, groupName: str) -> HTTPResponse:
"""
Patch group. See `spec patchGroup`_.
.. _`spec patchGroup`:
_static/api.html#operation/patchGroup
"""
data = self.request.json
self.validateJson(data, UPDATE_GROUP_SCHEMA, useJsonSchema=False)
await self.dbContext.updateGroup(groupName, data["description"])
return self.success(204)
[docs] async def delete(self, groupName: str) -> HTTPResponse:
"""
Delete group. See `spec deleteGroup`_.
.. _`spec deleteGroup`:
_static/api.html#operation/deleteGroup
"""
await self.dbContext.removeGroups(groupName)
return self.success(204)