Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 1m36s
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""
|
||
系统模块视图 - App端
|
||
"""
|
||
from rest_framework import viewsets
|
||
from rest_framework.decorators import action
|
||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||
from drf_spectacular.utils import extend_schema
|
||
|
||
from utils.response import success, error
|
||
from apps.admins.authentication import AppJWTAuthentication
|
||
from .models import Feedback, AppVersion
|
||
from .serializers import FeedbackSerializer, AppVersionSerializer
|
||
|
||
|
||
@extend_schema(tags=['系统'])
|
||
class FeedbackViewSet(viewsets.ViewSet):
|
||
"""意见反馈视图集(App端)"""
|
||
|
||
authentication_classes = [AppJWTAuthentication]
|
||
permission_classes = [IsAuthenticated]
|
||
|
||
def create(self, request):
|
||
"""
|
||
提交反馈
|
||
POST /api/v1/feedback/
|
||
"""
|
||
serializer = FeedbackSerializer(data=request.data)
|
||
if not serializer.is_valid():
|
||
return error(message=str(serializer.errors))
|
||
|
||
serializer.save(user=request.user)
|
||
return success(data=serializer.data, message='反馈已提交,感谢您的意见')
|
||
|
||
|
||
@extend_schema(tags=['系统'])
|
||
class VersionViewSet(viewsets.ViewSet):
|
||
"""版本检查视图集(App端)"""
|
||
|
||
permission_classes = [AllowAny]
|
||
|
||
@action(detail=False, methods=['get'])
|
||
def check(self, request):
|
||
"""
|
||
检查版本更新
|
||
GET /api/v1/version/check/?platform=ios¤t_version=1.0.0
|
||
"""
|
||
platform = request.query_params.get('platform', 'ios')
|
||
current_version = request.query_params.get('current_version', '')
|
||
|
||
latest = AppVersion.objects.filter(
|
||
platform=platform
|
||
).order_by('-created_at').first()
|
||
|
||
if not latest:
|
||
return success(data={'has_update': False})
|
||
|
||
has_update = latest.version != current_version
|
||
|
||
return success(data={
|
||
'has_update': has_update,
|
||
'latest_version': AppVersionSerializer(latest).data if has_update else None,
|
||
})
|