def post(self, request, image_id, format=None): user = request.user try: found_image = models.Image.objects.get(id=image_id) except models.Image.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) serializer = serializers.CommentSerializer(data=request.data) if serializer.is_valid(): serializer.save(creator=user, image=found_image) # 알림생성 notifications_views.create_notifications(user, found_image.creator, 'comment', found_image, request.data['message']) return Response(data=serializer.data, status=status.HTTP_201_CREATED) else: return Response(data=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, image_id, format=None): user = request.user try: found_image = models.Image.objects.get(id=image_id) except models.Image.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) try: pre_exisiting_like = models.Like.objects.get(creator=user, image=found_image) return Response(status=status.HTTP_304_NOT_MODIFIED) except models.Like.DoesNotExist: new_like = models.Like.objects.create(creator=request.user, image=found_image) new_like.save() notifications_views.create_notifications(user, found_image.creator, 'like', found_image) return Response(status=status.HTTP_201_CREATED)
def post(self, request, user_id, format=None): user = request.user try: user_to_follow = models.User.objects.get(id=user_id) except models.User.DoesNotExitst: return Response(status=status.HTTP_404_NOT_FOUND) user.following.add(user_to_follow) user.save() # 알림 notifications_views.create_notifications(user, user_to_follow, 'follow') return Response(status=status.HTTP_200_OK)