|
| 1 | +from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent |
| 2 | +from domain.core.cpm_product.v1 import CpmProduct |
| 3 | +from domain.core.device_reference_data.v1 import DeviceReferenceData |
| 4 | +from domain.core.product_team.v3 import ProductTeam |
| 5 | +from domain.repository.cpm_product_repository.v3 import CpmProductRepository |
| 6 | +from domain.repository.device_reference_data_repository.v1 import ( |
| 7 | + DeviceReferenceDataRepository, |
| 8 | +) |
| 9 | +from domain.repository.product_team_repository.v2 import ProductTeamRepository |
| 10 | +from domain.request_models.v1 import DeviceReferenceDataPathParams |
| 11 | +from domain.response.validation_errors import mark_validation_errors_as_inbound |
| 12 | +from event.step_chain import StepChain |
| 13 | + |
| 14 | + |
| 15 | +@mark_validation_errors_as_inbound |
| 16 | +def parse_path_params(data, cache) -> DeviceReferenceDataPathParams: |
| 17 | + event = APIGatewayProxyEvent(data[StepChain.INIT]) |
| 18 | + return DeviceReferenceDataPathParams(**event.path_parameters) |
| 19 | + |
| 20 | + |
| 21 | +def read_product_team(data, cache) -> ProductTeam: |
| 22 | + path_params: DeviceReferenceDataPathParams = data[parse_path_params] |
| 23 | + product_team_repo = ProductTeamRepository( |
| 24 | + table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"] |
| 25 | + ) |
| 26 | + return product_team_repo.read(id=path_params.product_team_id) |
| 27 | + |
| 28 | + |
| 29 | +def read_product(data, cache) -> CpmProduct: |
| 30 | + path_params: DeviceReferenceDataPathParams = data[parse_path_params] |
| 31 | + product_repo = CpmProductRepository( |
| 32 | + table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"] |
| 33 | + ) |
| 34 | + cpm_product = product_repo.read( |
| 35 | + product_id=path_params.product_id, product_team_id=path_params.product_team_id |
| 36 | + ) |
| 37 | + return cpm_product |
| 38 | + |
| 39 | + |
| 40 | +def read_device_reference_data(data, cache) -> DeviceReferenceData: |
| 41 | + path_params: DeviceReferenceDataPathParams = data[parse_path_params] |
| 42 | + product_repo = DeviceReferenceDataRepository( |
| 43 | + table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"] |
| 44 | + ) |
| 45 | + return product_repo.read( |
| 46 | + product_id=path_params.product_id, |
| 47 | + product_team_id=path_params.product_team_id, |
| 48 | + device_reference_data_id=path_params.device_reference_data_id, |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +def device_reference_data_to_dict(data, cache) -> dict: |
| 53 | + device_reference_data: DeviceReferenceData = data[read_device_reference_data] |
| 54 | + return device_reference_data.state() |
| 55 | + |
| 56 | + |
| 57 | +steps = [ |
| 58 | + parse_path_params, |
| 59 | + read_product_team, |
| 60 | + read_product, |
| 61 | + read_device_reference_data, |
| 62 | + device_reference_data_to_dict, |
| 63 | +] |
0 commit comments