mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-23 01:20:03 +02:00
reduces complexity of create_api_application method
This commit is contained in:
parent
6d12e5c939
commit
374a930745
@ -24,12 +24,9 @@ STATUS_OK = 200
|
|||||||
STATUS_FAILED = 400
|
STATUS_FAILED = 400
|
||||||
|
|
||||||
|
|
||||||
def create_api_application(state_manager: StateManager) -> aiohttp.web.Application:
|
async def _get_value(
|
||||||
api_application = aiohttp.web.Application(
|
state_manager: StateManager, request: aiohttp.web.Request
|
||||||
middlewares=(aiohttp_middlewares.error.error_middleware(),)
|
) -> aiohttp.web.Response:
|
||||||
)
|
|
||||||
|
|
||||||
async def _get_value(request: aiohttp.web.Request) -> aiohttp.web.Response:
|
|
||||||
logger.info("Handle api request: %s", request)
|
logger.info("Handle api request: %s", request)
|
||||||
|
|
||||||
access_path = request.rel_url.query["access_path"]
|
access_path = request.rel_url.query["access_path"]
|
||||||
@ -43,7 +40,10 @@ def create_api_application(state_manager: StateManager) -> aiohttp.web.Applicati
|
|||||||
status = STATUS_FAILED
|
status = STATUS_FAILED
|
||||||
return aiohttp.web.json_response(result, status=status)
|
return aiohttp.web.json_response(result, status=status)
|
||||||
|
|
||||||
async def _update_value(request: aiohttp.web.Request) -> aiohttp.web.Response:
|
|
||||||
|
async def _update_value(
|
||||||
|
state_manager: StateManager, request: aiohttp.web.Request
|
||||||
|
) -> aiohttp.web.Response:
|
||||||
data: UpdateDict = await request.json()
|
data: UpdateDict = await request.json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -54,7 +54,10 @@ def create_api_application(state_manager: StateManager) -> aiohttp.web.Applicati
|
|||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
return aiohttp.web.json_response(dump(e), status=STATUS_FAILED)
|
return aiohttp.web.json_response(dump(e), status=STATUS_FAILED)
|
||||||
|
|
||||||
async def _trigger_method(request: aiohttp.web.Request) -> aiohttp.web.Response:
|
|
||||||
|
async def _trigger_method(
|
||||||
|
state_manager: StateManager, request: aiohttp.web.Request
|
||||||
|
) -> aiohttp.web.Response:
|
||||||
data: TriggerMethodDict = await request.json()
|
data: TriggerMethodDict = await request.json()
|
||||||
|
|
||||||
method = get_object_attr_from_path(state_manager.service, data["access_path"])
|
method = get_object_attr_from_path(state_manager.service, data["access_path"])
|
||||||
@ -73,8 +76,23 @@ def create_api_application(state_manager: StateManager) -> aiohttp.web.Applicati
|
|||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
return aiohttp.web.json_response(dump(e), status=STATUS_FAILED)
|
return aiohttp.web.json_response(dump(e), status=STATUS_FAILED)
|
||||||
|
|
||||||
api_application.router.add_get("/get_value", _get_value)
|
|
||||||
api_application.router.add_put("/update_value", _update_value)
|
def create_api_application(state_manager: StateManager) -> aiohttp.web.Application:
|
||||||
api_application.router.add_put("/trigger_method", _trigger_method)
|
api_application = aiohttp.web.Application(
|
||||||
|
middlewares=(aiohttp_middlewares.error.error_middleware(),)
|
||||||
|
)
|
||||||
|
|
||||||
|
api_application.router.add_get(
|
||||||
|
"/get_value",
|
||||||
|
lambda request: _get_value(state_manager=state_manager, request=request),
|
||||||
|
)
|
||||||
|
api_application.router.add_put(
|
||||||
|
"/update_value",
|
||||||
|
lambda request: _update_value(state_manager=state_manager, request=request),
|
||||||
|
)
|
||||||
|
api_application.router.add_put(
|
||||||
|
"/trigger_method",
|
||||||
|
lambda request: _trigger_method(state_manager=state_manager, request=request),
|
||||||
|
)
|
||||||
|
|
||||||
return api_application
|
return api_application
|
||||||
|
Loading…
x
Reference in New Issue
Block a user