feat: Update spec, fix bugs, improve UI/UX, and clean up code
This commit is contained in:
@@ -1,36 +1,48 @@
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Optional
|
||||
from sqlalchemy.orm import Session
|
||||
from ..services.postgresql_manager import PostgreSQLManager
|
||||
from ..utils.config import config
|
||||
from ..models.activity import Activity
|
||||
from ..models.sync_log import SyncLog
|
||||
from datetime import datetime
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
def get_db():
|
||||
db_manager = PostgreSQLManager(config.DATABASE_URL)
|
||||
with db_manager.get_db_session() as session:
|
||||
yield session
|
||||
|
||||
class SyncLogResponse(BaseModel):
|
||||
id: int
|
||||
operation: str
|
||||
status: str
|
||||
message: Optional[str]
|
||||
start_time: str
|
||||
end_time: Optional[str]
|
||||
message: Optional[str] = None
|
||||
start_time: datetime
|
||||
end_time: Optional[datetime] = None
|
||||
records_processed: int
|
||||
records_failed: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
class StatusResponse(BaseModel):
|
||||
total_weight_records: int
|
||||
synced_weight_records: int
|
||||
unsynced_weight_records: int
|
||||
total_activities: int
|
||||
downloaded_activities: int
|
||||
recent_logs: List[SyncLogResponse]
|
||||
|
||||
@router.get("/status")
|
||||
async def get_status():
|
||||
# This would return the current sync status
|
||||
# Implementation will connect with the services layer
|
||||
return {
|
||||
"total_weight_records": 100,
|
||||
"synced_weight_records": 85,
|
||||
"unsynced_weight_records": 15,
|
||||
"total_activities": 50,
|
||||
"downloaded_activities": 30,
|
||||
"recent_logs": []
|
||||
}
|
||||
@router.get("/status", response_model=StatusResponse)
|
||||
def get_status(db: Session = Depends(get_db)):
|
||||
"""Returns the current sync status and recent logs."""
|
||||
total_activities = db.query(Activity).count()
|
||||
downloaded_activities = db.query(Activity).filter(Activity.download_status == 'downloaded').count()
|
||||
|
||||
recent_logs = db.query(SyncLog).order_by(SyncLog.start_time.desc()).limit(10).all()
|
||||
|
||||
return StatusResponse(
|
||||
total_activities=total_activities,
|
||||
downloaded_activities=downloaded_activities,
|
||||
recent_logs=recent_logs
|
||||
)
|
||||
Reference in New Issue
Block a user