more stuff yay

This commit is contained in:
2025-02-05 21:51:22 -05:00
parent bd9cfca7a9
commit a78c3bcba3
15 changed files with 958 additions and 249 deletions

View File

@@ -11,8 +11,8 @@ from services.file import FileService
from services.product import ProductService
from services.task import TaskService
from schemas.file import FileSchema, CreateFileRequest, CreateFileResponse, GetFileResponse, DeleteFileResponse, GetFileQueryParams
from schemas.box import CreateBoxResponse, CreateBoxRequestData
from dependencies import get_data_service, get_upload_service, get_tcgplayer_service, get_box_service, get_create_file_metadata, get_file_service, get_product_service, get_task_service
from schemas.box import CreateBoxResponse, CreateBoxRequest, BoxSchema, UpdateBoxRequest, CreateOpenBoxRequest, CreateOpenBoxResponse, OpenBoxSchema
from dependencies import get_data_service, get_upload_service, get_tcgplayer_service, get_box_service, get_create_file_metadata, get_file_service, get_product_service, get_task_service, get_box_data, get_box_update_data, get_open_box_data
import logging
@@ -31,11 +31,6 @@ MAX_FILE_SIZE = 1024 * 1024 * 100 # 100 MB
response_model=CreateFileResponse,
status_code=201
)
@router.post(
"/files",
response_model=CreateFileResponse,
status_code=201
)
async def create_file(
background_tasks: BackgroundTasks,
file: UploadFile = File(...),
@@ -144,9 +139,76 @@ async def delete_file(
raise HTTPException(status_code=400, detail=str(e))
## BOX
## CREATE
@router.post("/boxes", response_model=CreateBoxResponse, status_code=201)
async def create_box(
box_data: CreateBoxRequest = Depends(get_box_data),
box_service: BoxService = Depends(get_box_service)
):
try:
result = box_service.create_box(box_data)
return CreateBoxResponse(
status_code=201,
success=True,
box=[BoxSchema.from_orm(result)]
)
except Exception as e:
logger.error(f"Create box failed: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))
## UPDATE
@router.put("/boxes/{box_id}", response_model=CreateBoxResponse)
async def update_box(
box_id: str,
box_data: UpdateBoxRequest = Depends(get_box_update_data),
box_service: BoxService = Depends(get_box_service)
):
try:
result = box_service.update_box(box_id, box_data)
return CreateBoxResponse(
status_code=200,
success=True,
box=[BoxSchema.from_orm(result)]
)
except Exception as e:
logger.error(f"Update box failed: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))
## DELETE
@router.delete("/boxes/{box_id}", response_model=CreateBoxResponse)
async def delete_box(
box_id: str,
box_service: BoxService = Depends(get_box_service)
):
try:
result = box_service.delete_box(box_id)
return CreateBoxResponse(
status_code=200,
success=True,
box=[BoxSchema.from_orm(result)]
)
except Exception as e:
logger.error(f"Delete box failed: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))
# BOX OPEN
@router.post("/boxes/{box_id}/open", response_model=CreateOpenBoxResponse, status_code=201)
async def open_box(
box_id: str,
box_data: CreateOpenBoxRequest = Depends(get_open_box_data),
box_service: BoxService = Depends(get_box_service)
):
try:
result = box_service.open_box(box_id, box_data)
return CreateOpenBoxResponse(
status_code=201,
success=True,
open_box=[OpenBoxSchema.from_orm(result)]
)
except Exception as e:
logger.error(f"Open box failed: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))