added update to comments with characters counter
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.routers import address, contact, proposal, dewar, shipment
|
||||
from app.routers import address, contact, proposal, dewar, shipment, upload
|
||||
from app.database import Base, engine, SessionLocal, load_sample_data
|
||||
|
||||
app = FastAPI()
|
||||
@ -35,6 +35,7 @@ app.include_router(address.router, prefix="/addresses", tags=["addresses"])
|
||||
app.include_router(proposal.router, prefix="/proposals", tags=["proposals"])
|
||||
app.include_router(dewar.router, prefix="/dewars", tags=["dewars"])
|
||||
app.include_router(shipment.router, prefix="/shipments", tags=["shipments"])
|
||||
app.include_router(upload.router, tags=["upload"]) # Removed the trailing '/' from the prefix
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
35
backend/app/routers/upload.py
Normal file
35
backend/app/routers/upload.py
Normal file
@ -0,0 +1,35 @@
|
||||
# app/routers/upload.py
|
||||
|
||||
from fastapi import APIRouter, UploadFile, File, HTTPException
|
||||
import os
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/upload")
|
||||
async def upload_file(file: UploadFile = File(...)):
|
||||
if not file.filename.endswith('.xlsx'):
|
||||
raise HTTPException(status_code=400, detail="Invalid file format. Please upload an .xlsx file.")
|
||||
|
||||
save_path = os.path.join("uploads", file.filename)
|
||||
os.makedirs(os.path.dirname(save_path), exist_ok=True)
|
||||
with open(save_path, "wb") as buffer:
|
||||
buffer.write(await file.read())
|
||||
|
||||
# Validate the file (add your validation logic here)
|
||||
is_valid, summary, error = validate_file(save_path)
|
||||
if not is_valid:
|
||||
raise HTTPException(status_code=400, detail=error)
|
||||
|
||||
return summary
|
||||
|
||||
|
||||
def validate_file(file_path: str):
|
||||
# Implement your file validation logic here
|
||||
# For demo purpose, assuming it always succeeds
|
||||
summary = {
|
||||
"dewars": 5,
|
||||
"pucks": 10,
|
||||
"samples": 100,
|
||||
}
|
||||
return True, summary, None
|
Reference in New Issue
Block a user