mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-11-01 10:25:45 +08:00
Remove list endpoint and related methods
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from typing import Generic, List, Optional, Type
|
||||
from typing import Generic, Optional, Type
|
||||
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
|
||||
@ -18,10 +18,6 @@ class BaseUserDatabase(Generic[UD]):
|
||||
def __init__(self, user_db_model: Type[UD]):
|
||||
self.user_db_model = user_db_model
|
||||
|
||||
async def list(self) -> List[UD]:
|
||||
"""List all users."""
|
||||
raise NotImplementedError()
|
||||
|
||||
async def get(self, id: str) -> Optional[UD]:
|
||||
"""Get a single user by id."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import List, Optional, Type
|
||||
from typing import Optional, Type
|
||||
|
||||
from motor.motor_asyncio import AsyncIOMotorCollection
|
||||
|
||||
@ -22,9 +22,6 @@ class MongoDBUserDatabase(BaseUserDatabase[UD]):
|
||||
self.collection.create_index("id", unique=True)
|
||||
self.collection.create_index("email", unique=True)
|
||||
|
||||
async def list(self) -> List[UD]:
|
||||
return [self.user_db_model(**user) async for user in self.collection.find()]
|
||||
|
||||
async def get(self, id: str) -> Optional[UD]:
|
||||
user = await self.collection.find_one({"id": id})
|
||||
return self.user_db_model(**user) if user else None
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import List, Mapping, Optional, Type
|
||||
from typing import Mapping, Optional, Type
|
||||
|
||||
from databases import Database
|
||||
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Table, select
|
||||
@ -75,11 +75,6 @@ class SQLAlchemyUserDatabase(BaseUserDatabase[UD]):
|
||||
self.users = users
|
||||
self.oauth_accounts = oauth_accounts
|
||||
|
||||
async def list(self) -> List[UD]:
|
||||
query = self.users.select()
|
||||
users = await self.database.fetch_all(query)
|
||||
return [await self._make_user(user) for user in users]
|
||||
|
||||
async def get(self, id: str) -> Optional[UD]:
|
||||
query = self.users.select().where(self.users.c.id == id)
|
||||
user = await self.database.fetch_one(query)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import List, Optional, Type
|
||||
from typing import Optional, Type
|
||||
|
||||
from tortoise import fields, models
|
||||
from tortoise.exceptions import DoesNotExist
|
||||
@ -61,16 +61,6 @@ class TortoiseUserDatabase(BaseUserDatabase[UD]):
|
||||
self.model = model
|
||||
self.oauth_account_model = oauth_account_model
|
||||
|
||||
async def list(self) -> List[UD]:
|
||||
query = self.model.all()
|
||||
|
||||
if self.oauth_account_model is not None:
|
||||
query = query.prefetch_related("oauth_accounts")
|
||||
|
||||
users = await query
|
||||
|
||||
return [self.user_db_model(**await user.to_dict()) for user in users]
|
||||
|
||||
async def get(self, id: str) -> Optional[UD]:
|
||||
try:
|
||||
query = self.model.get(id=id)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import Any, Dict, List, Type, cast
|
||||
from typing import Any, Dict, Type, cast
|
||||
|
||||
import jwt
|
||||
from fastapi import Body, Depends, HTTPException
|
||||
@ -185,14 +185,6 @@ def get_user_router(
|
||||
|
||||
return updated_user
|
||||
|
||||
@router.get(
|
||||
"/",
|
||||
response_model=List[user_model], # type: ignore
|
||||
dependencies=[Depends(get_current_superuser)],
|
||||
)
|
||||
async def list_users():
|
||||
return await user_db.list()
|
||||
|
||||
@router.get(
|
||||
"/{id}",
|
||||
response_model=user_model,
|
||||
|
||||
Reference in New Issue
Block a user