Skip to content

Commit 82b9fbe

Browse files
authored
Merge pull request #113 from doccano/feature/filter-example-by-confirmation-state
Enable to filter examples by confirmation state
2 parents 6933ad6 + 72f6c58 commit 82b9fbe

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

doccano_client/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,17 @@ def upload_label_type(self, project_id: int, file_path: str, type: Literal["cate
526526
"""
527527
self._get_label_type_usecase(type).upload(project_id, file_path)
528528

529-
def list_examples(self, project_id: int) -> Iterator[Example]:
529+
def list_examples(self, project_id: int, is_confirmed: Optional[bool] = None) -> Iterator[Example]:
530530
"""Return all examples.
531531
532532
Args:
533533
project_id (int): The id of the project.
534+
is_confirmed (bool, optional): Filter by confirmed state. Defaults to None.
534535
535536
Yields:
536537
Example: The examples in the project.
537538
"""
538-
yield from self.example.list(project_id)
539+
yield from self.example.list(project_id, is_confirmed)
539540

540541
def find_example_by_id(self, project_id: int, example_id: int) -> Example:
541542
"""Find an example by id.

doccano_client/repositories/example.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Iterator, List
3+
from typing import Iterator, List, Optional
44

55
from doccano_client.models.example import Example
66
from doccano_client.repositories.base import BaseRepository
@@ -37,16 +37,20 @@ def count(self, project_id: int) -> int:
3737
response = self._client.get(f"projects/{project_id}/examples")
3838
return response.json()["count"]
3939

40-
def list(self, project_id: int) -> Iterator[Example]:
40+
def list(self, project_id: int, is_confirmed: Optional[bool] = None) -> Iterator[Example]:
4141
"""Return all examples in which you are a member
4242
4343
Args:
4444
project_id (int): The id of the project
45+
is_confirmed (bool, optional): Filter by confirmed state. Defaults to None.
4546
4647
Yields:
4748
Example: The next example.
4849
"""
49-
response = self._client.get(f"projects/{project_id}/examples")
50+
params = {}
51+
if is_confirmed is not None:
52+
params["confirmed"] = is_confirmed
53+
response = self._client.get(f"projects/{project_id}/examples", params=params)
5054

5155
while True:
5256
examples = response.json()

doccano_client/usecase/example.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Iterator, List
1+
from typing import Any, Dict, Iterator, List, Optional
22

33
from doccano_client.models.example import Example
44
from doccano_client.repositories.example import ExampleRepository
@@ -31,16 +31,17 @@ def count(self, project_id: int) -> int:
3131
"""
3232
return self._repository.count(project_id)
3333

34-
def list(self, project_id: int) -> Iterator[Example]:
34+
def list(self, project_id: int, is_confirmed: Optional[bool] = None) -> Iterator[Example]:
3535
"""Return all examples
3636
3737
Args:
3838
project_id (int): The id of the project
39+
is_confirmed (bool, optional): Filter by confirmed state. Defaults to None.
3940
4041
Yields:
4142
Example: The examples in the project.
4243
"""
43-
yield from self._repository.list(project_id)
44+
yield from self._repository.list(project_id, is_confirmed)
4445

4546
def create(
4647
self,

tests/unit/usecase/test_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_find_by_id(self):
2525

2626
def test_list(self):
2727
list(self.usecase.list(0))
28-
self.repository.list.assert_called_once_with(0)
28+
self.repository.list.assert_called_once_with(0, None)
2929

3030
def test_create(self, payload):
3131
project_id = 0

0 commit comments

Comments
 (0)