feat: implement chat messaging and Redis cache
This commit is contained in:
+13
-1
@@ -1,3 +1,4 @@
|
||||
from datetime import timezone
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, status
|
||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -16,6 +17,7 @@ router = APIRouter(prefix="/api/v1/auth", tags=["Authentication"])
|
||||
basic_security = HTTPBasic(auto_error=False)
|
||||
|
||||
|
||||
|
||||
@router.post("/sessions", status_code=status.HTTP_201_CREATED)
|
||||
def create_session(
|
||||
credentials: HTTPBasicCredentials = Depends(basic_security),
|
||||
@@ -36,10 +38,19 @@ def create_session(
|
||||
password=credentials.password,
|
||||
)
|
||||
|
||||
expires_at = result["expires_at"]
|
||||
|
||||
if expires_at.tzinfo is None:
|
||||
expires_at = expires_at.replace(tzinfo=timezone.utc)
|
||||
else:
|
||||
expires_at = expires_at.astimezone(timezone.utc)
|
||||
|
||||
return {
|
||||
"token": result["token"],
|
||||
"token_type": result["token_type"],
|
||||
"expires_at": result["expires_at"],
|
||||
"expires_at": expires_at.isoformat(
|
||||
timespec="microseconds"
|
||||
).replace("+00:00", "Z"),
|
||||
"user": user_to_response(result["user"]),
|
||||
}
|
||||
|
||||
@@ -53,6 +64,7 @@ def create_session(
|
||||
) from None
|
||||
|
||||
|
||||
|
||||
@router.delete("/sessions/current", status_code=status.HTTP_204_NO_CONTENT)
|
||||
def delete_current_session(
|
||||
authorization: str | None = Header(default=None),
|
||||
|
||||
Reference in New Issue
Block a user