+ new_books = []
+ for book in books:
+ new_books.append(BookProxy(book).set('liked', book.id in likes))
+ return QuerySetProxy(new_books)
+
+
+class UserLikeHandler(BaseHandler):
+ fields = []
+ allowed_methods = ('GET', 'POST')
+
+ def read(self, request, slug):
+ if not request.user.is_authenticated():
+ return rc.FORBIDDEN
+ try:
+ book = Book.objects.get(slug=slug)
+ except Book.DoesNotExist:
+ return rc.NOT_FOUND
+ return {'likes': likes(request.user, book)}
+
+ def create(self, request, slug):
+ if not request.user.is_authenticated():
+ return rc.FORBIDDEN
+ try:
+ book = Book.objects.get(slug=slug)
+ except Book.DoesNotExist:
+ return rc.NOT_FOUND
+ action = request.GET.get('action', 'like')
+ if action == 'like':
+ book.like(request.user)
+ elif action == 'unlike':
+ book.unlike(request.user)
+ return {}