diff --git a/portfolios/views.py b/portfolios/views.py index e715aec..3acaf70 100644 --- a/portfolios/views.py +++ b/portfolios/views.py @@ -54,12 +54,15 @@ class PortfolioSetRepresentAPIView(APIView): portfolio = get_object_or_404(Portfolio, id=pk) if user != portfolio.owner: return Response({"message": "Not owner"}, status=status.HTTP_403_FORBIDDEN) - if before_represent := Portfolio.objects.filter(owner=user, is_represent=True).first(): - before_represent.is_represent = False - before_represent.save() - portfolio.is_represent = True + + is_representing = request.data.get("representing", False) + if is_representing: + if before_represent := Portfolio.objects.filter(owner=user, is_represent=True).first(): + before_represent.is_represent = False + before_represent.save() + portfolio.is_represent = is_representing portfolio.save() - return Response({"message": "change represent success"}, status=status.HTTP_200_OK) + return Response({"is_represented": is_representing}, status=status.HTTP_200_OK) class PortfolioSetPublishAPIView(APIView): @@ -69,9 +72,10 @@ class PortfolioSetPublishAPIView(APIView): portfolio = get_object_or_404(Portfolio, id=pk) if user != portfolio.owner: return Response({"message": "Not owner"}, status=status.HTTP_403_FORBIDDEN) - portfolio.is_published = True + is_publishing = request.data.get("publishing", False) + portfolio.is_published = is_publishing portfolio.save() - return Response({"message": "publish success"}, status=status.HTTP_200_OK) + return Response({"is_published": is_publishing}, status=status.HTTP_200_OK) class PortfolioChangeState(APIView): @transaction.atomic diff --git a/projects/views.py b/projects/views.py index b04368c..44d76f5 100644 --- a/projects/views.py +++ b/projects/views.py @@ -89,12 +89,15 @@ class ProjectSetRepresentAPIView(APIView): project = get_object_or_404(Project, id=pk) if user != project.owner: return Response({"message": "Not owner"}, status=status.HTTP_403_FORBIDDEN) - if before_represent := Project.objects.filter(owner=user, is_represent=True).first(): - before_represent.is_represent = False - before_represent.save() - project.is_represent = True + + is_representing = request.data.get("representing", False) + if is_representing: + if before_represent := Project.objects.filter(owner=user, is_represent=True).first(): + before_represent.is_represent = False + before_represent.save() + project.is_represent = is_representing project.save() - return Response({"message": "change represent success"}, status=status.HTTP_200_OK) + return Response({"is_represented": is_representing}, status=status.HTTP_200_OK) class ProjectSetPublishAPIView(APIView): @@ -104,9 +107,10 @@ class ProjectSetPublishAPIView(APIView): project = get_object_or_404(Project, id=pk) if user != project.owner: return Response({"message": "Not owner"}, status=status.HTTP_403_FORBIDDEN) - project.is_published = True + is_publishing = request.data.get("publishing", False) + project.is_published = is_publishing project.save() - return Response({"message": "publish success"}, status=status.HTTP_200_OK) + return Response({"is_published": is_publishing}, status=status.HTTP_200_OK) class ProjectChangeState(APIView): @transaction.atomic