def post(self, request, target_post_id): target_post = Post.objects.filter(id=target_post_id) if not target_post.exists(): message = 'post not found' return responses.not_found_json_response(message) target_post = target_post.first() # user allowed to bookmark herself posts! ''' if target_post.channel.owner == self.request.user: message = 'You can not bookmark your post!' return responses.bad_request_json_response(message) ''' if Bookmark.objects.filter(user=request.user, post=target_post).count() == 0: bookmark = Bookmark.objects.create( user=request.user, post=target_post, ) bookmark.save() message = 'post bookmarked successfully' return responses.successful_json_resonse(message, status=201) else: message = 'post was previously bookmarked' return responses.successful_json_resonse(message, status=201)
def post(self, request, target_user_id): if target_user_id == request.user.id: message = 'You can not follow yourself!' return responses.bad_request_json_response(message) target_user = User.objects.filter(id=target_user_id) if not target_user.exists(): message = 'user not found' return responses.not_found_json_response(message) target_user = target_user.first() user_self_channel = Channel.objects.filter(owner=target_user, is_user_self_channel=True) if not user_self_channel.exists(): user_self_channel = Channel.objects.create( owner=target_user, is_user_self_channel=True) user_self_channel.save() else: user_self_channel = user_self_channel.first() if Follow.objects.filter(user=request.user, channel=user_self_channel).count() == 0: follow = Follow.objects.create(user=request.user, channel=user_self_channel) follow.save() message = 'user followed successfully' return responses.successful_json_resonse(message, status=201) else: message = 'user was previously followed.' return responses.successful_json_resonse(message, status=201)
def delete(self, request, target_post_id): target_post = Post.objects.filter(id=target_post_id) if not target_post.exists(): message = 'post not found' return responses.not_found_json_response(message) target_post = target_post.first() bookmark = Bookmark.objects.filter(user=request.user, post=target_post) if bookmark.exists(): bookmark.delete() message = 'undo post bookmark successfully' return responses.successful_json_resonse(message, status=201) else: message = 'post was not previously bookmarked' return responses.successful_json_resonse(message, status=201)
def delete(self, request, target_channel_id): channel = Channel.objects.filter(is_user_self_channel=False).filter( id=target_channel_id) if not channel.exists(): message = 'Channel not found' return responses.not_found_json_response(message) channel = channel.first() follow = channel.follow_set.filter(user_id=request.user.id) if follow.count() != 0: follow.delete() message = 'channel unfollowed successfully' return responses.successful_json_resonse(message, status=200) else: message = 'channel not previously followed.' return responses.successful_json_resonse(message, status=200)
def post(self, request, target_channel_id): channel = Channel.objects.filter(is_user_self_channel=False).filter( id=target_channel_id) if not channel.exists(): message = 'Channel not found' return responses.not_found_json_response(message) channel = channel.first() if channel.owner == request.user: message = 'you can not follow your channel' return responses.bad_request_json_response(message) if Follow.objects.filter(user=request.user, channel=channel).count() == 0: follow = Follow.objects.create(user=request.user, channel=channel) follow.save() message = 'channel followed successfully' return responses.successful_json_resonse(message, status=201) else: message = 'channel was previously followed.' return responses.successful_json_resonse(message, status=201)
def post(self, request, target_post_id): target_post = Post.objects.filter(id=target_post_id) if not target_post.exists(): message = 'post not found' return responses.not_found_json_response(message) target_post = target_post.first() if target_post.channel.owner == self.request.user: message = 'You can not seen your post!' return responses.bad_request_json_response(message) if Seen.objects.filter(user=request.user, post=target_post).count() == 0: seen = Seen.objects.create( user=request.user, post=target_post, ) seen.save() message = 'post seen successfully' return responses.successful_json_resonse(message, status=201) else: message = 'post was previously seen.' return responses.successful_json_resonse(message, status=201)