eksplicit mapping af envs
This commit is contained in:
0
backend/app/api/__init__.py
Normal file
0
backend/app/api/__init__.py
Normal file
9
backend/app/api/health.py
Normal file
9
backend/app/api/health.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health() -> JSONResponse:
|
||||
return JSONResponse({"status": "ok"})
|
||||
19
backend/app/api/match.py
Normal file
19
backend/app/api/match.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.models.match import MatchRequest, MatchResult
|
||||
from app.services import match_service, stats_service
|
||||
|
||||
router = APIRouter(tags=["match"])
|
||||
|
||||
|
||||
@router.post("", response_model=MatchResult)
|
||||
async def attempt_match(
|
||||
body: MatchRequest,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> MatchResult:
|
||||
result = await match_service.attempt_match(body.own_token, body.detected_token)
|
||||
if result["match"]:
|
||||
await stats_service.increment_matches(db)
|
||||
return MatchResult(**result)
|
||||
18
backend/app/api/session.py
Normal file
18
backend/app/api/session.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.models.session import SessionCreate, SessionResponse
|
||||
from app.services import session_service, stats_service
|
||||
|
||||
router = APIRouter(tags=["session"])
|
||||
|
||||
|
||||
@router.post("", response_model=SessionResponse)
|
||||
async def create_session(
|
||||
body: SessionCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> SessionResponse:
|
||||
result = await session_service.create_session(body.ble_token, body.interests)
|
||||
await stats_service.increment_sessions(db)
|
||||
return SessionResponse(**result)
|
||||
14
backend/app/api/stats.py
Normal file
14
backend/app/api/stats.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.models.stats import StatsResponse
|
||||
from app.services import stats_service
|
||||
|
||||
router = APIRouter(tags=["stats"])
|
||||
|
||||
|
||||
@router.get("", response_model=StatsResponse)
|
||||
async def get_stats(db: AsyncSession = Depends(get_db)) -> StatsResponse:
|
||||
data = await stats_service.get_stats(db)
|
||||
return StatsResponse(**data)
|
||||
16
backend/app/api/ws.py
Normal file
16
backend/app/api/ws.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
||||
|
||||
from app.services.ws_manager import manager
|
||||
|
||||
router = APIRouter(tags=["websocket"])
|
||||
|
||||
|
||||
@router.websocket("/ws/{ble_token}")
|
||||
async def websocket_endpoint(websocket: WebSocket, ble_token: str) -> None:
|
||||
await manager.connect(ble_token, websocket)
|
||||
try:
|
||||
while True:
|
||||
# Keep the connection alive; nudges are pushed server-side.
|
||||
await websocket.receive_text()
|
||||
except WebSocketDisconnect:
|
||||
manager.disconnect(ble_token)
|
||||
Reference in New Issue
Block a user