Source code for luna_faces.app.handlers.linker_handler

from sanic.response import HTTPResponse

from app.handlers.base_handler import BaseRequestHandler
from app.handlers.schemas import UPDATE_LIST_SCHEMA
from crutches_on_wheels.errors.errors import Error
from crutches_on_wheels.web.query_getters import uuidGetter


[docs]class LinkerHandler(BaseRequestHandler): """ Handler for work with list """
[docs] async def patch(self) -> HTTPResponse: """ Link or unlink face to/from list See `linker`_. .. _`linker`: _static/api.html#operation/linker """ data = self.request.json self.validateJson(data, UPDATE_LIST_SCHEMA, False) listId = data["list_id"] faceIds = set(data["face_ids"]) accountId = self.getQueryParam("account_id", uuidGetter) if not await self.facesContext.isListsExist({listId}, accountId): return self.error(400, error=Error.ListNotFound.format(listId)) nonExistFaceId = await self.facesContext.getNonexistentFaceId(faceIds, accountId) if nonExistFaceId is not None: return self.error(400, error=Error.FacesNotFound.format(nonExistFaceId)) if data["action"] == "attach": await self.facesContext.linkFacesToList(data["list_id"], faceIds) else: await self.facesContext.unlinkFacesFromList(data["list_id"], faceIds) return self.success(204)