Coverage for app/controllers/users_controller.py: 100%
28 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-02 23:27 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-02 23:27 +0000
1from fastapi import APIRouter, Depends
2from sqlalchemy.orm import Session
3from pydantic import BaseModel, EmailStr
4from app.db.supabaseDB import get_db
5from app.core.security import get_current_user_id, require_role
6from app.services.user import get_user_info
7from app.services.notifications import get_user_notifications
8from app.services.events import get_world_events
10users_controller = APIRouter()
13@users_controller.get("/me")
14def get_me(user_id: str = Depends(get_current_user_id), db: Session = Depends(get_db)):
15 response = get_user_info(user_id, db)
16 return response
18# NOTE: Requires passing in pagination params from client
19@users_controller.get("/notifications")
20def get_notifications(
21 limit: int = 10,
22 offset: int = 0,
23 user_id: str = Depends(get_current_user_id),
24 db: Session = Depends(get_db),
25):
26 user_participations = get_user_info(user_id, db)
27 response = get_user_notifications(limit, offset, user_participations, db)
28 return response
31# NOTE: Requires passing in pagination params from client
32@users_controller.get("/events")
33def get_events(
34 limit: int = 10,
35 offset: int = 0,
36 user_id: str = Depends(get_current_user_id),
37 db: Session = Depends(get_db),
38):
39 user_participations = get_user_info(user_id, db)
40 user_worlds = [world.id for world in user_participations["world_info"]]
41 response = get_world_events(limit, offset, user_worlds, db)
42 return response
45@users_controller.get("/{user_id}")
46def get_user(user_id: str, db: Session = Depends(get_db)):
47 response = get_user_info(user_id, db)
48 # If wanting to restrict info
49 # return {
50 # "user_campaigns": response["campaign_names"],
51 # "user_worlds": response["world_names"],
52 # }
53 return response