mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-24 06:45:16 +02:00
rename SessionDependency to DbSessionDependency
This commit is contained in:
@@ -8,10 +8,12 @@ from jwt.exceptions import InvalidTokenError
|
||||
from pydantic import BaseModel
|
||||
|
||||
from auth.config import AuthConfig
|
||||
from database import SessionDependency
|
||||
from database import DbSessionDependency
|
||||
from database.users import User
|
||||
|
||||
|
||||
# TODO: evaluate FASTAPI-Users package
|
||||
|
||||
class Token(BaseModel):
|
||||
access_token: str
|
||||
token_type: str
|
||||
@@ -28,7 +30,7 @@ oauth2_scheme = OAuth2PasswordBearer(tokenUrl="api/v1/token")
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
async def get_current_user(db: SessionDependency, token: str = Depends(oauth2_scheme)) -> User:
|
||||
async def get_current_user(db: DbSessionDependency, token: str = Depends(oauth2_scheme)) -> User:
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Could not validate credentials",
|
||||
|
||||
@@ -6,7 +6,7 @@ from fastapi.security import OAuth2PasswordRequestForm
|
||||
from sqlmodel import select
|
||||
|
||||
from auth import Token, create_access_token, router
|
||||
from database import SessionDependency
|
||||
from database import DbSessionDependency
|
||||
from database.users import User
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ def get_password_hash(password: str) -> str:
|
||||
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")
|
||||
|
||||
|
||||
def authenticate_user(db: SessionDependency, email: str, password: str) -> bool | User:
|
||||
def authenticate_user(db: DbSessionDependency, email: str, password: str) -> bool | User:
|
||||
"""
|
||||
|
||||
:param email: email of the USER
|
||||
@@ -39,7 +39,7 @@ def authenticate_user(db: SessionDependency, email: str, password: str) -> bool
|
||||
@router.post("/token")
|
||||
async def login_for_access_token(
|
||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
|
||||
db: SessionDependency,
|
||||
db: DbSessionDependency,
|
||||
) -> Token:
|
||||
user = authenticate_user(db,form_data.username, form_data.password)
|
||||
if not user:
|
||||
|
||||
@@ -23,5 +23,5 @@ def get_session() -> Generator[Session, Any, None]:
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
||||
SessionDependency = Annotated[Session, Depends(get_session)]
|
||||
|
||||
DbSessionDependency = Annotated[Session, Depends(get_session)]
|
||||
|
||||
@@ -7,6 +7,7 @@ from pydantic import BaseModel, computed_field
|
||||
from database.torrents import QualityMixin, Torrent
|
||||
|
||||
|
||||
# TODO: use something like strategy pattern to make sorting more user customizable
|
||||
class IndexerQueryResult(BaseModel, QualityMixin):
|
||||
id: UUID = pydantic.Field(default_factory=uuid4)
|
||||
title: str
|
||||
|
||||
@@ -12,7 +12,7 @@ import auth
|
||||
import dowloadClients
|
||||
import indexer
|
||||
import metadataProvider
|
||||
from database import SessionDependency
|
||||
from database import DbSessionDependency
|
||||
from database.torrents import Torrent
|
||||
from database.tv import Season, Show
|
||||
from indexer import IndexerQueryResult
|
||||
@@ -34,7 +34,7 @@ class ShowDetails(BaseModel):
|
||||
status.HTTP_201_CREATED: {"model": Show, "description": "Successfully created show"},
|
||||
status.HTTP_409_CONFLICT: {"model": Message, "description": "Show already exists"},
|
||||
})
|
||||
def add_show(db: SessionDependency, show_id: int, metadata_provider: str = "tmdb", version: str = ""):
|
||||
def add_show(db: DbSessionDependency, show_id: int, metadata_provider: str = "tmdb", version: str = ""):
|
||||
res = db.exec(select(Show).
|
||||
where(Show.external_id == show_id).
|
||||
where(Show.metadata_provider == metadata_provider).
|
||||
@@ -59,14 +59,14 @@ def add_show(db: SessionDependency, show_id: int, metadata_provider: str = "tmdb
|
||||
|
||||
|
||||
@router.delete("/{show_id}", status_code=status.HTTP_200_OK)
|
||||
def delete_show(db: SessionDependency, show_id: UUID):
|
||||
def delete_show(db: DbSessionDependency, show_id: UUID):
|
||||
db.delete(db.get(Show, show_id))
|
||||
db.commit()
|
||||
|
||||
|
||||
@router.patch("/{show_id}/{season_id}", status_code=status.HTTP_200_OK, dependencies=[Depends(auth.get_current_user)],
|
||||
response_model=Season)
|
||||
def add_season(db: SessionDependency, season_id: UUID):
|
||||
def add_season(db: DbSessionDependency, season_id: UUID):
|
||||
"""
|
||||
adds requested flag to a season
|
||||
"""
|
||||
@@ -81,7 +81,7 @@ def add_season(db: SessionDependency, season_id: UUID):
|
||||
|
||||
@router.delete("/{show_id}/{season_id}", status_code=status.HTTP_200_OK, dependencies=[Depends(auth.get_current_user)],
|
||||
response_model=Show)
|
||||
def delete_season(db: SessionDependency, show_id: UUID, season: int):
|
||||
def delete_season(db: DbSessionDependency, show_id: UUID, season: int):
|
||||
"""
|
||||
removes requested flag from a season
|
||||
"""
|
||||
@@ -96,7 +96,7 @@ def delete_season(db: SessionDependency, show_id: UUID, season: int):
|
||||
@router.get("/{show_id}/{season_id}/torrent", status_code=status.HTTP_200_OK, dependencies=[Depends(
|
||||
auth.get_current_user)],
|
||||
response_model=list[IndexerQueryResult])
|
||||
def get_season_torrents(db: SessionDependency, show_id: UUID, season_id: UUID):
|
||||
def get_season_torrents(db: DbSessionDependency, show_id: UUID, season_id: UUID):
|
||||
season = db.get(Season, season_id)
|
||||
|
||||
if season is None:
|
||||
@@ -121,7 +121,7 @@ def get_season_torrents(db: SessionDependency, show_id: UUID, season_id: UUID):
|
||||
|
||||
@router.post("/{show_id}/torrent", status_code=status.HTTP_200_OK, dependencies=[Depends(
|
||||
auth.get_current_user)], response_model=list[Season])
|
||||
def download_seasons_torrent(db: SessionDependency, show_id: UUID, torrent_id: UUID):
|
||||
def download_seasons_torrent(db: DbSessionDependency, show_id: UUID, torrent_id: UUID):
|
||||
"""
|
||||
downloads torrents for a show season, links the torrent for all seasons the torrent contains
|
||||
|
||||
@@ -153,7 +153,7 @@ def download_seasons_torrent(db: SessionDependency, show_id: UUID, torrent_id: U
|
||||
|
||||
@router.post("/{show_id}/{season_id}/torrent", status_code=status.HTTP_200_OK, dependencies=[Depends(
|
||||
auth.get_current_user)], response_model=list[Season])
|
||||
def delete_seasons_torrent(db: SessionDependency, show_id: UUID, season_id: UUID, torrent_id: UUID):
|
||||
def delete_seasons_torrent(db: DbSessionDependency, show_id: UUID, season_id: UUID, torrent_id: UUID):
|
||||
"""
|
||||
downloads torrents for a season, links the torrent only to the specified season
|
||||
this means that multiple torrents can contain a season but you can choose from one which the content should be
|
||||
@@ -186,13 +186,13 @@ def delete_seasons_torrent(db: SessionDependency, show_id: UUID, season_id: UUID
|
||||
|
||||
|
||||
@router.get("/", dependencies=[Depends(auth.get_current_user)], response_model=list[Show])
|
||||
def get_shows(db: SessionDependency):
|
||||
def get_shows(db: DbSessionDependency):
|
||||
""""""
|
||||
return db.exec(select(Show)).unique().fetchall()
|
||||
|
||||
|
||||
@router.get("/{show_id}", dependencies=[Depends(auth.get_current_user)], response_model=ShowDetails)
|
||||
def get_show(db: SessionDependency, show_id: UUID):
|
||||
def get_show(db: DbSessionDependency, show_id: UUID):
|
||||
"""
|
||||
|
||||
:param show_id:
|
||||
|
||||
@@ -5,7 +5,7 @@ from starlette.responses import JSONResponse
|
||||
|
||||
from auth import get_current_user
|
||||
from auth.password import get_password_hash
|
||||
from database import SessionDependency
|
||||
from database import DbSessionDependency
|
||||
from database.users import User, UserCreate, UserPublic
|
||||
from users import log
|
||||
|
||||
@@ -24,7 +24,7 @@ class Message(BaseModel):
|
||||
201: {"model": UserPublic, "description": "User created successfully"}
|
||||
})
|
||||
async def create_user(
|
||||
db: SessionDependency,
|
||||
db: DbSessionDependency,
|
||||
user: UserCreate = Depends(UserCreate),
|
||||
):
|
||||
internal_user = User(name=user.name, lastname=user.lastname, email=user.email,
|
||||
|
||||
Reference in New Issue
Block a user