29 lines
869 B
Python
29 lines
869 B
Python
from fastapi import APIRouter, Depends, UploadFile, File, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from app.db.database import get_db
|
|
from app.services.service_manager import ServiceManager
|
|
|
|
router = APIRouter(prefix="/manabox")
|
|
|
|
service_manager = ServiceManager()
|
|
|
|
@router.post("/process-csv")
|
|
async def process_manabox_csv(
|
|
file: UploadFile = File(...),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
try:
|
|
|
|
content = await file.read()
|
|
|
|
manabox_service = service_manager.get_service("manabox")
|
|
|
|
success = await manabox_service.process_manabox_csv(db, content)
|
|
|
|
if not success:
|
|
raise HTTPException(status_code=400, detail="Failed to process CSV file")
|
|
|
|
return {"message": "CSV processed successfully"}
|
|
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=str(e)) |