Spaces:
Sleeping
Sleeping
| from typing import Optional | |
| from fastapi import APIRouter, File, Form, Query, UploadFile | |
| from app.core.errors import not_found | |
| from app.schemas.common import StatusMessage | |
| from app.schemas.data import ( | |
| GroupInfoResponse, | |
| SaveRdsRequest, | |
| SaveRdsResponse, | |
| UpdateDataFileRequest, | |
| UpdateDataFileResponse, | |
| UploadResponse, | |
| ) | |
| from app.schemas.project import SelectDataFileResponse | |
| from app.services import workspace_service | |
| router = APIRouter(prefix="/projects/{project_id}/data", tags=["data"]) | |
| def upload_data( | |
| project_id: str, | |
| files: UploadFile = File(...), | |
| group_index: str = Form("2"), | |
| wavenumber_range: Optional[str] = Form(default=None, alias="Wavenumber range"), | |
| ) -> dict: | |
| group_index_value = workspace_service.validate_group_index(group_index) | |
| return workspace_service.upload_data_file(project_id, files, group_index_value, wavenumber_range) | |
| def group_info( | |
| project_id: str, | |
| group_index: Optional[str] = Query(default=None), | |
| ) -> dict: | |
| workspace_service.validate_group_index(group_index or "2") | |
| try: | |
| return workspace_service.get_group_info(project_id) | |
| except KeyError: | |
| not_found("project_not_found", "项目不存在") | |
| def save_rds(project_id: str, payload: SaveRdsRequest) -> dict: | |
| try: | |
| return workspace_service.save_rds_data(project_id, payload.group_order) | |
| except KeyError: | |
| not_found("project_not_found", "项目不存在") | |
| def select_data_file(project_id: str, file_id: int) -> dict: | |
| try: | |
| return workspace_service.select_data_file(project_id, file_id) | |
| except KeyError as exc: | |
| if str(exc).strip("'") == "file_not_found": | |
| not_found("file_not_found", "数据文件不存在") | |
| not_found("project_not_found", "项目不存在") | |
| def update_data_file( | |
| project_id: str, | |
| file_id: int, | |
| payload: UpdateDataFileRequest, | |
| ) -> dict: | |
| try: | |
| return workspace_service.update_data_file(project_id, file_id, payload.wavenumber_range) | |
| except KeyError as exc: | |
| if str(exc).strip("'") == "file_not_found": | |
| not_found("file_not_found", "数据文件不存在") | |
| not_found("project_not_found", "项目不存在") | |
| def delete_data_file(project_id: str, file_id: int) -> dict: | |
| try: | |
| return workspace_service.delete_data_file(project_id, file_id) | |
| except KeyError as exc: | |
| if str(exc).strip("'") == "file_not_found": | |
| not_found("file_not_found", "数据文件不存在") | |
| not_found("project_not_found", "项目不存在") | |