Skip to content

Commit

Permalink
add list
Browse files Browse the repository at this point in the history
  • Loading branch information
skyl committed Oct 30, 2024
1 parent 7cb9ca9 commit ff9eae3
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 3 deletions.
1 change: 1 addition & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
echo 'autoload -Uz add-zsh-hook; append_history() { fc -W }; add-zsh-hook precmd append_history; export HISTFILE=/home/vscode/.corpora.zsh_history/.zsh_history' >> ~/.zshrc
echo alias tree="tree -I '.venv|node_modules|__pycache__|.git|.pytest_cache' -a" >> ~/.zshrc
pip install -e /workspace/py/gen/corpora_client
zsh
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# TODO

- corpora_client generated

- prove client works
- auth/auth for API endpoints, Corpus ownership
- CLI that hits API
- API spec, generation (?)
- play with models in admin and management commands with direct DB access

# Next

Expand Down
1 change: 1 addition & 0 deletions py/gen/corpora_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Class | Method | HTTP request | Description
*CorporaApi* | [**corpora_api_create_file**](docs/CorporaApi.md#corpora_api_create_file) | **POST** /api/corpora/file | Create File
*CorporaApi* | [**corpora_api_get_corpus**](docs/CorporaApi.md#corpora_api_get_corpus) | **GET** /api/corpora/corpus/{corpus_id} | Get Corpus
*CorporaApi* | [**corpora_api_get_file**](docs/CorporaApi.md#corpora_api_get_file) | **GET** /api/corpora/file/{file_id} | Get File
*CorporaApi* | [**corpora_api_list_corpora**](docs/CorporaApi.md#corpora_api_list_corpora) | **GET** /api/corpora/corpus | List Corpora


## Documentation For Models
Expand Down
228 changes: 228 additions & 0 deletions py/gen/corpora_client/corpora_client/api/corpora_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing_extensions import Annotated

from pydantic import StrictStr
from typing import List
from corpora_client.models.corpus_response_schema import CorpusResponseSchema
from corpora_client.models.corpus_schema import CorpusSchema
from corpora_client.models.file_response_schema import FileResponseSchema
Expand Down Expand Up @@ -1026,3 +1027,230 @@ def _corpora_api_get_file_serialize(
_host=_host,
_request_auth=_request_auth,
)

@validate_call
async def corpora_api_list_corpora(
self,
_request_timeout: Union[
None,
Annotated[StrictFloat, Field(gt=0)],
Tuple[
Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
],
] = None,
_request_auth: Optional[Dict[StrictStr, Any]] = None,
_content_type: Optional[StrictStr] = None,
_headers: Optional[Dict[StrictStr, Any]] = None,
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
) -> List[CorpusResponseSchema]:
"""List Corpora
List all Corpora.
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:type _request_timeout: int, tuple(int, int), optional
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the
authentication in the spec for a single request.
:type _request_auth: dict, optional
:param _content_type: force content-type for the request.
:type _content_type: str, Optional
:param _headers: set to override the headers for a single
request; this effectively ignores the headers
in the spec for a single request.
:type _headers: dict, optional
:param _host_index: set to override the host_index for a single
request; this effectively ignores the host_index
in the spec for a single request.
:type _host_index: int, optional
:return: Returns the result object.
""" # noqa: E501

_param = self._corpora_api_list_corpora_serialize(
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index,
)

_response_types_map: Dict[str, Optional[str]] = {
"200": "List[CorpusResponseSchema]",
}
response_data = await self.api_client.call_api(
*_param, _request_timeout=_request_timeout
)
await response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
).data

@validate_call
async def corpora_api_list_corpora_with_http_info(
self,
_request_timeout: Union[
None,
Annotated[StrictFloat, Field(gt=0)],
Tuple[
Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
],
] = None,
_request_auth: Optional[Dict[StrictStr, Any]] = None,
_content_type: Optional[StrictStr] = None,
_headers: Optional[Dict[StrictStr, Any]] = None,
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
) -> ApiResponse[List[CorpusResponseSchema]]:
"""List Corpora
List all Corpora.
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:type _request_timeout: int, tuple(int, int), optional
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the
authentication in the spec for a single request.
:type _request_auth: dict, optional
:param _content_type: force content-type for the request.
:type _content_type: str, Optional
:param _headers: set to override the headers for a single
request; this effectively ignores the headers
in the spec for a single request.
:type _headers: dict, optional
:param _host_index: set to override the host_index for a single
request; this effectively ignores the host_index
in the spec for a single request.
:type _host_index: int, optional
:return: Returns the result object.
""" # noqa: E501

_param = self._corpora_api_list_corpora_serialize(
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index,
)

_response_types_map: Dict[str, Optional[str]] = {
"200": "List[CorpusResponseSchema]",
}
response_data = await self.api_client.call_api(
*_param, _request_timeout=_request_timeout
)
await response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
)

@validate_call
async def corpora_api_list_corpora_without_preload_content(
self,
_request_timeout: Union[
None,
Annotated[StrictFloat, Field(gt=0)],
Tuple[
Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
],
] = None,
_request_auth: Optional[Dict[StrictStr, Any]] = None,
_content_type: Optional[StrictStr] = None,
_headers: Optional[Dict[StrictStr, Any]] = None,
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
) -> RESTResponseType:
"""List Corpora
List all Corpora.
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:type _request_timeout: int, tuple(int, int), optional
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the
authentication in the spec for a single request.
:type _request_auth: dict, optional
:param _content_type: force content-type for the request.
:type _content_type: str, Optional
:param _headers: set to override the headers for a single
request; this effectively ignores the headers
in the spec for a single request.
:type _headers: dict, optional
:param _host_index: set to override the host_index for a single
request; this effectively ignores the host_index
in the spec for a single request.
:type _host_index: int, optional
:return: Returns the result object.
""" # noqa: E501

_param = self._corpora_api_list_corpora_serialize(
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index,
)

_response_types_map: Dict[str, Optional[str]] = {
"200": "List[CorpusResponseSchema]",
}
response_data = await self.api_client.call_api(
*_param, _request_timeout=_request_timeout
)
return response_data.response

def _corpora_api_list_corpora_serialize(
self,
_request_auth,
_content_type,
_headers,
_host_index,
) -> RequestSerialized:

_host = None

_collection_formats: Dict[str, str] = {}

_path_params: Dict[str, str] = {}
_query_params: List[Tuple[str, str]] = []
_header_params: Dict[str, Optional[str]] = _headers or {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[
str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]]
] = {}
_body_params: Optional[bytes] = None

# process the path parameters
# process the query parameters
# process the header parameters
# process the form parameters
# process the body parameter

# set the HTTP header `Accept`
if "Accept" not in _header_params:
_header_params["Accept"] = self.api_client.select_header_accept(
["application/json"]
)

# authentication setting
_auth_settings: List[str] = ["BearerAuth"]

return self.api_client.param_serialize(
method="GET",
resource_path="/api/corpora/corpus",
path_params=_path_params,
query_params=_query_params,
header_params=_header_params,
body=_body_params,
post_params=_form_params,
files=_files,
auth_settings=_auth_settings,
collection_formats=_collection_formats,
_host=_host,
_request_auth=_request_auth,
)
75 changes: 75 additions & 0 deletions py/gen/corpora_client/docs/CorporaApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Method | HTTP request | Description
[**corpora_api_create_file**](CorporaApi.md#corpora_api_create_file) | **POST** /api/corpora/file | Create File
[**corpora_api_get_corpus**](CorporaApi.md#corpora_api_get_corpus) | **GET** /api/corpora/corpus/{corpus_id} | Get Corpus
[**corpora_api_get_file**](CorporaApi.md#corpora_api_get_file) | **GET** /api/corpora/file/{file_id} | Get File
[**corpora_api_list_corpora**](CorporaApi.md#corpora_api_list_corpora) | **GET** /api/corpora/corpus | List Corpora


# **corpora_api_create_corpus**
Expand Down Expand Up @@ -324,3 +325,77 @@ Name | Type | Description | Notes

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **corpora_api_list_corpora**
> List[CorpusResponseSchema] corpora_api_list_corpora()
List Corpora

List all Corpora.

### Example

* Bearer Authentication (BearerAuth):

```python
import corpora_client
from corpora_client.models.corpus_response_schema import CorpusResponseSchema
from corpora_client.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to http://localhost
# See configuration.py for a list of all supported configuration parameters.
configuration = corpora_client.Configuration(
host = "http://localhost"
)

# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = corpora_client.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

# Enter a context with an instance of the API client
async with corpora_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = corpora_client.CorporaApi(api_client)

try:
# List Corpora
api_response = await api_instance.corpora_api_list_corpora()
print("The response of CorporaApi->corpora_api_list_corpora:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling CorporaApi->corpora_api_list_corpora: %s\n" % e)
```



### Parameters

This endpoint does not need any parameter.

### Return type

[**List[CorpusResponseSchema]**](CorpusResponseSchema.md)

### Authorization

[BearerAuth](../README.md#BearerAuth)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

### HTTP response details

| Status code | Description | Response headers |
|-------------|-------------|------------------|
**200** | OK | - |

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

7 changes: 7 additions & 0 deletions py/gen/corpora_client/test/test_corpora_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ async def test_corpora_api_get_file(self) -> None:
"""
pass

async def test_corpora_api_list_corpora(self) -> None:
"""Test case for corpora_api_list_corpora
List Corpora
"""
pass


if __name__ == "__main__":
unittest.main()
10 changes: 10 additions & 0 deletions py/packages/corpora/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import List
import uuid

# from ninja import NinjaAPI
from ninja import Router
from asgiref.sync import sync_to_async

from .lib.files import calculate_checksum
from .lib.dj.decorators import async_raise_not_found
Expand All @@ -21,6 +23,14 @@ async def create_corpus(request, payload: CorpusSchema):
return corpus


@api.get("/corpus", response={200: List[CorpusResponseSchema]})
async def list_corpora(request):
"""List all Corpora."""
# TODO .. pagination .. ?
corpora = await sync_to_async(list)(Corpus.objects.filter(owner=request.user))
return corpora


@api.get("/corpus/{corpus_id}", response=CorpusResponseSchema)
@async_raise_not_found
async def get_corpus(request, corpus_id: uuid.UUID):
Expand Down
Loading

0 comments on commit ff9eae3

Please sign in to comment.