2025-11-06 07:23:24 +00:00
|
|
|
|
2025-11-17 03:53:15 +00:00
|
|
|
from fastapi import APIRouter, File, Form, UploadFile, Depends
|
2025-11-06 07:23:24 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
from typing import List, Optional
|
|
|
|
|
from services.upload_file.upload import handle_upload_file, handle_process_pdf, handle_to_postgis
|
2025-11-17 03:53:15 +00:00
|
|
|
from api.deps.role_dependency import require_role
|
|
|
|
|
from database.connection import engine
|
2025-11-06 07:23:24 +00:00
|
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
@router.post("/file")
|
2025-11-17 03:53:15 +00:00
|
|
|
# async def upload_file(file: UploadFile = File(...), page: Optional[str] = Form(""), sheet: Optional[str] = Form(""), user = Depends(require_role("admin"))):
|
2025-11-06 07:23:24 +00:00
|
|
|
async def upload_file(file: UploadFile = File(...), page: Optional[str] = Form(""), sheet: Optional[str] = Form("")):
|
|
|
|
|
return await handle_upload_file(file, page, sheet)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PdfRequest(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
columns: List[str]
|
|
|
|
|
rows: List[List]
|
|
|
|
|
|
|
|
|
|
@router.post("/process-pdf")
|
|
|
|
|
async def upload_file(payload: PdfRequest):
|
|
|
|
|
return await handle_process_pdf(payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UploadRequest(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
rows: List[dict]
|
|
|
|
|
columns: List[str]
|
|
|
|
|
|
|
|
|
|
@router.post("/to-postgis")
|
2025-11-17 03:53:15 +00:00
|
|
|
async def upload_to_postgis(payload: UploadRequest):
|
|
|
|
|
return await handle_to_postgis(payload, engine)
|