diff --git a/users/urls.py b/users/urls.py index bad61f2..59b7fc2 100644 --- a/users/urls.py +++ b/users/urls.py @@ -23,4 +23,5 @@ urlpatterns = [ path('mypage/works//', MyPageWorkListAPIView.as_view()), path('mypage/my-info/', MyPageMemberInfoAPIView.as_view()), path("github/", include(router.urls)), + path("portfolio/", UserInfoAPIView.as_view()), ] \ No newline at end of file diff --git a/users/views.py b/users/views.py index b3b3684..bacb7ec 100644 --- a/users/views.py +++ b/users/views.py @@ -373,6 +373,12 @@ class SetPortofolioRequiredInfoAPIView(APIView): custom_url = request.GET.get('custom_url', None) if not custom_url: return Response({"message": "no url"}, status=status.HTTP_400_BAD_REQUEST) + + normalized = custom_url.strip().lower() + + if "www" in normalized or "vvvvvv" in normalized: + return Response({"message": "custom_url cannot contain 'www'"}, status=status.HTTP_400_BAD_REQUEST) + if User.objects.filter(custom_url=custom_url).exists(): return Response({"message": "already used url"}, status=status.HTTP_400_BAD_REQUEST) else: @@ -494,3 +500,21 @@ class MyPageMemberInfoAPIView(APIView): return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) +class UserInfoAPIView(APIView): + permission_classes = [AllowAny] + + # 유저 대표 포트폴리오 id 제공 + def get(self, request): + sub_domain = request.query_params.get('sub_domain', '') + + if not sub_domain: + return Response({"message": "no sub domain"}, status=status.HTTP_400_BAD_REQUEST) + + target_user = get_object_or_404(User, custom_url=sub_domain) + represent_portfolio = target_user.owned_portfolios.filter(is_represent=True, is_published=True).first() + + if not represent_portfolio: + return Response({"message": "no represent published portfolio"}, status=status.HTTP_404_NOT_FOUND) + + return Response({"portfolio_id": represent_portfolio.id}, status=status.HTTP_200_OK) +