diff --git a/users/urls.py b/users/urls.py index 9cf77599..c8e86235 100644 --- a/users/urls.py +++ b/users/urls.py @@ -46,6 +46,7 @@ ReformerFreelancerView, ) from users.views.reformer_view.reformer_profile_view import ReformerProfileView +from users.views.reformer_view.reformer_specific_profile_view import ReformerSpecificProfileView from users.views.token_view.token_view import UserTokenRefreshView, UserTokenVerifyView from users.views.user_view.user_auth_view import * from users.views.user_view.user_crud_view import * @@ -60,6 +61,7 @@ path("/token/verify", UserTokenVerifyView.as_view(), name="token_verify"), path("/token/refresh", UserTokenRefreshView.as_view(), name="token_refresh"), path("/reformer", ReformerProfileView.as_view(), name="reformer"), + path("/reformer/", ReformerSpecificProfileView.as_view(), name="specific_reformer"), path( "/reformer/education", ReformerEducationCreateListView.as_view(), diff --git a/users/views/reformer_view/reformer_specific_profile_view.py b/users/views/reformer_view/reformer_specific_profile_view.py new file mode 100644 index 00000000..5eab6e4c --- /dev/null +++ b/users/views/reformer_view/reformer_specific_profile_view.py @@ -0,0 +1,42 @@ +from rest_framework import serializers, status +from rest_framework.response import Response +from rest_framework.views import APIView +from rest_framework.permissions import AllowAny + +from users.models.user import User +from users.models.reformer import Reformer +from users.serializers.reformer_serializer.reformer_profile_serializer import ( + ReformerProfileSerializer, +) +from users.services import UserService + +class ReformerSpecificProfileView(APIView): + permission_classes = [AllowAny,] + + def get(self, request, email:str) -> Response: + try: + user = User.objects.get(email=email) + reformer_profile = Reformer.objects.get(user=user) + if not reformer_profile: + raise Reformer.DoesNotExist( + "해당 사용자는 리포머 프로필이 등록되어 있지 않습니다." + ) + serializer = ReformerProfileSerializer( + instance=reformer_profile, context={"request": request} + ) + return Response(serializer.data, status=status.HTTP_200_OK) + except User.DoesNotExist as e: + return Response( + data={"message": str(e)}, + status=status.HTTP_404_NOT_FOUND, + ) + except Reformer.DoesNotExist as e: + return Response( + data={"message": str(e)}, + status=status.HTTP_404_NOT_FOUND, + ) + except Exception as e: + return Response( + data={"message": f"{str(e)}"}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR, + )