mirror of
https://github.com/sstent/AICyclingCoach.git
synced 2026-04-05 12:33:03 +00:00
sync
This commit is contained in:
40
backend/app/routes/export.py
Normal file
40
backend/app/routes/export.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from fastapi import APIRouter, Query, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
from app.services.export_service import ExportService
|
||||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@router.get("/export")
|
||||
async def export_data(
|
||||
types: str = Query(..., description="Comma-separated list of data types to export"),
|
||||
format: str = Query('json', description="Export format (json, zip, gpx)")
|
||||
):
|
||||
valid_types = {'routes', 'rules', 'plans'}
|
||||
requested_types = set(types.split(','))
|
||||
|
||||
# Validate requested types
|
||||
if not requested_types.issubset(valid_types):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Invalid export types. Valid types are: {', '.join(valid_types)}"
|
||||
)
|
||||
|
||||
try:
|
||||
exporter = ExportService()
|
||||
export_path = await exporter.create_export(
|
||||
export_types=list(requested_types),
|
||||
export_format=format
|
||||
)
|
||||
|
||||
return FileResponse(
|
||||
export_path,
|
||||
media_type="application/zip" if format == 'zip' else "application/json",
|
||||
filename=f"export_{'_'.join(requested_types)}.{format}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Export failed: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail="Export failed") from e
|
||||
38
backend/app/routes/import.py
Normal file
38
backend/app/routes/import.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from fastapi import APIRouter, UploadFile, File, Form, HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
from app.services.import_service import ImportService
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@router.post("/import/validate")
|
||||
async def validate_import(
|
||||
file: UploadFile = File(...),
|
||||
):
|
||||
try:
|
||||
importer = ImportService()
|
||||
validation_result = await importer.validate_import(file)
|
||||
return JSONResponse(content=validation_result)
|
||||
except Exception as e:
|
||||
logger.error(f"Import validation failed: {str(e)}")
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
|
||||
@router.post("/import")
|
||||
async def execute_import(
|
||||
file: UploadFile = File(...),
|
||||
conflict_resolution: str = Form("skip"),
|
||||
resolutions: Optional[str] = Form(None),
|
||||
):
|
||||
try:
|
||||
importer = ImportService()
|
||||
import_result = await importer.execute_import(
|
||||
file,
|
||||
conflict_resolution,
|
||||
resolutions
|
||||
)
|
||||
return JSONResponse(content=import_result)
|
||||
except Exception as e:
|
||||
logger.error(f"Import failed: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||
Reference in New Issue
Block a user