Feat: [#94] 서브도메인 대표 포트폴리오 id 반환 + www포함 url 금지

This commit is contained in:
sm4640
2025-12-24 17:45:46 +09:00
parent b15b415a93
commit 8c128b1062
2 changed files with 25 additions and 0 deletions

View File

@@ -23,4 +23,5 @@ urlpatterns = [
path('mypage/works/<str:nickname>/', MyPageWorkListAPIView.as_view()),
path('mypage/my-info/', MyPageMemberInfoAPIView.as_view()),
path("github/", include(router.urls)),
path("portfolio/", UserInfoAPIView.as_view()),
]

View File

@@ -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)