craftbeerpi4-pione/core/http_endpoints/http_api.py

31 lines
1 KiB
Python
Raw Normal View History

2018-11-01 19:50:04 +01:00
import logging
from aiohttp import web
from aiojobs.aiohttp import get_scheduler_from_app
from core.api.decorator import request_mapping
2018-11-01 21:27:37 +01:00
from core.utils.utils import json_dumps
2018-11-01 19:50:04 +01:00
class HttpAPI():
2018-11-01 21:25:42 +01:00
def __init__(self,cbpi):
2018-11-01 19:50:04 +01:00
self.logger = logging.getLogger(__name__)
self.logger.info("WOOHOO MY ACTOR")
2018-11-01 21:25:42 +01:00
self.cbpi =cbpi
2018-11-01 19:50:04 +01:00
@request_mapping(path="/", auth_required=False)
async def http_get_all(self, request):
return web.json_response(await self.get_all(force_db_update=True), dumps=json_dumps)
@request_mapping(path="/{id}", auth_required=False)
async def http_get_one(self, request):
id = int(request.match_info['id'])
return web.json_response(await self.get_one(id), dumps=json_dumps)
@request_mapping(path="/{id}'", method="POST", auth_required=False)
async def http_add_one(self, request):
id = request.match_info['id']
await self.get_all(force_db_update=True)
return web.json_response(await self.get_one(id), dumps=json_dumps)