Пример #1
0
async def put(request, post_id):
    post_repo = get_post_repo()
    try:
        data = request.json
    except InvalidUsage as e:
        return text(
            'request body "%s" cannot be parsed. Err: %s' % (request.body, e),
            status=http.HTTPStatus.BAD_REQUEST,
        )
    updated_post = await post_repo.update(post_id, data)
    return text(updated_post)
Пример #2
0
async def post(request):
    """
    :param request:
    :return:

    post_id should be included inside post body
    """
    post_repo = get_post_repo()
    try:
        post = request.json
    except InvalidUsage as e:
        return text(
            'request body "%s" cannot be parsed. Err: %s' % (request.body, e),
            status=http.HTTPStatus.BAD_REQUEST,
        )
    post = await post_repo.save(post)
    return text(post)
Пример #3
0
async def delete(request, post_id):
    post_repo = get_post_repo()
    await post_repo.delete(post_id)
    return text("ok")
Пример #4
0
async def get_one(request, post_id):
    post_repo = get_post_repo()
    post = await post_repo.get(post_id)
    return text(post)
Пример #5
0
async def get_all(request):
    post_repo = get_post_repo()
    posts = await post_repo.get_all()
    return text(posts)
Пример #6
0
 def __init__(self, db):
     self._db = db
     self.post_repo = get_post_repo()