documente_shared 0.1.72b0__py3-none-any.whl → 0.1.74__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of documente_shared might be problematic. Click here for more details.
- documente_shared/__init__.py +0 -0
- documente_shared/application/__init__.py +0 -0
- documente_shared/application/digest.py +7 -7
- documente_shared/application/exceptions.py +23 -23
- documente_shared/application/files.py +22 -22
- documente_shared/application/query_params.py +129 -0
- documente_shared/application/time_utils.py +13 -13
- documente_shared/application/timezone.py +7 -7
- documente_shared/domain/__init__.py +0 -0
- documente_shared/domain/base_enum.py +53 -53
- documente_shared/domain/constants.py +8 -3
- documente_shared/domain/entities/__init__.py +0 -0
- documente_shared/domain/entities/document.py +348 -348
- documente_shared/domain/entities/document_metadata.py +63 -63
- documente_shared/domain/entities/in_memory_result.py +51 -51
- documente_shared/domain/entities/processing_case.py +145 -144
- documente_shared/domain/entities/processing_case_filters.py +48 -0
- documente_shared/domain/entities/processing_case_item.py +216 -216
- documente_shared/domain/entities/processing_case_item_filters.py +51 -0
- documente_shared/domain/entities/processing_event.py +49 -49
- documente_shared/domain/enums/__init__.py +0 -0
- documente_shared/domain/enums/common.py +95 -95
- documente_shared/domain/enums/document.py +71 -71
- documente_shared/domain/enums/processing_case.py +55 -54
- documente_shared/domain/repositories/__init__.py +0 -0
- documente_shared/domain/repositories/document.py +24 -24
- documente_shared/domain/repositories/processing_case.py +24 -24
- documente_shared/domain/repositories/processing_case_item.py +25 -29
- documente_shared/infrastructure/__init__.py +0 -0
- documente_shared/infrastructure/documente_client.py +20 -20
- documente_shared/infrastructure/dynamo_table.py +75 -75
- documente_shared/infrastructure/repositories/__init__.py +0 -0
- documente_shared/infrastructure/repositories/dynamo_document.py +43 -43
- documente_shared/infrastructure/repositories/dynamo_processing_case.py +43 -43
- documente_shared/infrastructure/repositories/dynamo_processing_case_item.py +43 -54
- documente_shared/infrastructure/repositories/http_processing_case.py +41 -40
- documente_shared/infrastructure/repositories/http_processing_case_item.py +43 -53
- documente_shared/infrastructure/s3_bucket.py +57 -57
- documente_shared/infrastructure/sqs_queue.py +47 -47
- {documente_shared-0.1.72b0.dist-info → documente_shared-0.1.74.dist-info}/METADATA +1 -1
- documente_shared-0.1.74.dist-info/RECORD +42 -0
- documente_shared/infrastructure/repositories/http_document_processing.py +0 -41
- documente_shared-0.1.72b0.dist-info/RECORD +0 -40
- {documente_shared-0.1.72b0.dist-info → documente_shared-0.1.74.dist-info}/WHEEL +0 -0
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import boto3
|
|
2
|
-
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
from boto3.dynamodb.conditions import Key
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
RETURN_VALUES = 'UPDATED_NEW'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@dataclass
|
|
11
|
-
class DynamoDBTable(object):
|
|
12
|
-
table_name: str
|
|
13
|
-
|
|
14
|
-
def __post_init__(self):
|
|
15
|
-
self._table = boto3.resource('dynamodb').Table(self.table_name)
|
|
16
|
-
|
|
17
|
-
def get(self, key: dict):
|
|
18
|
-
return self._table.get_item(Key=key).get('Item')
|
|
19
|
-
|
|
20
|
-
def get_all(self):
|
|
21
|
-
return self._table.scan().get('Items')
|
|
22
|
-
|
|
23
|
-
def upsert(self, key, attributes):
|
|
24
|
-
return self.put({**key, **attributes})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def filter_by(self, attribute: str, target_value: str):
|
|
28
|
-
return self._table.query(
|
|
29
|
-
FilterExpression=Key(attribute).eq(target_value),
|
|
30
|
-
).get('Items')
|
|
31
|
-
|
|
32
|
-
def put(self, attributes: dict, condition: dict = None):
|
|
33
|
-
extra_args = {}
|
|
34
|
-
if condition:
|
|
35
|
-
extra_args['ConditionExpression'] = condition
|
|
36
|
-
return self._table.put_item(Item=attributes, **extra_args)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def update(self, key: str, attributes: dict):
|
|
40
|
-
return self._table.update_item(
|
|
41
|
-
Key=key,
|
|
42
|
-
UpdateExpression=self._update_expression(attributes),
|
|
43
|
-
ExpressionAttributeNames=self._expression_attribute_names(attributes),
|
|
44
|
-
ExpressionAttributeValues=self._expression_attribute_values(attributes),
|
|
45
|
-
ReturnValues=RETURN_VALUES,
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
def delete(self, key: dict):
|
|
49
|
-
return self._table.delete_item(Key=key)
|
|
50
|
-
|
|
51
|
-
def count(self) -> int:
|
|
52
|
-
return self._table.item_count
|
|
53
|
-
|
|
54
|
-
@classmethod
|
|
55
|
-
def _update_expression(cls, attributes):
|
|
56
|
-
return 'SET {param}'.format(
|
|
57
|
-
param=','.join(
|
|
58
|
-
'#{key}=:{key}'.format(
|
|
59
|
-
key=key,
|
|
60
|
-
)
|
|
61
|
-
for key in attributes
|
|
62
|
-
),
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
@classmethod
|
|
66
|
-
def _expression_attribute_names(cls, attributes):
|
|
67
|
-
return {
|
|
68
|
-
'#{key}'.format(key=key): key for key in attributes
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@classmethod
|
|
72
|
-
def _expression_attribute_values(cls, attributes):
|
|
73
|
-
return {
|
|
74
|
-
':{key}'.format(key=key): attr for key, attr in attributes.items()
|
|
75
|
-
}
|
|
1
|
+
import boto3
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from boto3.dynamodb.conditions import Key
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
RETURN_VALUES = 'UPDATED_NEW'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class DynamoDBTable(object):
|
|
12
|
+
table_name: str
|
|
13
|
+
|
|
14
|
+
def __post_init__(self):
|
|
15
|
+
self._table = boto3.resource('dynamodb').Table(self.table_name)
|
|
16
|
+
|
|
17
|
+
def get(self, key: dict):
|
|
18
|
+
return self._table.get_item(Key=key).get('Item')
|
|
19
|
+
|
|
20
|
+
def get_all(self):
|
|
21
|
+
return self._table.scan().get('Items')
|
|
22
|
+
|
|
23
|
+
def upsert(self, key, attributes):
|
|
24
|
+
return self.put({**key, **attributes})
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def filter_by(self, attribute: str, target_value: str):
|
|
28
|
+
return self._table.query(
|
|
29
|
+
FilterExpression=Key(attribute).eq(target_value),
|
|
30
|
+
).get('Items')
|
|
31
|
+
|
|
32
|
+
def put(self, attributes: dict, condition: dict = None):
|
|
33
|
+
extra_args = {}
|
|
34
|
+
if condition:
|
|
35
|
+
extra_args['ConditionExpression'] = condition
|
|
36
|
+
return self._table.put_item(Item=attributes, **extra_args)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def update(self, key: str, attributes: dict):
|
|
40
|
+
return self._table.update_item(
|
|
41
|
+
Key=key,
|
|
42
|
+
UpdateExpression=self._update_expression(attributes),
|
|
43
|
+
ExpressionAttributeNames=self._expression_attribute_names(attributes),
|
|
44
|
+
ExpressionAttributeValues=self._expression_attribute_values(attributes),
|
|
45
|
+
ReturnValues=RETURN_VALUES,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def delete(self, key: dict):
|
|
49
|
+
return self._table.delete_item(Key=key)
|
|
50
|
+
|
|
51
|
+
def count(self) -> int:
|
|
52
|
+
return self._table.item_count
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def _update_expression(cls, attributes):
|
|
56
|
+
return 'SET {param}'.format(
|
|
57
|
+
param=','.join(
|
|
58
|
+
'#{key}=:{key}'.format(
|
|
59
|
+
key=key,
|
|
60
|
+
)
|
|
61
|
+
for key in attributes
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def _expression_attribute_names(cls, attributes):
|
|
67
|
+
return {
|
|
68
|
+
'#{key}'.format(key=key): key for key in attributes
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def _expression_attribute_values(cls, attributes):
|
|
73
|
+
return {
|
|
74
|
+
':{key}'.format(key=key): attr for key, attr in attributes.items()
|
|
75
|
+
}
|
|
File without changes
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
from typing import Optional, List
|
|
2
|
-
|
|
3
|
-
from boto3.dynamodb.conditions import Key
|
|
4
|
-
|
|
5
|
-
from documente_shared.domain.entities.document import DocumentProcessing
|
|
6
|
-
from documente_shared.domain.enums.document import DocumentProcessingStatus
|
|
7
|
-
from documente_shared.domain.repositories.document import DocumentProcessingRepository
|
|
8
|
-
|
|
9
|
-
from documente_shared.infrastructure.dynamo_table import DynamoDBTable
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class DynamoDocumentProcessingRepository(
|
|
13
|
-
DynamoDBTable,
|
|
14
|
-
DocumentProcessingRepository,
|
|
15
|
-
):
|
|
16
|
-
def find(self, digest: str) -> Optional[DocumentProcessing]:
|
|
17
|
-
item = self.get(key={'digest': digest})
|
|
18
|
-
if item:
|
|
19
|
-
return DocumentProcessing.from_dict(item)
|
|
20
|
-
return None
|
|
21
|
-
|
|
22
|
-
def persist(self, instance: DocumentProcessing) -> DocumentProcessing:
|
|
23
|
-
self.put(instance.to_simple_dict)
|
|
24
|
-
return instance
|
|
25
|
-
|
|
26
|
-
def remove(self, instance: DocumentProcessing):
|
|
27
|
-
self.delete(key={'digest': instance.digest})
|
|
28
|
-
|
|
29
|
-
def filter(self, statuses: List[DocumentProcessingStatus]) -> List[DocumentProcessing]:
|
|
30
|
-
items = []
|
|
31
|
-
|
|
32
|
-
for status in statuses:
|
|
33
|
-
response = self._table.query(
|
|
34
|
-
IndexName='status',
|
|
35
|
-
KeyConditionExpression=Key('status').eq(status.value),
|
|
36
|
-
)
|
|
37
|
-
status_items = response.get('Items', [])
|
|
38
|
-
items.extend(status_items)
|
|
39
|
-
|
|
40
|
-
return [
|
|
41
|
-
DocumentProcessing.from_dict(item)
|
|
42
|
-
for item in items
|
|
43
|
-
]
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
|
|
3
|
+
from boto3.dynamodb.conditions import Key
|
|
4
|
+
|
|
5
|
+
from documente_shared.domain.entities.document import DocumentProcessing
|
|
6
|
+
from documente_shared.domain.enums.document import DocumentProcessingStatus
|
|
7
|
+
from documente_shared.domain.repositories.document import DocumentProcessingRepository
|
|
8
|
+
|
|
9
|
+
from documente_shared.infrastructure.dynamo_table import DynamoDBTable
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DynamoDocumentProcessingRepository(
|
|
13
|
+
DynamoDBTable,
|
|
14
|
+
DocumentProcessingRepository,
|
|
15
|
+
):
|
|
16
|
+
def find(self, digest: str) -> Optional[DocumentProcessing]:
|
|
17
|
+
item = self.get(key={'digest': digest})
|
|
18
|
+
if item:
|
|
19
|
+
return DocumentProcessing.from_dict(item)
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
def persist(self, instance: DocumentProcessing) -> DocumentProcessing:
|
|
23
|
+
self.put(instance.to_simple_dict)
|
|
24
|
+
return instance
|
|
25
|
+
|
|
26
|
+
def remove(self, instance: DocumentProcessing):
|
|
27
|
+
self.delete(key={'digest': instance.digest})
|
|
28
|
+
|
|
29
|
+
def filter(self, statuses: List[DocumentProcessingStatus]) -> List[DocumentProcessing]:
|
|
30
|
+
items = []
|
|
31
|
+
|
|
32
|
+
for status in statuses:
|
|
33
|
+
response = self._table.query(
|
|
34
|
+
IndexName='status',
|
|
35
|
+
KeyConditionExpression=Key('status').eq(status.value),
|
|
36
|
+
)
|
|
37
|
+
status_items = response.get('Items', [])
|
|
38
|
+
items.extend(status_items)
|
|
39
|
+
|
|
40
|
+
return [
|
|
41
|
+
DocumentProcessing.from_dict(item)
|
|
42
|
+
for item in items
|
|
43
|
+
]
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
from typing import Optional, List
|
|
2
|
-
|
|
3
|
-
from boto3.dynamodb.conditions import Key
|
|
4
|
-
|
|
5
|
-
from documente_shared.domain.entities.processing_case import ProcessingCase
|
|
6
|
-
from documente_shared.domain.enums.common import ProcessingStatus
|
|
7
|
-
from documente_shared.domain.repositories.processing_case import ProcessingCaseRepository
|
|
8
|
-
|
|
9
|
-
from documente_shared.infrastructure.dynamo_table import DynamoDBTable
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class DynamoProcessingCaseRepository(
|
|
13
|
-
DynamoDBTable,
|
|
14
|
-
ProcessingCaseRepository,
|
|
15
|
-
):
|
|
16
|
-
def find(self,
|
|
17
|
-
item = self.get(key={'
|
|
18
|
-
if item:
|
|
19
|
-
return ProcessingCase.from_dict(item)
|
|
20
|
-
return None
|
|
21
|
-
|
|
22
|
-
def persist(self, instance: ProcessingCase) -> ProcessingCase:
|
|
23
|
-
self.put(instance.to_persist_dict)
|
|
24
|
-
return instance
|
|
25
|
-
|
|
26
|
-
def remove(self, instance: ProcessingCase):
|
|
27
|
-
self.delete(key={'
|
|
28
|
-
|
|
29
|
-
def filter(self, statuses: List[ProcessingStatus]) -> List[ProcessingCase]:
|
|
30
|
-
items = []
|
|
31
|
-
|
|
32
|
-
for status in statuses:
|
|
33
|
-
response = self._table.query(
|
|
34
|
-
IndexName='status',
|
|
35
|
-
KeyConditionExpression=Key('status').eq(status.value),
|
|
36
|
-
)
|
|
37
|
-
status_items = response.get('Items', [])
|
|
38
|
-
items.extend(status_items)
|
|
39
|
-
|
|
40
|
-
return [
|
|
41
|
-
ProcessingCase.from_dict(item)
|
|
42
|
-
for item in items
|
|
43
|
-
]
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
|
|
3
|
+
from boto3.dynamodb.conditions import Key
|
|
4
|
+
|
|
5
|
+
from documente_shared.domain.entities.processing_case import ProcessingCase
|
|
6
|
+
from documente_shared.domain.enums.common import ProcessingStatus
|
|
7
|
+
from documente_shared.domain.repositories.processing_case import ProcessingCaseRepository
|
|
8
|
+
|
|
9
|
+
from documente_shared.infrastructure.dynamo_table import DynamoDBTable
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DynamoProcessingCaseRepository(
|
|
13
|
+
DynamoDBTable,
|
|
14
|
+
ProcessingCaseRepository,
|
|
15
|
+
):
|
|
16
|
+
def find(self, uuid: str) -> Optional[ProcessingCase]:
|
|
17
|
+
item = self.get(key={'uuid': uuid})
|
|
18
|
+
if item:
|
|
19
|
+
return ProcessingCase.from_dict(item)
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
def persist(self, instance: ProcessingCase) -> ProcessingCase:
|
|
23
|
+
self.put(instance.to_persist_dict)
|
|
24
|
+
return instance
|
|
25
|
+
|
|
26
|
+
def remove(self, instance: ProcessingCase):
|
|
27
|
+
self.delete(key={'uuid': instance.uuid})
|
|
28
|
+
|
|
29
|
+
def filter(self, statuses: List[ProcessingStatus]) -> List[ProcessingCase]:
|
|
30
|
+
items = []
|
|
31
|
+
|
|
32
|
+
for status in statuses:
|
|
33
|
+
response = self._table.query(
|
|
34
|
+
IndexName='status',
|
|
35
|
+
KeyConditionExpression=Key('status').eq(status.value),
|
|
36
|
+
)
|
|
37
|
+
status_items = response.get('Items', [])
|
|
38
|
+
items.extend(status_items)
|
|
39
|
+
|
|
40
|
+
return [
|
|
41
|
+
ProcessingCase.from_dict(item)
|
|
42
|
+
for item in items
|
|
43
|
+
]
|
|
@@ -1,54 +1,43 @@
|
|
|
1
|
-
from typing import Optional, List
|
|
2
|
-
|
|
3
|
-
from boto3.dynamodb.conditions import Key
|
|
4
|
-
|
|
5
|
-
from documente_shared.domain.entities.processing_case_item import ProcessingCaseItem
|
|
6
|
-
from documente_shared.domain.enums.common import ProcessingStatus
|
|
7
|
-
from documente_shared.domain.repositories.processing_case_item import ProcessingCaseItemRepository
|
|
8
|
-
|
|
9
|
-
from documente_shared.infrastructure.dynamo_table import DynamoDBTable
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class DynamoProcessingCaseItemRepository(
|
|
13
|
-
DynamoDBTable,
|
|
14
|
-
ProcessingCaseItemRepository,
|
|
15
|
-
):
|
|
16
|
-
def find(self, uuid: str) -> Optional[ProcessingCaseItem]:
|
|
17
|
-
item = self.get(key={'digest': uuid})
|
|
18
|
-
if item:
|
|
19
|
-
return ProcessingCaseItem.from_dict(item)
|
|
20
|
-
return None
|
|
21
|
-
|
|
22
|
-
def persist(self, instance: ProcessingCaseItem) -> ProcessingCaseItem:
|
|
23
|
-
self.put(instance.to_simple_dict)
|
|
24
|
-
return instance
|
|
25
|
-
|
|
26
|
-
def remove(self, instance: ProcessingCaseItem):
|
|
27
|
-
self.delete(key={'case_id': instance.case_id})
|
|
28
|
-
|
|
29
|
-
def filter(self, statuses: List[ProcessingStatus]) -> List[ProcessingCaseItem]:
|
|
30
|
-
items = []
|
|
31
|
-
|
|
32
|
-
for status in statuses:
|
|
33
|
-
response = self._table.query(
|
|
34
|
-
IndexName='status',
|
|
35
|
-
KeyConditionExpression=Key('status').eq(status.value),
|
|
36
|
-
)
|
|
37
|
-
status_items = response.get('Items', [])
|
|
38
|
-
items.extend(status_items)
|
|
39
|
-
|
|
40
|
-
return [
|
|
41
|
-
ProcessingCaseItem.from_dict(item)
|
|
42
|
-
for item in items
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
def filter_by_case_id(self, case_id: str) -> List[ProcessingCaseItem]:
|
|
46
|
-
response = self._table.query(
|
|
47
|
-
IndexName='case_id',
|
|
48
|
-
KeyConditionExpression=Key('case_id').eq(case_id),
|
|
49
|
-
)
|
|
50
|
-
items = response.get('Items', [])
|
|
51
|
-
return [
|
|
52
|
-
ProcessingCaseItem.from_dict(item)
|
|
53
|
-
for item in items
|
|
54
|
-
]
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
|
|
3
|
+
from boto3.dynamodb.conditions import Key
|
|
4
|
+
|
|
5
|
+
from documente_shared.domain.entities.processing_case_item import ProcessingCaseItem
|
|
6
|
+
from documente_shared.domain.enums.common import ProcessingStatus
|
|
7
|
+
from documente_shared.domain.repositories.processing_case_item import ProcessingCaseItemRepository
|
|
8
|
+
|
|
9
|
+
from documente_shared.infrastructure.dynamo_table import DynamoDBTable
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DynamoProcessingCaseItemRepository(
|
|
13
|
+
DynamoDBTable,
|
|
14
|
+
ProcessingCaseItemRepository,
|
|
15
|
+
):
|
|
16
|
+
def find(self, uuid: str) -> Optional[ProcessingCaseItem]:
|
|
17
|
+
item = self.get(key={'digest': uuid})
|
|
18
|
+
if item:
|
|
19
|
+
return ProcessingCaseItem.from_dict(item)
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
def persist(self, instance: ProcessingCaseItem) -> ProcessingCaseItem:
|
|
23
|
+
self.put(instance.to_simple_dict)
|
|
24
|
+
return instance
|
|
25
|
+
|
|
26
|
+
def remove(self, instance: ProcessingCaseItem):
|
|
27
|
+
self.delete(key={'case_id': instance.case_id})
|
|
28
|
+
|
|
29
|
+
def filter(self, statuses: List[ProcessingStatus]) -> List[ProcessingCaseItem]:
|
|
30
|
+
items = []
|
|
31
|
+
|
|
32
|
+
for status in statuses:
|
|
33
|
+
response = self._table.query(
|
|
34
|
+
IndexName='status',
|
|
35
|
+
KeyConditionExpression=Key('status').eq(status.value),
|
|
36
|
+
)
|
|
37
|
+
status_items = response.get('Items', [])
|
|
38
|
+
items.extend(status_items)
|
|
39
|
+
|
|
40
|
+
return [
|
|
41
|
+
ProcessingCaseItem.from_dict(item)
|
|
42
|
+
for item in items
|
|
43
|
+
]
|
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from typing import List, Optional
|
|
3
|
-
|
|
4
|
-
from documente_shared.domain.entities.processing_case import ProcessingCase
|
|
5
|
-
from documente_shared.domain.
|
|
6
|
-
from documente_shared.domain.
|
|
7
|
-
from documente_shared.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
|
|
4
|
+
from documente_shared.domain.entities.processing_case import ProcessingCase
|
|
5
|
+
from documente_shared.domain.entities.processing_case_filters import ProcessingCaseFilters
|
|
6
|
+
from documente_shared.domain.enums.common import ProcessingStatus
|
|
7
|
+
from documente_shared.domain.repositories.processing_case import ProcessingCaseRepository
|
|
8
|
+
from documente_shared.infrastructure.documente_client import DocumenteClientMixin
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class HttpProcessingCaseRepository(
|
|
13
|
+
DocumenteClientMixin,
|
|
14
|
+
ProcessingCaseRepository,
|
|
15
|
+
):
|
|
16
|
+
def find(self, uuid: str) -> Optional[ProcessingCase]:
|
|
17
|
+
response = self.session.get(f"{self.api_url}/processing-cases/{uuid}/")
|
|
18
|
+
if response.status_code == 200:
|
|
19
|
+
return ProcessingCase.from_dict(response.json())
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
def persist(self, instance: ProcessingCase) -> ProcessingCase:
|
|
23
|
+
response = self.session.put(
|
|
24
|
+
url=f"{self.api_url}/processing-cases/{instance.uuid}/",
|
|
25
|
+
json=instance.to_dict,
|
|
26
|
+
)
|
|
27
|
+
if response.status_code not in [200, 201]:
|
|
28
|
+
raise Exception(f'Error persisting processing case: {response.text}')
|
|
29
|
+
return ProcessingCase.from_dict(response.json())
|
|
30
|
+
|
|
31
|
+
def remove(self, instance: ProcessingCase):
|
|
32
|
+
self.session.delete(f"{self.api_url}/processing-cases/{instance.uuid}/")
|
|
33
|
+
|
|
34
|
+
def filter(self, filters: ProcessingCaseFilters) -> List[ProcessingCase]:
|
|
35
|
+
response = self.session.get(f"{self.api_url}/processing-cases/")
|
|
36
|
+
if response.status_code == 200:
|
|
37
|
+
raw_response = response.json()
|
|
38
|
+
return [
|
|
39
|
+
ProcessingCase.from_dict(item)
|
|
40
|
+
for item in raw_response.get('data', [])
|
|
41
|
+
]
|
|
41
42
|
return []
|
|
@@ -1,53 +1,43 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from typing import List, Optional
|
|
3
|
-
|
|
4
|
-
from documente_shared.domain.entities.processing_case import ProcessingCase
|
|
5
|
-
from documente_shared.domain.entities.processing_case_item import ProcessingCaseItem
|
|
6
|
-
from documente_shared.domain.enums.common import ProcessingStatus
|
|
7
|
-
from documente_shared.domain.repositories.processing_case_item import ProcessingCaseItemRepository
|
|
8
|
-
from documente_shared.infrastructure.documente_client import DocumenteClientMixin
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@dataclass
|
|
12
|
-
class HttpProcessingCaseItemRepository(
|
|
13
|
-
DocumenteClientMixin,
|
|
14
|
-
ProcessingCaseItemRepository,
|
|
15
|
-
):
|
|
16
|
-
|
|
17
|
-
def find(self, uuid: str) -> Optional[ProcessingCaseItem]:
|
|
18
|
-
response = self.session.get(f"{self.
|
|
19
|
-
if response.status_code == 200:
|
|
20
|
-
return ProcessingCaseItem.from_dict(response.json())
|
|
21
|
-
return None
|
|
22
|
-
|
|
23
|
-
def persist(self, instance: ProcessingCaseItem) -> ProcessingCaseItem:
|
|
24
|
-
response = self.session.put(
|
|
25
|
-
url=f"{self.
|
|
26
|
-
json=instance.to_simple_dict,
|
|
27
|
-
)
|
|
28
|
-
if response.status_code in [200, 201]:
|
|
29
|
-
return ProcessingCaseItem.from_dict(response.json())
|
|
30
|
-
return instance
|
|
31
|
-
|
|
32
|
-
def remove(self, instance: ProcessingCaseItem):
|
|
33
|
-
self.session.delete(f"{self.
|
|
34
|
-
|
|
35
|
-
def filter(self, statuses: List[ProcessingStatus]) -> List[ProcessingCase]:
|
|
36
|
-
response = self.session.get(f"{self.
|
|
37
|
-
if response.status_code == 200:
|
|
38
|
-
raw_response = response.json()
|
|
39
|
-
return [
|
|
40
|
-
ProcessingCase.from_dict(item)
|
|
41
|
-
for item in raw_response.get('data', [])
|
|
42
|
-
]
|
|
43
|
-
return []
|
|
44
|
-
|
|
45
|
-
def filter_by_case_id(self, case_id: str) -> List[ProcessingCase]:
|
|
46
|
-
response = self.session.get(f"{self.base_url}/processing-case-items/?case_id={case_id}")
|
|
47
|
-
if response.status_code == 200:
|
|
48
|
-
raw_response = response.json()
|
|
49
|
-
return [
|
|
50
|
-
ProcessingCase.from_dict(item)
|
|
51
|
-
for item in raw_response.get('data', [])
|
|
52
|
-
]
|
|
53
|
-
return []
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
|
|
4
|
+
from documente_shared.domain.entities.processing_case import ProcessingCase
|
|
5
|
+
from documente_shared.domain.entities.processing_case_item import ProcessingCaseItem
|
|
6
|
+
from documente_shared.domain.enums.common import ProcessingStatus
|
|
7
|
+
from documente_shared.domain.repositories.processing_case_item import ProcessingCaseItemRepository
|
|
8
|
+
from documente_shared.infrastructure.documente_client import DocumenteClientMixin
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class HttpProcessingCaseItemRepository(
|
|
13
|
+
DocumenteClientMixin,
|
|
14
|
+
ProcessingCaseItemRepository,
|
|
15
|
+
):
|
|
16
|
+
|
|
17
|
+
def find(self, uuid: str) -> Optional[ProcessingCaseItem]:
|
|
18
|
+
response = self.session.get(f"{self.api_url}/processing-case-items/{uuid}/")
|
|
19
|
+
if response.status_code == 200:
|
|
20
|
+
return ProcessingCaseItem.from_dict(response.json())
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
def persist(self, instance: ProcessingCaseItem) -> ProcessingCaseItem:
|
|
24
|
+
response = self.session.put(
|
|
25
|
+
url=f"{self.api_url}/processing-case-items/{instance.uuid}/",
|
|
26
|
+
json=instance.to_simple_dict,
|
|
27
|
+
)
|
|
28
|
+
if response.status_code in [200, 201]:
|
|
29
|
+
return ProcessingCaseItem.from_dict(response.json())
|
|
30
|
+
return instance
|
|
31
|
+
|
|
32
|
+
def remove(self, instance: ProcessingCaseItem):
|
|
33
|
+
self.session.delete(f"{self.api_url}/processing-case-items/{instance.uuid}/")
|
|
34
|
+
|
|
35
|
+
def filter(self, statuses: List[ProcessingStatus]) -> List[ProcessingCase]:
|
|
36
|
+
response = self.session.get(f"{self.api_url}/processing-case-items/")
|
|
37
|
+
if response.status_code == 200:
|
|
38
|
+
raw_response = response.json()
|
|
39
|
+
return [
|
|
40
|
+
ProcessingCase.from_dict(item)
|
|
41
|
+
for item in raw_response.get('data', [])
|
|
42
|
+
]
|
|
43
|
+
return []
|