forked from mtusi2026/mtusi2026lab2
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
from sqlalchemy.ext.asyncio import AsyncSession
|
|
import uuid
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from src.models.sessions import Session
|
|
from src.api.repositories.core import DatabaseManager
|
|
from src.models.sessions import Session
|
|
|
|
|
|
class SessionRepo(DatabaseManager):
|
|
def __init__(self, session: AsyncSession):
|
|
super().__init__(session, Session)
|
|
|
|
async def create(self, token_hash: str, user_id: uuid.UUID, expires_at: datetime) -> Optional[Session]:
|
|
result = await super().create(token_hash=token_hash, user_id=user_id, expires_at=expires_at)
|
|
return result
|
|
|
|
async def get_by_token_hash(self, token_hash: str) -> Optional[Session]:
|
|
result = await super().get_by_field("token_hash", token_hash)
|
|
return result
|
|
|
|
async def get_by_user_id(self, user_id: str) -> Optional[Session]:
|
|
result = await super().get_by_field("user_id", user_id)
|
|
return result
|
|
|
|
async def delete_by_user_id(self, token_hash: str) -> bool:
|
|
result = await super().delete_by_field("token_hash", token_hash)
|
|
return result |