+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, action='like'):
+ if not request.user.is_authenticated():
+ return rc.FORBIDDEN
+ try:
+ book = Book.objects.get(slug=slug)
+ except Book.DoesNotExist:
+ return rc.NOT_FOUND
+ if action == 'like':
+ book.like(request.user)
+ elif action == 'unlike':
+ book.unlike(request.user)
+ return {}
+
+