You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.4 KiB
75 lines
2.4 KiB
from rest_framework import status
|
|
from rest_framework.views import APIView
|
|
from rest_framework.generics import CreateAPIView, GenericAPIView
|
|
from rest_framework.response import Response
|
|
from rest_framework.permissions import AllowAny
|
|
from django.utils import timezone
|
|
|
|
from drf_spectacular.utils import extend_schema, OpenApiResponse, inline_serializer
|
|
from rest_framework import serializers
|
|
|
|
from apps.api.models import AppVersion, SupportMessage
|
|
from apps.api.serializers import AppVersionSerializer, SupportMessageCreateSerializer
|
|
|
|
|
|
class HealthCheckView(APIView):
|
|
"""
|
|
Health check endpoint returning system status and current timestamp
|
|
"""
|
|
permission_classes = [AllowAny]
|
|
|
|
@extend_schema(
|
|
summary="Check API server health status",
|
|
description="Returns system status, current timestamp, and API version",
|
|
responses={
|
|
200: inline_serializer(
|
|
name="HealthCheckResponse",
|
|
fields={
|
|
"status": serializers.CharField(default="healthy"),
|
|
"timestamp": serializers.DateTimeField(),
|
|
"version": serializers.CharField(default="1.0.0"),
|
|
}
|
|
)
|
|
}
|
|
)
|
|
def get(self, request):
|
|
return Response({
|
|
"status": "healthy",
|
|
"timestamp": timezone.now().isoformat(),
|
|
"version": "1.0.0",
|
|
}, status=status.HTTP_200_OK)
|
|
|
|
|
|
class AppVersionView(APIView):
|
|
"""
|
|
Returns latest active application version
|
|
"""
|
|
permission_classes = [AllowAny]
|
|
|
|
@extend_schema(
|
|
summary="Get active application version",
|
|
description="Returns latest active mobile/web application version details",
|
|
responses={
|
|
200: AppVersionSerializer,
|
|
404: OpenApiResponse(description="No active version found")
|
|
}
|
|
)
|
|
def get(self, request):
|
|
version = AppVersion.get_latest_active()
|
|
if not version:
|
|
return Response({"detail": "No active version found."}, status=status.HTTP_404_NOT_FOUND)
|
|
serializer = AppVersionSerializer(version, context={'request': request})
|
|
return Response(serializer.data)
|
|
|
|
|
|
class SupportMessageCreateView(CreateAPIView):
|
|
"""
|
|
Submit a user contact or support inquiry
|
|
"""
|
|
permission_classes = [AllowAny]
|
|
serializer_class = SupportMessageCreateSerializer
|
|
queryset = SupportMessage.objects.all()
|
|
|
|
|
|
# HomeView alias for backward compatibility
|
|
HomeView = HealthCheckView
|