From a9b8925be8e564c5afa5a9cc49c12e3c62e71265 Mon Sep 17 00:00:00 2001 From: GotthardG <51994228+GotthardG@users.noreply.github.com> Date: Sun, 3 Nov 2024 21:42:42 +0100 Subject: [PATCH] added update to comments with characters counter --- backend/app/main.py | 3 +- backend/app/routers/upload.py | 35 +++ frontend/src/components/DewarDetails.tsx | 16 +- frontend/src/components/ShipmentDetails.tsx | 259 ++++++++++---------- frontend/src/components/ShipmentPanel.tsx | 44 ++-- frontend/src/components/Unipuck.tsx | 42 ++++ 6 files changed, 242 insertions(+), 157 deletions(-) create mode 100644 backend/app/routers/upload.py create mode 100644 frontend/src/components/Unipuck.tsx diff --git a/backend/app/main.py b/backend/app/main.py index 45495fa..5097c68 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -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 diff --git a/backend/app/routers/upload.py b/backend/app/routers/upload.py new file mode 100644 index 0000000..b0501a5 --- /dev/null +++ b/backend/app/routers/upload.py @@ -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 \ No newline at end of file diff --git a/frontend/src/components/DewarDetails.tsx b/frontend/src/components/DewarDetails.tsx index 6d6a9dc..d773c3c 100644 --- a/frontend/src/components/DewarDetails.tsx +++ b/frontend/src/components/DewarDetails.tsx @@ -12,8 +12,9 @@ import QRCode from 'react-qr-code'; import { ContactPerson, Address, - Dewar, ContactsService, AddressesService, ShipmentsService, DewarsService, + Dewar, ContactsService, AddressesService, ShipmentsService, } from '../../openapi'; +import Unipuck from '../components/Unipuck'; interface DewarDetailsProps { dewar: Dewar; @@ -252,10 +253,10 @@ const DewarDetails: React.FC = ({ shipment_date: existingShipment.shipment_date, shipment_status: existingShipment.shipment_status, comments: existingShipment.comments, - contact_person_id: existingShipment.contact_person.id, // Keep main shipment contact person + contact_person_id: existingShipment.contact_person.id, return_address_id: selectedReturnAddress, proposal_id: existingShipment.proposal?.id, - dewars: [updatedDewar], // Updated dewars array + dewars: [updatedDewar], }; console.log('Payload for update:', JSON.stringify(payload, null, 2)); @@ -292,18 +293,19 @@ const DewarDetails: React.FC = ({ sx={{ width: '300px', marginBottom: 2 }} /> - + {dewar.qrcode ? ( ) : ( No QR code available )} + - Number of Pucks: {dewar.number_of_pucks} + Number of Samples: {dewar.number_of_samples} Current Contact Person: