feat / AEB-26 login page
This commit is contained in:
62
backend/api/account/views/UserDataView.py
Normal file
62
backend/api/account/views/UserDataView.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from rest_framework import status
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from drf_spectacular.utils import extend_schema, OpenApiResponse, OpenApiExample
|
||||
|
||||
from api.auth.serializers import UserResponseSerializer
|
||||
from api.models import UserProfile
|
||||
|
||||
from api.utils.decorators import handle_exceptions
|
||||
|
||||
|
||||
@extend_schema(tags=['Профиль'])
|
||||
class UserDataView(APIView):
|
||||
"""View для получения данных текущего пользователя"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = UserResponseSerializer
|
||||
|
||||
@extend_schema(
|
||||
summary="Получение данных пользователя",
|
||||
description="Получение данных авторизованного пользователя для инициализации клиентского состояния",
|
||||
responses={
|
||||
200: OpenApiResponse(
|
||||
response=UserResponseSerializer,
|
||||
description="Данные пользователя успешно получены",
|
||||
examples=[
|
||||
OpenApiExample(
|
||||
'Успешный ответ',
|
||||
value={
|
||||
"id": 1,
|
||||
"email": "user@example.com",
|
||||
"account_type": "engieneer",
|
||||
"name": "Иван",
|
||||
"surname": "Иванов",
|
||||
"imageURL": "https://example.com/avatar.jpg",
|
||||
"uuid": "abc123"
|
||||
}
|
||||
)
|
||||
]
|
||||
),
|
||||
404: OpenApiResponse(
|
||||
description="Профиль пользователя не найден",
|
||||
examples=[
|
||||
OpenApiExample(
|
||||
'Профиль не найден',
|
||||
value={"error": "Профиль пользователя не найден"}
|
||||
)
|
||||
]
|
||||
)
|
||||
}
|
||||
)
|
||||
@handle_exceptions
|
||||
def get(self, request):
|
||||
"""Получение данных текущего пользователя"""
|
||||
try:
|
||||
user_data = UserResponseSerializer(request.user).data
|
||||
return Response(user_data, status=status.HTTP_200_OK)
|
||||
except UserProfile.DoesNotExist:
|
||||
return Response(
|
||||
{"error": "Профиль пользователя не найден"},
|
||||
status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
3
backend/api/account/views/__init__.py
Normal file
3
backend/api/account/views/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Логика работы с аккаунтом пользователя
|
||||
"""
|
||||
Reference in New Issue
Block a user