Skip to content

Commit 5dba4fa

Browse files
committed
feat: updated readme for services to match workshop content.
1 parent e23c296 commit 5dba4fa

File tree

3 files changed

+49
-122
lines changed

3 files changed

+49
-122
lines changed

unicorn_contracts/README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1-
# Unicorn Properties: Contracts Service
1+
# Developing Unicorn Contracts
22

3-
## Overview
3+
![Contracts Service Architecture](https://static.us-east-1.prod.workshops.aws/public/fd291886-89c4-4336-b21b-5747484b495d/static/images/architecture-contracts.png)
44

5-
TODO: add overview
5+
## Architecture overview
66

7-
TODO: add architecture image
7+
Unicorn Contract manages the contractual relationship between the customers and the Unicorn Properties agency. It's primary function is to allow Unicorn Properties agents to create a new contract for a property listing, and to have the contract approved once it's ready.
88

9-
## Testing with Postman
9+
The architecture is fairly straight forward. An API exposes the create contract and update contract methods. This information is recorded in a Amazon DynamoDB table which will contain all latest information about the contract and it's status.
1010

11-
TODO: add instructions
11+
Each time a new contract is created or updated, Unicorn Contracts publishes a `ContractStatusChanged` event to Amazon EventBridge signalling changes to the contract status. These events are consumed by **Unicorn Properties**, so it can track changes to contracts, without needing to take a direct dependency on Unicorn Contracts and it's database.
1212

13-
## Testing with TODO: curl or httpie
13+
Here is an example of an event that is published to EventBridge:
1414

15+
```json
16+
{
17+
"version": "0",
18+
"account": "123456789012",
19+
"region": "us-east-1",
20+
"detail-type": "ContractStatusChanged",
21+
"source": "unicorn.contracts",
22+
"time": "2022-08-14T22:06:31Z",
23+
"id": "c071bfbf-83c4-49ca-a6ff-3df053957145",
24+
"resources": [],
25+
"detail": {
26+
"contract_updated_on": "10/08/2022 19:56:30",
27+
"ContractId": "617dda8c-e79b-406a-bc5b-3a4712f5e4d7",
28+
"PropertyId": "usa/anytown/main-street/111",
29+
"ContractStatus": "DRAFT"
30+
}
31+
}
32+
```

unicorn_properties/README.md

Lines changed: 13 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,22 @@
1-
# ContractStatusChanged
1+
# Developing Unicorn Properties
22

3-
*Automatically generated by the [Amazon Event Schemas](https://aws.amazon.com/)*
3+
![Properties Approval Architecture](https://static.us-east-1.prod.workshops.aws/public/fd291886-89c4-4336-b21b-5747484b495d/static/images/architecture-properties.png)
44

5-
## Requirements
5+
## Architecture overview
66

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.
108

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:
1310

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.
1515

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.
2017

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.
2219

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.
2621

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.

unicorn_web/README.md

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,18 @@
1-
# Unicorn Properties: Properties Web
1+
# Developing Unicorn Web
22

3-
## Overview
3+
![Properties Web Architecture](https://static.us-east-1.prod.workshops.aws/public/fd291886-89c4-4336-b21b-5747484b495d/static/images/architecture-properties-web.png)
44

5-
TODO: add overview
5+
## Architecture Overview
66

7-
TODO: add architecture image
7+
Unicorn Web is primarily responsible for allowing customers to search and view property listings. It also supports ability for agents to request approval for specific property. Those approval requests are sent to Property service for validation, before Properties table is updated with approval evaluation results.
88

9-
## Testing with Postman
9+
A core component of Unicorn Web are the Lambda functions which are responsible with completing API Gateway requests to:
1010

11-
TODO: add instructions
11+
- search approved property listings
12+
This function interacts with DynamoDB table to retrieve property listings marked as `APPROVED`. The API Gateway implementation and lambda code support multiple types of search patterns, and allow searching by city, street, or house number.
1213

13-
## Testing with TODO: curl or httpie
14+
- request approval of property listing
15+
This function sends an event to EventBridge requesting an approval for a property listing specified in the payload sent from client
1416

15-
Using Httpie as a starting point; will need to change to Postman next
16-
17-
### Add
18-
19-
```bash
20-
https https://rruhykpqtb.execute-api.ap-southeast-1.amazonaws.com/default/properties/add < postman/property01.json
21-
```
22-
23-
### List property by city and by street
24-
25-
```bash
26-
https https://rruhykpqtb.execute-api.ap-southeast-1.amazonaws.com/default/properties/list/usa/anytown
27-
https https://rruhykpqtb.execute-api.ap-southeast-1.amazonaws.com/default/properties/list/usa/anytown/main-street
28-
```
29-
30-
### Property details
31-
32-
```bash
33-
https https://rruhykpqtb.execute-api.ap-southeast-1.amazonaws.com/default/properties/usa/anytown/main-street/123
34-
```
17+
- publication approved function
18+
There is also a lambda function responsible for receiving any "Approval Evaluation Completed" events from EventBridge. This function writes the evaluation result to DynamoDB table.

0 commit comments

Comments
 (0)