Files
aerbim-ht-monitor/backend/api/account/views/objects_views.py
2025-10-06 15:19:10 +03:00

37 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
from api.account.serializers.objects_serializers import ObjectSerializer
from sitemanagement.models import Object
from api.utils.decorators import handle_exceptions
class ObjectView(APIView):
permission_classes = [IsAuthenticated]
serializer_class = ObjectSerializer
@extend_schema(
summary="Получение всех объектов",
description="Получение всех объектов",
responses={200: OpenApiResponse(response=ObjectSerializer, description="Объекты успешно получены")})
@handle_exceptions
def get(self, request):
"""Получение всех объектов с их зонами и датчиками"""
try:
objects = Object.objects.prefetch_related(
'zones',
'zones__sensors',
'zones__sensors__sensor_type'
).all()
serializer = ObjectSerializer(objects, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
except Object.DoesNotExist:
return Response(
{"error": "Объекты не найдены"},
status=status.HTTP_404_NOT_FOUND)