def get(self, req, user_id, *args, **kwargs): eid = req.GET.get("eid", "") if not eid: raise serializers.ValidationError("缺少'eid'字段") query = req.GET.get("query", "") try: page = int(req.GET.get("page", 1)) except ValueError: page = 1 try: page_size = int(req.GET.get("page_size", 10)) except ValueError: page_size = 10 tenants, total = team_services.list_teams_by_user_id( eid=eid, user_id=user_id, query=query, page=page, page_size=page_size) result = {"tenants": tenants, "total": total} serializer = ListTeamRespSerializer(data=result) serializer.is_valid(raise_exception=True) return Response(result, status.HTTP_200_OK)
def get(self, req, *args, **kwargs): query = req.GET.get("query", "") try: page = int(req.GET.get("page", 1)) except ValueError: page = 1 try: page_size = int(req.GET.get("page_size", 10)) except ValueError: page_size = 10 tenants, total = team_services.list_teams_by_user_id( eid=self.enterprise.enterprise_id, user_id=req.user.user_id, query=query, page=page, page_size=page_size) result = { "tenants": tenants, "total": total, "page": page, "page_size": page_size } serializer = ListTeamRespSerializer(data=result) serializer.is_valid(raise_exception=True) return Response(serializer.data, status.HTTP_200_OK)
def get(self, req, *args, **kwargs): query = req.GET.get("query", "") try: page = int(req.GET.get("page", 1)) except ValueError: page = 1 try: page_size = int(req.GET.get("page_size", 10)) except ValueError: page_size = 10 tenant_names = req.GET.get("tenant_names", "") if tenant_names: data = team_services.list_by_tenant_names(tenant_names.split(",")) result = {"tenants": data, "total": len(data)} else: data, total = team_services.list_teams_v2(req.user.enterprise_id, query=query, page=page, page_size=page_size) result = { "tenants": data, "total": total, "page": page, "page_size": page_size } serializer = ListTeamRespSerializer(data=result) serializer.is_valid(raise_exception=True) return Response(result, status.HTTP_200_OK)
class ListTeamInfo(BaseOpenAPIView): @swagger_auto_schema( operation_description="获取用户所在团队列表", manual_parameters=[ openapi.Parameter("query", openapi.IN_QUERY, description="团队名称搜索", type=openapi.TYPE_STRING), openapi.Parameter("page", openapi.IN_QUERY, description="页码", type=openapi.TYPE_STRING), openapi.Parameter("page_size", openapi.IN_QUERY, description="每页数量", type=openapi.TYPE_STRING), ], responses={200: ListTeamRespSerializer()}, tags=['openapi-team'], ) def get(self, req, *args, **kwargs): query = req.GET.get("query", "") try: page = int(req.GET.get("page", 1)) except ValueError: page = 1 try: page_size = int(req.GET.get("page_size", 10)) except ValueError: page_size = 10 tenants, total = team_services.list_teams_by_user_id( eid=self.enterprise.enterprise_id, user_id=req.user.user_id, query=query, page=page, page_size=page_size) result = {"tenants": tenants, "total": total, "page": page, "page_size": page_size} serializer = ListTeamRespSerializer(data=result) serializer.is_valid(raise_exception=True) return Response(serializer.data, status.HTTP_200_OK) @swagger_auto_schema( operation_description="add team", request_body=CreateTeamReqSerializer(), responses={ status.HTTP_201_CREATED: TeamBaseInfoSerializer(), }, tags=['openapi-team'], ) def post(self, request): serializer = CreateTeamReqSerializer(data=request.data) serializer.is_valid(raise_exception=True) team_data = serializer.data team_data["creater"] = self.user.user_id team_data["enterprise_id"] = self.enterprise.enterprise_id en = self.enterprise if not en: raise serializers.ValidationError("指定企业不存在") region = None if team_data.get("region", None): region = region_services.get_region_by_region_name(team_data.get("region")) if not region: raise ErrRegionNotFound try: user = user_services.get_user_by_user_id(team_data.get("creater", 0)) except UserNotExistError: user = request.user team = team_services.create_team(user, en, team_alias=team_data["tenant_name"]) if region: region_services.create_tenant_on_region(self.enterprise.enterprise_id, team.tenant_name, region.region_name) re = TeamBaseInfoSerializer(team) return Response(re.data, status=status.HTTP_201_CREATED)
class UserTeamInfoView(ListAPIView): @swagger_auto_schema( operation_description="获取用户的团队列表", manual_parameters=[ openapi.Parameter("eid", openapi.IN_QUERY, description="企业ID", type=openapi.TYPE_STRING), openapi.Parameter("query", openapi.IN_QUERY, description="团队名称搜索", type=openapi.TYPE_STRING), openapi.Parameter("page", openapi.IN_QUERY, description="页码", type=openapi.TYPE_STRING), openapi.Parameter("page_size", openapi.IN_QUERY, description="每页数量", type=openapi.TYPE_STRING), ], responses={200: ListTeamRespSerializer()}, tags=['openapi-user'], ) def get(self, req, user_id, *args, **kwargs): eid = req.GET.get("eid", "") if not eid: raise serializers.ValidationError("缺少'eid'字段") query = req.GET.get("query", "") try: page = int(req.GET.get("page", 1)) except ValueError: page = 1 try: page_size = int(req.GET.get("page_size", 10)) except ValueError: page_size = 10 tenants, total = team_services.list_teams_by_user_id( eid=eid, user_id=user_id, query=query, page=page, page_size=page_size) result = {"tenants": tenants, "total": total} serializer = ListTeamRespSerializer(data=result) serializer.is_valid(raise_exception=True) return Response(result, status.HTTP_200_OK)
class ListTeamInfo(ListAPIView): @swagger_auto_schema( operation_description="获取团队列表", manual_parameters=[ openapi.Parameter("eid", openapi.IN_QUERY, description="企业ID", type=openapi.TYPE_STRING), openapi.Parameter("query", openapi.IN_QUERY, description="团队名称搜索", type=openapi.TYPE_STRING), openapi.Parameter("tenant_names", openapi.IN_QUERY, description="根据租户名称获取列表", type=openapi.TYPE_STRING), openapi.Parameter("page", openapi.IN_QUERY, description="页码", type=openapi.TYPE_STRING), openapi.Parameter("page_size", openapi.IN_QUERY, description="每页数量", type=openapi.TYPE_STRING), ], responses={200: ListTeamRespSerializer()}, tags=['openapi-team'], ) def get(self, req, *args, **kwargs): eid = req.GET.get("eid", "") if not eid: raise serializers.ValidationError("缺少'eid'字段") query = req.GET.get("query", "") try: page = int(req.GET.get("page", 1)) except ValueError: page = 1 try: page_size = int(req.GET.get("page_size", 10)) except ValueError: page_size = 10 tenant_names = req.GET.get("tenant_names", "") if tenant_names: data = team_services.list_by_tenant_names(tenant_names.split(",")) result = {"tenants": data, "total": len(data)} else: data, total = team_services.list_teams_v2( eid, query=query, page=page, page_size=page_size) result = {"tenants": data, "total": total} serializer = ListTeamRespSerializer(data=result) serializer.is_valid(raise_exception=True) return Response(result, status.HTTP_200_OK) @swagger_auto_schema( operation_description="add team", request_body=CreateTeamReqSerializer(), responses={ status.HTTP_201_CREATED: TeamBaseInfoSerializer(), status.HTTP_500_INTERNAL_SERVER_ERROR: None, status.HTTP_400_BAD_REQUEST: None, }, tags=['openapi-team'], ) def post(self, request): serializer = CreateTeamReqSerializer(data=request.data) serializer.is_valid(raise_exception=True) team_data = serializer.data en = enterprise_services.get_enterprise_by_enterprise_id(request.data.get("enterprise_id")) if not en: raise serializers.ValidationError("指定企业不存在") region = None if team_data.get("region", None): region = region_services.get_region_by_region_name(team_data.get("region")) if not region: raise serializers.ValidationError("指定数据中心不存在") try: user = user_services.get_user_by_user_id(team_data.get("creater", 0)) except UserNotExistError: user = request.user code, msg, team = team_services.create_team(user, en, team_alias=team_data["tenant_name"]) if code == 200 and region: code, message, bean = region_services.create_tenant_on_region(team.tenant_name, region.region_name) if code != 200: team.delete() raise serializers.ValidationError("数据中心创建团队时发生错误") if code == 200: re = TeamBaseInfoSerializer(team) return Response(re.data, status=status.HTTP_201_CREATED) else: return Response(None, status=status.HTTP_500_INTERNAL_SERVER_ERROR)