feat: update login api
This commit is contained in:
+34
-2
@@ -1,10 +1,12 @@
|
||||
from rest_framework import viewsets, filters, status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.decorators import action, api_view, permission_classes
|
||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||
from rest_framework.response import Response
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from drf_spectacular.utils import extend_schema
|
||||
|
||||
from config.exceptions import AppError
|
||||
from .auth import TRIAL_INSTITUTION_NAME
|
||||
from .models import User, Role, TeacherStudentRelation, Institution, Department
|
||||
from .serializers import (
|
||||
UserSerializer, UserCreateSerializer, UserUpdateSerializer,
|
||||
@@ -196,3 +198,33 @@ class DepartmentViewSet(viewsets.ModelViewSet):
|
||||
filter_backends = [DjangoFilterBackend, filters.SearchFilter]
|
||||
filterset_fields = ['institution', 'category']
|
||||
search_fields = ['name']
|
||||
|
||||
|
||||
# ── 移动端机构列表(不分页,登录前可调用)─────────────────────────────────────
|
||||
|
||||
@extend_schema(
|
||||
summary='移动端机构列表(不分页)',
|
||||
description='返回当前可选的全部机构,供移动端学生登录时选择所属机构。'
|
||||
f'is_trial=true 标识预留试用机构({TRIAL_INSTITUTION_NAME})。',
|
||||
responses={200: None},
|
||||
tags=['机构'],
|
||||
)
|
||||
@api_view(['GET'])
|
||||
@permission_classes([AllowAny])
|
||||
def institution_list(request):
|
||||
"""移动端机构列表 — 全部机构、不分页"""
|
||||
institutions = Institution.objects.all().order_by('name')
|
||||
data = [
|
||||
{
|
||||
'id': inst.id,
|
||||
'code': inst.code,
|
||||
'name': inst.name,
|
||||
'type': inst.type,
|
||||
'level': inst.level,
|
||||
'province': inst.province,
|
||||
'city': inst.city,
|
||||
'is_trial': inst.name == TRIAL_INSTITUTION_NAME,
|
||||
}
|
||||
for inst in institutions
|
||||
]
|
||||
return Response(data)
|
||||
|
||||
Reference in New Issue
Block a user