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.
74 lines
2.3 KiB
74 lines
2.3 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_yasg.utils import swagger_auto_schema
|
|
from drf_yasg import openapi
|
|
|
|
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]
|
|
|
|
@swagger_auto_schema(
|
|
operation_description="Check API server health status",
|
|
responses={
|
|
200: openapi.Response(
|
|
description="Server is healthy",
|
|
examples={
|
|
"application/json": {
|
|
"status": "healthy",
|
|
"timestamp": "2026-09-13T12:00:00Z",
|
|
"version": "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]
|
|
|
|
@swagger_auto_schema(
|
|
operation_description="Get the latest active mobile application version",
|
|
responses={
|
|
200: AppVersionSerializer(),
|
|
404: openapi.Response("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
|