示例#1
0
class Partner(APIView):
    @method_decorator(check_user())
    def post(self, request, user, format=None):

        new_partner_name = request.data.get('name', None)

        try:
            found_partner = models.Partner.objects.get(name=new_partner_name,
                                                       creator=user)

        except models.Partner.DoesNotExist:

            serializer = serializers.CreatePartnerSerializer(data=request.data,
                                                             partial=True)

            if serializer.is_valid():

                new_partner = serializer.save(creator=user)
                #파트너가 생성된 후, 직전에 생성된 파트너를 함께 일기 쓸 파트너로 선택하기
                user.partner = new_partner

                user.save()

                print(user.partner.name)

                return Response(data=serializer.data,
                                status=status.HTTP_201_CREATED)

            else:

                return Response(data=serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)
示例#2
0
class PartnerList(APIView):
    @method_decorator(check_user())
    def get(self, request, user, format=None):

        serializer = serializers.PartnerListSerializer(user)

        return Response(data=serializer.data, status=status.HTTP_200_OK)
示例#3
0
class Main(APIView):
    """ Main """
    @method_decorator(check_user())
    def get(self, request, user, format=None):

        serializer = serializers.MainSerializer(user)

        return Response(data=serializer.data, status=status.HTTP_200_OK)
示例#4
0
class PartnerProfile(APIView):
    @method_decorator(check_user())
    def get(self, request, user, partner_id, format=None):

        found_partner = get_partner(self, partner_id, user)

        if found_partner is None:

            return Response(status=status.HTTP_404_NOT_FOUND)

        else:

            serializer = serializers.PartnerProfileSerializer(found_partner)

            return Response(data=serializer.data, status=status.HTTP_200_OK)

    @method_decorator(check_user())
    def put(self, request, user, partner_id, format=None):

        found_partner = get_partner(self, partner_id, user)

        if found_partner is None:

            return Response(status=status.HTTP_404_NOT_FOUND)

        else:

            serializer = serializers.PartnerProfileSerializer(
                found_partner, data=request.data, partial=True)

            if serializer.is_valid():

                serializer.save()

                return Response(data=serializer.data,
                                status=status.HTTP_200_OK)

            else:

                return Response(data=serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)
示例#5
0
class DeletePartner(APIView):
    @method_decorator(check_user())
    def delete(self, request, user, partner_id, format=None):

        found_partner = get_partner(self, partner_id, user)

        if found_partner is None:

            return Response(status=status.HTTP_404_NOT_FOUND)

        else:

            found_partner.delete()

            return Response(status=status.HTTP_204_NO_CONTENT)
示例#6
0
class PartnerProfile_setting(APIView):
    @method_decorator(check_user())
    def get(self, request, user, format=None):

        found_partner = user.partner

        if found_partner is None:

            return Response(status=status.HTTP_404_NOT_FOUND)

        else:

            serializer = serializers.PartnerProfileSerializer(found_partner)

            return Response(data=serializer.data, status=status.HTTP_200_OK)
示例#7
0
class SetPartner(APIView):
    @method_decorator(check_user())
    def put(self, request, user, partner_id, format=None):

        found_partner = get_partner(self, partner_id, user)

        if found_partner is None:

            return Response(status=status.HTTP_404_NOT_FOUND)

        else:

            user.partner = found_partner

            user.save()

            return Response(status=status.HTTP_200_OK)