|
| 1 | +# Copyright (C) 2025 Intel Corporation |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +from typing import Annotated |
| 5 | + |
| 6 | +from fastapi import APIRouter, Depends, Query, status |
| 7 | +from starlette.responses import FileResponse |
| 8 | + |
| 9 | +from app.api.dependencies import get_dataset_revision, get_dataset_service, get_project |
| 10 | +from app.api.schemas.dataset_item import DatasetItemsWithPagination, DatasetItemView |
| 11 | +from app.api.validators import DatasetItemID, DatasetRevisionID |
| 12 | +from app.models import DatasetItemSubset, Project |
| 13 | +from app.models.dataset_revision import DatasetRevision |
| 14 | +from app.services import DatasetService |
| 15 | + |
| 16 | +router = APIRouter( |
| 17 | + prefix="/api/projects/{project_id}/dataset_revisions/{dataset_revision_id}", |
| 18 | + tags=["Dataset Revisions"], |
| 19 | +) |
| 20 | + |
| 21 | +DEFAULT_DATASET_ITEMS_NUMBER_RETURNED = 10 |
| 22 | +MAX_DATASET_ITEMS_NUMBER_RETURNED = 100 |
| 23 | + |
| 24 | + |
| 25 | +@router.get( |
| 26 | + "/items", |
| 27 | + responses={ |
| 28 | + status.HTTP_200_OK: { |
| 29 | + "description": "List of dataset items in the revision", |
| 30 | + "model": DatasetItemsWithPagination, |
| 31 | + }, |
| 32 | + status.HTTP_404_NOT_FOUND: {"description": "Dataset revision or project not found"}, |
| 33 | + }, |
| 34 | +) |
| 35 | +def list_dataset_revision_items( |
| 36 | + _project: Annotated[Project, Depends(get_project)], |
| 37 | + _dataset_service: Annotated[DatasetService, Depends(get_dataset_service)], |
| 38 | + _dataset_revision: Annotated[DatasetRevision, Depends(get_dataset_revision)], |
| 39 | + _limit: Annotated[int, Query(ge=1, le=MAX_DATASET_ITEMS_NUMBER_RETURNED)] = DEFAULT_DATASET_ITEMS_NUMBER_RETURNED, |
| 40 | + _offset: Annotated[int, Query(ge=0)] = 0, |
| 41 | + _subset: Annotated[DatasetItemSubset | None, Query()] = None, |
| 42 | +) -> DatasetItemsWithPagination: |
| 43 | + """List the items in a dataset revision. This endpoint supports pagination.""" |
| 44 | + raise NotImplementedError |
| 45 | + |
| 46 | + |
| 47 | +@router.get( |
| 48 | + "/items/{dataset_item_id}", |
| 49 | + responses={ |
| 50 | + status.HTTP_200_OK: {"description": "Dataset item found", "model": DatasetItemView}, |
| 51 | + status.HTTP_400_BAD_REQUEST: {"description": "Invalid dataset item ID or revision ID"}, |
| 52 | + status.HTTP_404_NOT_FOUND: {"description": "Dataset item, revision, or project not found"}, |
| 53 | + }, |
| 54 | +) |
| 55 | +def get_dataset_revision_item( |
| 56 | + _project: Annotated[Project, Depends(get_project)], |
| 57 | + _dataset_revision: Annotated[DatasetRevision, Depends(get_dataset_revision)], |
| 58 | + _dataset_item_id: DatasetItemID, |
| 59 | + _dataset_service: Annotated[DatasetService, Depends(get_dataset_service)], |
| 60 | +) -> DatasetItemView: |
| 61 | + """Get information about a specific item in the dataset revision""" |
| 62 | + raise NotImplementedError |
| 63 | + |
| 64 | + |
| 65 | +@router.get( |
| 66 | + "/items/{dataset_item_id}/binary", |
| 67 | + responses={ |
| 68 | + status.HTTP_200_OK: {"description": "Dataset item binary found"}, |
| 69 | + status.HTTP_400_BAD_REQUEST: {"description": "Invalid dataset item ID or revision ID"}, |
| 70 | + status.HTTP_404_NOT_FOUND: {"description": "Dataset item, binary, revision, or project not found"}, |
| 71 | + }, |
| 72 | +) |
| 73 | +def get_dataset_revision_item_binary( |
| 74 | + _project: Annotated[Project, Depends(get_project)], |
| 75 | + _dataset_revision: Annotated[DatasetRevision, Depends(get_dataset_revision)], |
| 76 | + _dataset_item_id: DatasetItemID, |
| 77 | + _dataset_service: Annotated[DatasetService, Depends(get_dataset_service)], |
| 78 | +) -> FileResponse: |
| 79 | + """Get the image data of an item in the dataset revision""" |
| 80 | + raise NotImplementedError |
| 81 | + |
| 82 | + |
| 83 | +@router.get( |
| 84 | + "/items/{dataset_item_id}/thumbnail", |
| 85 | + responses={ |
| 86 | + status.HTTP_200_OK: {"description": "Dataset item thumbnail found"}, |
| 87 | + status.HTTP_400_BAD_REQUEST: {"description": "Invalid dataset item ID or revision ID"}, |
| 88 | + status.HTTP_404_NOT_FOUND: {"description": "Dataset item, thumbnail, revision, or project not found"}, |
| 89 | + }, |
| 90 | +) |
| 91 | +def get_dataset_revision_item_thumbnail( |
| 92 | + _project: Annotated[Project, Depends(get_project)], |
| 93 | + _dataset_revision: Annotated[DatasetRevision, Depends(get_dataset_revision)], |
| 94 | + _dataset_item_id: DatasetItemID, |
| 95 | + _dataset_service: Annotated[DatasetService, Depends(get_dataset_service)], |
| 96 | +) -> FileResponse: |
| 97 | + """Get the thumbnail of an item in the dataset revision""" |
| 98 | + raise NotImplementedError |
| 99 | + |
| 100 | + |
| 101 | +@router.delete( |
| 102 | + "", |
| 103 | + status_code=status.HTTP_204_NO_CONTENT, |
| 104 | + responses={ |
| 105 | + status.HTTP_204_NO_CONTENT: {"description": "Dataset revision files deleted"}, |
| 106 | + status.HTTP_400_BAD_REQUEST: {"description": "Invalid revision ID"}, |
| 107 | + status.HTTP_404_NOT_FOUND: {"description": "Dataset revision or project not found"}, |
| 108 | + }, |
| 109 | +) |
| 110 | +def delete_dataset_revision_files( |
| 111 | + project: Annotated[Project, Depends(get_project)], |
| 112 | + dataset_revision_id: DatasetRevisionID, |
| 113 | + _dataset_revision: Annotated[DatasetRevision, Depends(get_dataset_revision)], |
| 114 | + dataset_service: Annotated[DatasetService, Depends(get_dataset_service)], |
| 115 | +) -> None: |
| 116 | + """Delete the files associated with a dataset revision""" |
| 117 | + dataset_service.delete_dataset_revision_files(project_id=project.id, revision_id=dataset_revision_id) |
0 commit comments