Skip to content

Commit 57bcc5e

Browse files
Add uf route #56
1 parent 5441be3 commit 57bcc5e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

PostmonServer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ def verifica_cep(cep):
8585
'localizado' % cep
8686
return
8787

88+
@app_v1.route('/uf/<sigla>')
89+
def uf(sigla):
90+
sigla = sigla.lower()
91+
db = Database()
92+
result = db.get_one_uf(sigla, fields={'_id': False})
93+
if result:
94+
response.headers['Cache-Control'] = 'public, max-age=2592000'
95+
return format_result(result)
96+
else:
97+
response.status = '404 A sigla %s informada nao pode ser localizada'.format(sigla)
98+
return
8899

89100
@app_v1.route('/rastreio/<provider>/<track>')
90101
def track_pack(provider, track):

database.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def __init__(self, address='localhost'):
2525
def get_one(self, cep, **kwargs):
2626
return self._db.ceps.find_one({'cep': cep}, **kwargs)
2727

28+
def get_one_uf(self, sigla, **kwargs):
29+
return self._db.ufs.find_one({'sigla': sigla}, **kwargs)
30+
2831
def insert_or_update(self, obj, **kwargs):
2932

3033
update = {'$set': obj}

0 commit comments

Comments
 (0)