Beispiel #1
0
    async def get(self, request, book_id):
        # await on database consults
        book = await self.get_object(request, book_id)

        return json({'method': request.method,
                     'status': 200,
                     'results': BookSerializer.serialize(book),
                     })
Beispiel #2
0
    async def get(self, request, book_id):
        # await on database consults
        book = await self.get_object(request, book_id)

        return json({
            "method": request.method,
            "status": 200,
            "results": BookSerializer.serialize(book)
        })
Beispiel #3
0
    async def patch(self, request, book_id):
        # await on database consults
        book = await self.get_object(request, book_id)
        # await on save
        await book.save(**request.json)

        return json({
            'method': request.method,
            'status': 200,
            'results': BookSerializer.serialize(book)
        })
Beispiel #4
0
    async def post(self, request):
        # populate the book with the data in the request
        book = Book(**request.json)

        # and await on save
        await book.save()

        return json({'method': request.method,
                     'status': 201,
                     'results': BookSerializer.serialize(book),
                     })
Beispiel #5
0
    async def post(self, request):
        # populate the book with the data in the request
        book = Book(**request.json)

        # and await on save
        await book.save()

        return json({
            "method": request.method,
            "status": 201,
            "results": BookSerializer.serialize(book)
        })
Beispiel #6
0
    async def patch(self, request, book_id):
        # await on database consults
        book = await self.get_object(request, book_id)
        # await on save
        await book.save(**request.json)

        return json(
            {
                "method": request.method,
                "status": 200,
                "results": BookSerializer.serialize(book),
            }
        )
Beispiel #7
0
    async def get(self, request):
        filtered_by = self.arg_parser(request)

        if filtered_by:
            q_books = await Book.objects.filter(**filtered_by)
        else:
            q_books = await Book.objects.all()

        books = [BookSerializer.serialize(book) for book in q_books]

        return json({
            'method': request.method,
            'status': 200,
            'results': books or None,
            'count': len(books),
        })
Beispiel #8
0
    async def get(self, request):
        filtered_by = request.raw_args

        if filtered_by:
            try:
                q_books = Book.objects.filter(**filtered_by)
            except AttributeError as e:
                raise URLBuildError(e.args[0])
        else:
            q_books = Book.objects.all()

        books = []
        async for book in q_books:
            books.append(BookSerializer.serialize(book))

        return json({'method': request.method,
                     'status': 200,
                     'results': books or None,
                     'count': len(books),
                     })