fase 3 afgerond
This commit is contained in:
@@ -15,6 +15,15 @@ class SelectedEpisodesReorderRequest(BaseModel):
|
||||
to_index: int = Field(ge=0)
|
||||
|
||||
|
||||
class SelectedFilesAddRequest(BaseModel):
|
||||
items: list[dict] = Field(default_factory=list)
|
||||
|
||||
|
||||
class SelectedFilesReorderRequest(BaseModel):
|
||||
from_index: int = Field(ge=0)
|
||||
to_index: int = Field(ge=0)
|
||||
|
||||
|
||||
def _normalize_session_id(session_id: str) -> str:
|
||||
normalized = session_id.strip()
|
||||
if not normalized:
|
||||
@@ -74,3 +83,57 @@ def reorder_selected_episodes(
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
return {"session_id": normalized_session_id, "items": items}
|
||||
|
||||
|
||||
@router.get("/selected-files")
|
||||
def get_selected_files(session_id: str = Query("default", min_length=1)):
|
||||
service = SessionService()
|
||||
normalized_session_id = _normalize_session_id(session_id)
|
||||
items = service.list_selected_files(normalized_session_id)
|
||||
return {"session_id": normalized_session_id, "items": items}
|
||||
|
||||
|
||||
@router.post("/selected-files")
|
||||
def add_selected_files(
|
||||
payload: SelectedFilesAddRequest,
|
||||
session_id: str = Query("default", min_length=1),
|
||||
):
|
||||
service = SessionService()
|
||||
normalized_session_id = _normalize_session_id(session_id)
|
||||
items = service.add_selected_files(normalized_session_id, payload.items)
|
||||
return {"session_id": normalized_session_id, "items": items}
|
||||
|
||||
|
||||
@router.delete("/selected-files")
|
||||
def clear_selected_files(session_id: str = Query("default", min_length=1)):
|
||||
service = SessionService()
|
||||
normalized_session_id = _normalize_session_id(session_id)
|
||||
service.clear_selected_files(normalized_session_id)
|
||||
return {"session_id": normalized_session_id, "items": []}
|
||||
|
||||
|
||||
@router.delete("/selected-files/{selection_id}")
|
||||
def remove_selected_file(selection_id: int, session_id: str = Query("default", min_length=1)):
|
||||
service = SessionService()
|
||||
normalized_session_id = _normalize_session_id(session_id)
|
||||
items = service.remove_selected_file(normalized_session_id, selection_id)
|
||||
return {"session_id": normalized_session_id, "items": items}
|
||||
|
||||
|
||||
@router.post("/selected-files/reorder")
|
||||
def reorder_selected_files(
|
||||
payload: SelectedFilesReorderRequest,
|
||||
session_id: str = Query("default", min_length=1),
|
||||
):
|
||||
service = SessionService()
|
||||
normalized_session_id = _normalize_session_id(session_id)
|
||||
try:
|
||||
items = service.reorder_selected_files(
|
||||
normalized_session_id,
|
||||
payload.from_index,
|
||||
payload.to_index,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
return {"session_id": normalized_session_id, "items": items}
|
||||
|
||||
Reference in New Issue
Block a user