Source code for luna_admin.app.handlers.accounts_handler

"""
Module realize a handler for work with several accounts
"""
from sanic.response import HTTPResponse

from app.handlers.base_handler import BaseHandler
from app.handlers.schemas import NEW_ACCOUNT_SCHEMA


[docs]class AccountsHandler(BaseHandler): """ Handler for work with several accounts """
[docs] async def get(self) -> HTTPResponse: """ Get accounts with pagination. See `spec_get_accounts`_. .. _spec_get_accounts: _static/api.html#operation/getAccounts Returns: response with account list and account count """ page, pageSize = self.getPagination() accounts = await self.dbAdminContext.getAccounts(page, pageSize) accountCount = await self.dbAdminContext.getAccountCount() return self.success(200, outputJson={"accounts": accounts, "account_count": accountCount})
[docs] async def post(self) -> HTTPResponse: """ Register a new account in luna-admin. See `spec_create_account`_. .. _spec_create_account: _static/api.html#operation/registerAccount Returns: response with account id """ data = self.request.json self.validateJson(data, NEW_ACCOUNT_SCHEMA, False) accountId = await self.dbAdminContext.createAccount(data["email"], data["organization_name"]) return self.success( 201, outputJson={"account_id": accountId}, extraHeaders={"Location": f"/{self.request.app.ctx.apiVersion}/accounts/{accountId}"}, )