Source code for luna_configurator.app.handlers.groups_handler

# -*- coding: utf-8 -*-
"""Limitation group Handler

Module realize limitation group handler.
"""

from sanic.response import HTTPResponse

from app.handlers.base_handler import BaseRequestHandler
from app.handlers.schemas import GROUP_SCHEMA
from app.version import VERSION
from crutches_on_wheels.web.query_getters import listStringsGetter


[docs]class GroupsHandler(BaseRequestHandler): """ Handler for limitation groups. """
[docs] async def post(self) -> HTTPResponse: """ Create group, see `spec newGroup`_ .. _`spec newGroup`: _static/api.html#operation/newGroup """ data = self.request.json self.validateJson(data, GROUP_SCHEMA, useJsonSchema=False) await self.dbContext.addGroup(data["group_name"], data.get("description", "")) self.respHeaders = {"Location": "/{}/groups/{}".format(VERSION["Version"]["api"], data["group_name"])} return self.success(201, outputJson={"group_name": data["group_name"]})
[docs] async def get(self) -> HTTPResponse: """ Get groups by names or limitation names, see `spec getGroups`_ .. _`spec getGroups`: _static/api.html#operation/getGroups """ limitationList = self.getQueryParam("limitation_names", listStringsGetter, False, default=None) groupList = self.getQueryParam("group_names", listStringsGetter, False, default=None) groupRes = await self.dbContext.getGroups(limitationList=limitationList, groupList=groupList) return self.success(200, outputJson={"groups": groupRes})