add message
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 1m3s
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 1m3s
This commit is contained in:
parent
f1bead86f6
commit
ee7f3ffea3
@ -1,10 +1,13 @@
|
|||||||
"""
|
"""
|
||||||
系统模块URL配置
|
系统模块URL配置
|
||||||
|
- App端接口:/api/v1/feedback/*, /api/v1/version/*
|
||||||
|
- 管理端接口:/api/admin/feedbacks/*
|
||||||
"""
|
"""
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
from .views import FeedbackViewSet, VersionViewSet
|
from .views import FeedbackViewSet, VersionViewSet, AdminFeedbackViewSet
|
||||||
|
|
||||||
|
# App端路由
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
router.register('feedback', FeedbackViewSet, basename='feedback')
|
router.register('feedback', FeedbackViewSet, basename='feedback')
|
||||||
router.register('version', VersionViewSet, basename='version')
|
router.register('version', VersionViewSet, basename='version')
|
||||||
@ -12,3 +15,11 @@ router.register('version', VersionViewSet, basename='version')
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# 管理端路由
|
||||||
|
admin_router = DefaultRouter()
|
||||||
|
admin_router.register('feedbacks', AdminFeedbackViewSet, basename='admin-feedbacks')
|
||||||
|
|
||||||
|
admin_urlpatterns = [
|
||||||
|
path('', include(admin_router.urls)),
|
||||||
|
]
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
系统模块视图 - App端
|
系统模块视图
|
||||||
"""
|
"""
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
@ -7,7 +7,8 @@ from rest_framework.permissions import IsAuthenticated, AllowAny
|
|||||||
from drf_spectacular.utils import extend_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
|
|
||||||
from utils.response import success, error
|
from utils.response import success, error
|
||||||
from apps.admins.authentication import AppJWTAuthentication
|
from apps.admins.authentication import AppJWTAuthentication, AdminJWTAuthentication
|
||||||
|
from apps.admins.permissions import IsAdminUser
|
||||||
from .models import Feedback, AppVersion
|
from .models import Feedback, AppVersion
|
||||||
from .serializers import FeedbackSerializer, AppVersionSerializer
|
from .serializers import FeedbackSerializer, AppVersionSerializer
|
||||||
|
|
||||||
@ -60,3 +61,65 @@ class VersionViewSet(viewsets.ViewSet):
|
|||||||
'has_update': has_update,
|
'has_update': has_update,
|
||||||
'latest_version': AppVersionSerializer(latest).data if has_update else None,
|
'latest_version': AppVersionSerializer(latest).data if has_update else None,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@extend_schema(tags=['管理员-意见反馈'])
|
||||||
|
class AdminFeedbackViewSet(viewsets.ViewSet):
|
||||||
|
"""意见反馈管理视图集(管理端)"""
|
||||||
|
|
||||||
|
authentication_classes = [AdminJWTAuthentication]
|
||||||
|
permission_classes = [IsAdminUser]
|
||||||
|
|
||||||
|
def list(self, request):
|
||||||
|
"""
|
||||||
|
反馈列表
|
||||||
|
GET /api/admin/feedbacks/
|
||||||
|
"""
|
||||||
|
queryset = Feedback.objects.select_related('user').all()
|
||||||
|
|
||||||
|
# 搜索条件
|
||||||
|
phone = request.query_params.get('phone')
|
||||||
|
if phone:
|
||||||
|
queryset = queryset.filter(user__phone__contains=phone)
|
||||||
|
|
||||||
|
# 分页
|
||||||
|
page = int(request.query_params.get('page', 1))
|
||||||
|
page_size = int(request.query_params.get('page_size', 10))
|
||||||
|
start = (page - 1) * page_size
|
||||||
|
end = start + page_size
|
||||||
|
|
||||||
|
total = queryset.count()
|
||||||
|
feedbacks = queryset[start:end]
|
||||||
|
|
||||||
|
items = [
|
||||||
|
{
|
||||||
|
'id': fb.id,
|
||||||
|
'user_phone': fb.user.phone,
|
||||||
|
'user_nickname': fb.user.nickname,
|
||||||
|
'content': fb.content,
|
||||||
|
'contact': fb.contact,
|
||||||
|
'created_at': fb.created_at,
|
||||||
|
}
|
||||||
|
for fb in feedbacks
|
||||||
|
]
|
||||||
|
|
||||||
|
return success(data={'total': total, 'items': items})
|
||||||
|
|
||||||
|
def retrieve(self, request, pk=None):
|
||||||
|
"""
|
||||||
|
反馈详情
|
||||||
|
GET /api/admin/feedbacks/{id}/
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
fb = Feedback.objects.select_related('user').get(pk=pk)
|
||||||
|
except Feedback.DoesNotExist:
|
||||||
|
return error(message='反馈不存在')
|
||||||
|
|
||||||
|
return success(data={
|
||||||
|
'id': fb.id,
|
||||||
|
'user_phone': fb.user.phone,
|
||||||
|
'user_nickname': fb.user.nickname,
|
||||||
|
'content': fb.content,
|
||||||
|
'contact': fb.contact,
|
||||||
|
'created_at': fb.created_at,
|
||||||
|
})
|
||||||
|
|||||||
@ -23,6 +23,7 @@ app_api_patterns = [
|
|||||||
# ============ Web管理端路由 (管理员,用户名密码登录) ============
|
# ============ Web管理端路由 (管理员,用户名密码登录) ============
|
||||||
from apps.inventory.urls import admin_urlpatterns as inventory_admin_urls
|
from apps.inventory.urls import admin_urlpatterns as inventory_admin_urls
|
||||||
from apps.users.urls import admin_urlpatterns as users_admin_urls
|
from apps.users.urls import admin_urlpatterns as users_admin_urls
|
||||||
|
from apps.system.urls import admin_urlpatterns as system_admin_urls
|
||||||
|
|
||||||
admin_api_patterns = [
|
admin_api_patterns = [
|
||||||
# 管理员认证和个人信息
|
# 管理员认证和个人信息
|
||||||
@ -31,6 +32,8 @@ admin_api_patterns = [
|
|||||||
path('', include(inventory_admin_urls)),
|
path('', include(inventory_admin_urls)),
|
||||||
# App用户管理
|
# App用户管理
|
||||||
path('', include(users_admin_urls)),
|
path('', include(users_admin_urls)),
|
||||||
|
# 意见反馈管理
|
||||||
|
path('', include(system_admin_urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user