|
1 | | -# ContractStatusChanged |
| 1 | +# Developing Unicorn Properties |
2 | 2 |
|
3 | | -*Automatically generated by the [Amazon Event Schemas](https://aws.amazon.com/)* |
| 3 | + |
4 | 4 |
|
5 | | -## Requirements |
| 5 | +## Architecture overview |
6 | 6 |
|
7 | | -1. Python 36+ |
8 | | -2. six 1.12.0 |
9 | | -3. regex 2019.11.1 |
| 7 | +Unicorn Properties is primarily responsible for approving property listings for Unicorn Web. |
10 | 8 |
|
11 | | -## Install Dependencies |
12 | | -### pip users |
| 9 | +A core component of Unicorn Properties is the approvals workflow. The approvals workflow is implemented using an AWS Step Functions state machine. At a high level, the workflow will: |
13 | 10 |
|
14 | | -Create and update it in current project's **requirements.txt**: |
| 11 | +* Check whether or not it has any contract information for the property it needs to approve. If there is no contract information, the approval process cannot be completed. |
| 12 | +* Ensure the sentiment of the property description is positive and that there no unsafe images. All checks must pass for the listing to be made public. |
| 13 | +* Ensure that the contract is in an APPROVED state before it can approve the listing. This accounts for a situation where the property listings are created before the contract has been signed and the services for Unicorn Properties are paid for. |
| 14 | +* Publish the result of the workflow via the `PublicationEvaluationCompleted` event. |
15 | 15 |
|
16 | | -``` |
17 | | -six == 1.12.0 |
18 | | -regex == 2019.11.1 |
19 | | -``` |
| 16 | +The workflow is initiated by a request made by an Unicorn Properties **agent** to have the property approved for publication. Once they have created a property listing (added property details and photos), they initiate the request in Unicorn Web, which generates a `PublicationApprovalRequested` event. This event contains the property information which the workflow processes. |
20 | 17 |
|
21 | | -Run Command: |
| 18 | +In order process the approvals workflow successfully, the properties service needs to know the current status of a contract. To remain fully decoupled from the **Contracts Service**, it maintains a local copy of contract status by consuming the `ContractStatusChanged` event. This is eliminates the need for the Contracts service to expose an API that gives other services access to its database, and allows the Properties service to function autonomously. |
22 | 19 |
|
23 | | -```sh |
24 | | -pip3 install -r requirements.txt |
25 | | -``` |
| 20 | +When the workflow is paused to check to see whether or not the contract is in an approved state, the `WaitForContractApproval` state will update a contract status for a specified property with its task token. This initiates a stream event on the DynamoDB table. The Property approvals sync function handles DynamoDB stream events. It determines whether or not to pass AWS Step Function task token back to the state machine based on the contract state. |
26 | 21 |
|
27 | | - |
28 | | -# Events |
29 | | - |
30 | | -## unicorn.contracts@ContractStatusChanged |
31 | | - |
32 | | -Payload: |
33 | | - |
34 | | -```json |
35 | | -{ |
36 | | - "contract_updated_on": "10/08/2022 19:56:30", |
37 | | - "contract_id": "222", |
38 | | - "property_id": "usa/anytown/main-street/123", |
39 | | - "contract_status": "DRAFT" |
40 | | -} |
41 | | -``` |
42 | | - |
43 | | -## unicorn.properties@PublicationEvaluationCompleted |
44 | | - |
45 | | -Payload: |
46 | | - |
47 | | -```json |
48 | | -{ |
49 | | - "property_id": "usa/anytown/main-street/123", |
50 | | - "evaluation_result": "APPROVED|DECLINED", |
51 | | - "result_reason": "UNSAFE_IMAGE_DETECTED|BAD_SENTIMENT_DETECTED|..." |
52 | | -} |
53 | | -``` |
54 | | - |
55 | | -## unicorn.properties.web@PublicationApprovalRequested |
56 | | - |
57 | | -Payload: |
58 | | - |
59 | | -```json |
60 | | -{ |
61 | | - "property_id": "usa/anytown/main-street/123", |
62 | | - "country": "USA", |
63 | | - "city": "Anytown", |
64 | | - "street": "Main Street", |
65 | | - "number": 123, |
66 | | - "description": "This classic Anytown estate comes with a covetable lake view. The romantic and comfortable backyard is the perfect setting for unicorn get-togethers. The open concept Main Stable is fully equipped with all the desired amenities. Second floor features 6 straw bales including large Rainbow Suite with private training pool terrace and Jr Sparkles Suite.", |
67 | | - "contract": "sale", |
68 | | - "listprice": 200, |
69 | | - "currency": "SPL", |
70 | | - "images": [ |
71 | | - "usa/anytown/main-street-123-0d61b4e3" |
72 | | - ] |
73 | | -} |
74 | | -``` |
75 | | - |
76 | | -# DynamoDB Schemas |
77 | | - |
78 | | -## unicorn.contracts@ContractsTable |
79 | | - |
80 | | -Item: |
81 | | - |
82 | | -```json |
83 | | -``` |
84 | | - |
85 | | -## unicorn.properties@ContractStatusTable |
86 | | - |
87 | | -Item: |
88 | | - |
89 | | -```json |
90 | | -``` |
91 | | - |
92 | | -## unicorn.properties.web@PropertiesTable |
93 | | - |
94 | | -Item: |
95 | | - |
96 | | -```json |
97 | | -``` |
| 22 | +If workflow is completed successfully, it will emit a `PublicationEvaluationCompleted` event, with an evaluation result of `APPROVED` or `DECLINED`. This is what the Property Web will listen to in order to make the list available for publication. |
0 commit comments