same as original code now -5 days of my life

This commit is contained in:
2025-02-07 18:27:20 -05:00
parent 511b070cbb
commit 1f5361da88
12 changed files with 394 additions and 394 deletions

View File

@@ -1,7 +1,9 @@
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, BackgroundTasks
from fastapi.responses import StreamingResponse
from typing import Optional
from typing import Optional, List
from io import BytesIO
import logging
from datetime import datetime
from schemas.file import (
FileSchema,
@@ -23,6 +25,7 @@ from schemas.box import (
from services.file import FileService
from services.box import BoxService
from services.task import TaskService
from services.pricing import PricingService
from dependencies import (
get_file_service,
get_box_service,
@@ -30,7 +33,8 @@ from dependencies import (
get_create_file_metadata,
get_box_data,
get_box_update_data,
get_open_box_data
get_open_box_data,
get_pricing_service
)
logger = logging.getLogger(__name__)
@@ -143,7 +147,9 @@ async def create_box(
) -> CreateBoxResponse:
"""Create a new box."""
try:
result = box_service.create_box(box_data)
result, success = box_service.create_box(box_data)
if not success:
raise HTTPException(status_code=400, detail="Box creation failed, box already exists")
return CreateBoxResponse(
status_code=201,
success=True,
@@ -204,4 +210,69 @@ async def open_box(
)
except Exception as e:
logger.error(f"Open box failed: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))
@router.delete("/boxes/{box_id}/open", response_model=CreateOpenBoxResponse, status_code=200)
async def delete_open_box(
box_id: str,
box_service: BoxService = Depends(get_box_service)
) -> CreateOpenBoxResponse:
"""Delete an open box by ID."""
try:
result = box_service.delete_open_box(box_id)
return CreateOpenBoxResponse(
status_code=201,
success=True,
open_box=[OpenBoxSchema.from_orm(result)]
)
except Exception as e:
logger.error(f"Delete open box failed: {str(e)}")
raise HTTPException(status_code=400, detail=str(e)
)
@router.post("/tcgplayer/inventory/add", response_class=StreamingResponse)
async def create_inventory_add_file(
request: dict, # Just use a dict instead
pricing_service: PricingService = Depends(get_pricing_service),
):
"""Create a new inventory add file for download."""
try:
# Get IDs directly from the dict
open_box_ids = request.get('open_box_ids', [])
content = pricing_service.generate_tcgplayer_inventory_update_file_with_pricing(open_box_ids)
stream = BytesIO(content)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
return StreamingResponse(
iter([stream.getvalue()]),
media_type="text/csv",
headers={
'Content-Disposition': f'attachment; filename="inventory_add_{timestamp}.csv"'
}
)
except Exception as e:
logger.error(f"Create inventory add file failed: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))
@router.get("/tcgplayer/inventory/update", response_class=StreamingResponse)
async def create_inventory_update_file(
pricing_service: PricingService = Depends(get_pricing_service),
):
"""Create a new inventory update file for download."""
try:
content = pricing_service.generate_tcgplayer_inventory_update_file_with_pricing()
stream = BytesIO(content)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
return StreamingResponse(
iter([stream.getvalue()]),
media_type="text/csv",
headers={
'Content-Disposition': f'attachment; filename="inventory_update_{timestamp}.csv"'
}
)
except Exception as e:
logger.error(f"Create inventory update file failed: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))