Introduce service/repository dependency protocols and tests
This commit is contained in:
47
backend/app/repositories/protocols.py
Normal file
47
backend/app/repositories/protocols.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Repository interface protocols for dependency injection.
|
||||
|
||||
Routers and services can depend on these abstractions instead of concrete
|
||||
module implementations, making the backend easier to test and extend.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Protocol
|
||||
|
||||
import aiosqlite
|
||||
|
||||
from app.models.auth import Session
|
||||
|
||||
|
||||
class SessionRepository(Protocol):
|
||||
"""Protocol for session persistence operations."""
|
||||
|
||||
async def create_session(
|
||||
self,
|
||||
db: aiosqlite.Connection,
|
||||
token: str,
|
||||
created_at: str,
|
||||
expires_at: str,
|
||||
) -> Session:
|
||||
...
|
||||
|
||||
async def get_session(
|
||||
self,
|
||||
db: aiosqlite.Connection,
|
||||
token: str,
|
||||
) -> Session | None:
|
||||
...
|
||||
|
||||
async def delete_session(
|
||||
self,
|
||||
db: aiosqlite.Connection,
|
||||
token: str,
|
||||
) -> None:
|
||||
...
|
||||
|
||||
async def delete_expired_sessions(
|
||||
self,
|
||||
db: aiosqlite.Connection,
|
||||
now_iso: str,
|
||||
) -> int:
|
||||
...
|
||||
Reference in New Issue
Block a user