Пример #1
0
 def get(self):
     """Get the reading list for the authenticated user."""
     reading_list = current_user.reading_list.all()
     res = {
         'result': serialize_book(reading_list, many=True).data,
         'user': serialize_user(current_user._get_current_object()).data
     }
     return res
Пример #2
0
    def post(self):
        """Add a book to the authenticated user's reading list.

        :param-json int book_id: ID of the book to add.
        """
        book = self._get_book_from_request()
        current_user.add_to_reading_list(book)
        current_user.save()
        return {
            'result': serialize_book(book).data,
            'user': serialize_user(current_user._get_current_object()).data,
        }, http.OK
Пример #3
0
    def put(self):
        """Toggle the ``read`` status of a book.

        :param-json int book_id: ID of the book to modify.
        """
        book = self._get_book_from_request()
        current_user.toggle_read(book)
        current_user.save()
        has_read = current_user.has_read(book)
        return {
            'result': serialize_book(book, extra={'read': has_read}).data,
            'user': serialize_user(current_user._get_current_object()).data,
        }, http.OK