Skip to content

Commit 45fd88a

Browse files
committed
FINISH
1 parent 28aa024 commit 45fd88a

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Assessment de Microserviços
1313
#### Criando o Banco de Dados local:
1414
Basta rodar o models.py de cada app.
1515

16+
### Repo na nuvem
17+
```
18+
scp -i "hihiray.pem" ~/Documents/Programming/faculdade/microservice-at.zip ec2-user@ec2-52-67-178-65.sa-east-1.compute.amazonaws.com:/home/ec2-user
19+
```
20+
21+
1622
### Acessando a Documentação
1723
- Orders
1824
https://app.swaggerhub.com/apis/hi-hi-ray/Orders_API/1.0.0

app_order/send_to_sqs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def send_to_sqs(id, id_toy, quantity):
1010
queue = client.get_queue_by_name(QueueName=queue_name)
1111

1212
message = ("id: " + str(id) +
13-
" id_toy: "+ id_toy +
13+
" id_toy: "+ str(id_toy) +
1414
" quantity: " + str(quantity))
1515

1616
response = queue.send_message(MessageBody=message)

app_stock/toystock.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ def delete_item(id_req):
4949

5050

5151
def update_item(id_req, name_req, quantity_req):
52-
query_update = (ToyStock.update({
53-
'name': name_req,
54-
'quantity': quantity_cal(id_req, quantity_req)
55-
}).where(ToyStock.id == id_req))
56-
rows_updated = query_update.execute()
52+
if name_req != "NoneFila":
53+
query_update = (ToyStock.update({
54+
'name': name_req,
55+
'quantity': quantity_cal(id_req, quantity_req)
56+
}).where(ToyStock.id == id_req))
57+
rows_updated = query_update.execute()
58+
else:
59+
query_update = (ToyStock.update({
60+
'quantity': quantity_cal(id_req, quantity_req)
61+
}).where(ToyStock.id == id_req))
62+
rows_updated = query_update.execute()
5763
if rows_updated != 0:
5864
return "Toy Updated"
5965
else:

lambda.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
import urllib3
3+
from botocore.vendored import requests
4+
5+
def lambda_handler(event, context):
6+
print(event)
7+
data = event["Records"][0]["body"]
8+
message = data
9+
10+
txt = message.split()
11+
name = 'Filaignore'
12+
13+
order = {
14+
"name": "Filaignore",
15+
"quantity": int(txt[5])
16+
}
17+
18+
jsonData = json.dumps(order)
19+
20+
print(order)
21+
url = "http://18.228.238.155/toy/" + txt[3]
22+
print(url)
23+
24+
http = urllib3.PoolManager()
25+
r = http.request('PUT', url,
26+
headers={'Content-Type': 'application/json'},
27+
body=jsonData)
28+
29+
return {
30+
'statusCode': r.status
31+
}

0 commit comments

Comments
 (0)