-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
131 lines (95 loc) · 2.74 KB
/
main.py
File metadata and controls
131 lines (95 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from pprint import pprint
from fastapi import FastAPI
import boto3
from Model.user import user
from Model.clients import clients
from Controller.clientController import clientController
app = FastAPI()
# Rota Raiz
@app.get("/")
def raiz():
return {"Hello": "World"}
# Criar base de dados
base_de_dados = [
user(id=1, email="felipe@landim.com.br", password="landim123"),
user(id=2, email="teste@teste.com.br", password="teste123")
]
# Rota Get All
@app.get("/usuarios")
def get_todos_os_usuarios():
return base_de_dados
# Rota Get Id
@app.get("/usuarios/{id_usuario}")
def get_usuario_usando_id(id_usuario: int):
for user in base_de_dados:
if(user.id == id_usuario):
return user
return {"Status": 404, "Mensagem": "Não encontrou usuario"}
# Rota Insere
@app.post("/usuarios")
def insere_usuario(user: user):
# criar regras de negocio
base_de_dados.append(user)
return user
# Rota Insere
@app.post("/clients")
def insere_usuario(clients: clients):
# criar regras de negocio
cliContr = clientController()
response = cliContr.putClient(clients)
return response
# Rota Insere
@app.get("/clients")
def search_all_clients():
# criar regras de negocio
cliContr = clientController()
response = cliContr.getAllClients()
return response
#add new client
def put_client(document, name, email, phone, dynamodb=None):
cliContr = clientController()
response = table.put_item(Item=input)
return response
#criar tabela clients
'''
# Rota Insere
@app.post("/createtableclients")
def insere_usuario():
# criar tabela
return create_clients_table()
def create_clients_table(dynamodb=None):
if not dynamodb:
dynamodb = boto3.resource('dynamodb',
aws_access_key_id="anything",
aws_secret_access_key="anything",
region_name='us-west-2',
endpoint_url="http://localhost:8000")
table = dynamodb.create_table(
TableName='Clients',
KeySchema=[
{
'AttributeName': 'document',
'KeyType': 'HASH' # Partition key
},
{
'AttributeName': 'name',
'KeyType': 'RANGE' # Sort key
}
],
AttributeDefinitions=[
{
'AttributeName': 'document',
'AttributeType': 'S'
},
{
'AttributeName': 'name',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
}
)
return table
'''