-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
access 토큰 없이 특정 리폼러의 data를 가져오는 api 추가
- Loading branch information
1 parent
862974c
commit aa2475c
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
users/views/reformer_view/reformer_specific_profile_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |