@mytec: 1.1iter ready for testing
This commit is contained in:
0
backend/app/api/__init__.py
Normal file
0
backend/app/api/__init__.py
Normal file
BIN
backend/app/api/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
backend/app/api/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/api/__pycache__/deps.cpython-311.pyc
Normal file
BIN
backend/app/api/__pycache__/deps.cpython-311.pyc
Normal file
Binary file not shown.
5
backend/app/api/deps.py
Normal file
5
backend/app/api/deps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from app.core.database import get_database
|
||||
|
||||
|
||||
async def get_db():
|
||||
return await get_database()
|
||||
0
backend/app/api/routes/__init__.py
Normal file
0
backend/app/api/routes/__init__.py
Normal file
BIN
backend/app/api/routes/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
backend/app/api/routes/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/api/routes/__pycache__/health.cpython-311.pyc
Normal file
BIN
backend/app/api/routes/__pycache__/health.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/api/routes/__pycache__/projects.cpython-311.pyc
Normal file
BIN
backend/app/api/routes/__pycache__/projects.cpython-311.pyc
Normal file
Binary file not shown.
18
backend/app/api/routes/health.py
Normal file
18
backend/app/api/routes/health.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from app.api.deps import get_db
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def health_check():
|
||||
return {"status": "ok", "service": "rfcp-backend", "version": "1.1.0"}
|
||||
|
||||
|
||||
@router.get("/db")
|
||||
async def db_check(db=Depends(get_db)):
|
||||
try:
|
||||
await db.command("ping")
|
||||
return {"status": "ok", "database": "connected"}
|
||||
except Exception as e:
|
||||
return {"status": "error", "database": str(e)}
|
||||
83
backend/app/api/routes/projects.py
Normal file
83
backend/app/api/routes/projects.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from datetime import datetime
|
||||
|
||||
from app.api.deps import get_db
|
||||
from app.models.project import Project, CoverageSettings
|
||||
from app.models.site import Site
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/current")
|
||||
async def get_current_project(db=Depends(get_db)):
|
||||
"""Get the global project."""
|
||||
project = await db.projects.find_one({"name": "global"})
|
||||
if not project:
|
||||
default = Project(name="global")
|
||||
result = await db.projects.insert_one(default.model_dump())
|
||||
return default.model_dump()
|
||||
project.pop("_id", None)
|
||||
return project
|
||||
|
||||
|
||||
@router.put("/current")
|
||||
async def update_current_project(project: Project, db=Depends(get_db)):
|
||||
"""Update the global project."""
|
||||
project.updated_at = datetime.utcnow()
|
||||
data = project.model_dump()
|
||||
await db.projects.update_one(
|
||||
{"name": "global"},
|
||||
{"$set": data},
|
||||
upsert=True,
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
@router.get("/current/sites")
|
||||
async def get_sites(db=Depends(get_db)):
|
||||
"""Get all sites from the global project."""
|
||||
project = await db.projects.find_one({"name": "global"})
|
||||
if not project:
|
||||
return []
|
||||
return project.get("sites", [])
|
||||
|
||||
|
||||
@router.put("/current/sites")
|
||||
async def update_sites(sites: list[Site], db=Depends(get_db)):
|
||||
"""Update all sites in the global project."""
|
||||
await db.projects.update_one(
|
||||
{"name": "global"},
|
||||
{
|
||||
"$set": {
|
||||
"sites": [s.model_dump() for s in sites],
|
||||
"updated_at": datetime.utcnow(),
|
||||
}
|
||||
},
|
||||
upsert=True,
|
||||
)
|
||||
return {"updated": len(sites)}
|
||||
|
||||
|
||||
@router.get("/current/settings")
|
||||
async def get_settings(db=Depends(get_db)):
|
||||
"""Get coverage settings."""
|
||||
project = await db.projects.find_one({"name": "global"})
|
||||
if not project:
|
||||
return CoverageSettings().model_dump()
|
||||
return project.get("settings", CoverageSettings().model_dump())
|
||||
|
||||
|
||||
@router.put("/current/settings")
|
||||
async def update_settings(settings: CoverageSettings, db=Depends(get_db)):
|
||||
"""Update coverage settings."""
|
||||
await db.projects.update_one(
|
||||
{"name": "global"},
|
||||
{
|
||||
"$set": {
|
||||
"settings": settings.model_dump(),
|
||||
"updated_at": datetime.utcnow(),
|
||||
}
|
||||
},
|
||||
upsert=True,
|
||||
)
|
||||
return settings.model_dump()
|
||||
Reference in New Issue
Block a user