service
A generic service object implementation.
Service object is generic on the domain model type, which should be a SQLAlchemy model.
Service ¶
Bases: Generic[ModelT]
Generic Service object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository |
Instance conforming to |
required |
__init_subclass__ ¶
Create and cache a DTO instance that is internal use only.
note
This pattern could be changed to on first access, rather than at compile time.
authorize_create
async
¶
Control resource creation.
Can use self.user here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
ModelT
|
The object to be created. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
The object with restricted attribute values removed. |
authorize_delete
async
¶
Authorize delete of item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_ |
Any
|
Identifier of item to be retrieved. |
required |
authorize_get
async
¶
Authorize get of item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_ |
Any
|
Identifier of item to be retrieved. |
required |
authorize_update
async
¶
Authorize update of item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_ |
Any
|
Identifier of the object to be updated. |
required |
data |
ModelT
|
The object to be updated. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
ModelT |
authorize_upsert
async
¶
Authorize upsert of item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_ |
Any
|
The identifier of the resource to upsert. |
required |
data |
ModelT
|
The object to be updated. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
ModelT |
create
async
¶
Wraps repository instance creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
ModelT
|
Representation to be created. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
Representation of created instance. |
delete
async
¶
Wraps repository delete operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_ |
Any
|
Identifier of instance to be deleted. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
Representation of the deleted instance. |
enqueue_callback
async
¶
Enqueue an async callback for the operation and data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation |
Operation
|
Operation performed on data. |
required |
data |
ModelT
|
The data for the operation. |
required |
get
async
¶
Wraps repository scalar operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_ |
Any
|
Identifier of instance to be retrieved. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
Representation of instance with identifier |
list
async
¶
receive_callback
async
¶
UnauthorizedException ¶
Bases: ServiceException
A user tried to do something they shouldn't have.
make_service_callback
async
¶
Function that makes the async service callbacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_ctx |
dict
|
the SAQ context |
required |
service_module_name |
str
|
Module of service type to instantiate. |
required |
service_type_fqdn |
str
|
Reference to service type in module. |
required |
operation |
Operation
|
Operation performed on the instance. |
required |
raw_obj |
dict[str, Any]
|
Data received from the work queue. |
required |