Skip to content

Commit a4c7d8c

Browse files
committed
documentation added for the endpoints
1 parent 13955a8 commit a4c7d8c

10 files changed

+74
-26
lines changed

src/api_modules/adm1.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ def get(self):
1313
Get all Administrative levels 1 from database (zone)
1414
---
1515
description: Query the information of all administrative levels 1 and the API will respond with the list of all regions, this endpoint has no parameters.
16+
tags:
17+
- Administrative levels
1618
responses:
1719
200:
1820
description: Administrative level 1
21+
1922
schema:
2023
id: Adm1
2124
properties:

src/api_modules/adm2.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ def get(self, adm1 = None):
1313
Get all Administrative levels 2 from database (woreda)
1414
---
1515
description: Query the information of the administrative levels 2 (woreda). This endpoint needs one parameter, **adm1** that is id of the administrative levels 1 (zone) to be queried (this id can be obtained from the endpoint `/adm1`); The API will respond with the list of the woredas from that specific zone.
16+
tags:
17+
- Administrative levels
1618
parameters:
1719
- in: path
1820
name: adm1
1921
type: string
2022
required: true
23+
description: adm1 id to be query, for example 64d1be9c16bfd546aec4f58b
2124
responses:
2225
200:
2326
description: Administrative levels 2

src/api_modules/adm3.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ def get(self,adm2=None):
1313
Get all Administrative levels 3 from database (kebele)
1414
---
1515
description: Query the information of the administrative levels 3 (kebele). This endpoint needs one parameter, **adm2** that is id of the administrative levels 2 (woreda) to be queried (this id can be obtained from the endpoint `/adm2`); The API will respond with the list of the kebeles from that specific woreda.
16+
tags:
17+
- Administrative levels
1618
parameters:
1719
- in: path
1820
name: adm2
1921
type: string
2022
required: true
23+
description: adm2 id to be query, for example 64d1bec4f8b9461ac6ed74cb
2124
responses:
2225
200:
2326
description: Administrative levels 3

src/api_modules/monitored_data.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ def get(self, waterpoint=None):
1212
Get all Monitored data
1313
---
1414
description: Query the information of monitored data from one waterpoint . This endpoint needs one parameter, **waterpoint** that is id of the waterpoint to be queried (this id can be obtained from the endpoint `/waterpoint`); The API will respond with the list of the monitored values from that specific waterpoint.
15+
tags:
16+
- Waterpoint Monitored data
1517
parameters:
1618
- in: path
1719
name: waterpoint
1820
type: string
1921
required: true
22+
description: waterpoint id to be query, for example 64d1bf1cc703fe54e05ee7d6
2023
responses:
2124
200:
2225
description: Monitored data

src/api_modules/monitored_latest.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ def get(self, waterpoint=None):
1212
Get last Monitored data
1313
---
1414
description: Query the information of last monitored data from one waterpoint . This endpoint needs one parameter, **waterpoint** that is id of the waterpoint to be queried (this id can be obtained from the endpoint `/waterpoint`); The API will respond with the list of the last monitored values from that specific waterpoint.
15+
tags:
16+
- Waterpoint Monitored data
1517
parameters:
1618
- in: path
1719
name: waterpoint
1820
type: string
1921
required: true
22+
description: waterpoint id to be query, for example 64d1bf1cc703fe54e05ee7d6
2023
responses:
2124
200:
2225
description: Monitored data

src/api_modules/sigle_waterpoint.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ def get(self,waterpoint=None):
1313
Get all one waterpoint from database
1414
---
1515
description: Query the information of the ons specific waterpoint. This endpoint needs one parameter, **waterpoint** that is id of the waterpoint to be queried (this id can be obtained from the endpoint `/waterpoints`); The API will respond with the waterpoit with the id provided.
16+
tags:
17+
- Waterpoint information
1618
parameters:
1719
- in: path
1820
name: waterpoint
1921
type: string
2022
required: true
23+
description: waterpoint id to be query, for example 64d1bf1cc703fe54e05ee7d6
2124
responses:
2225
200:
2326
description: Waterpoint

src/api_modules/waterpoint.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def get(self):
1313
Get all waterpoints from database
1414
---
1515
description: Query the information of the waterpoints. This endpoint has not parameter.
16+
tags:
17+
- Waterpoint information
1618
responses:
1719
200:
1820
description: Waterpoints

src/api_modules/single_waterpoint_profile.py src/api_modules/waterpoint_profiles.py

+33-12
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ def get(self, waterpoints=None,language=None):
2323
Get one waterpoint profile from database
2424
---
2525
description: Query the information of the one waterpoints profile. This endpoint has not parameter. This endpoint needs two parameters, **waterpoint** that is id of the waterpoint to be queried (this id can be obtained from the endpoint `/waterpoints`), and the **language** that is the language that you want to get; The API will respond with the waterpoit profile with the id provided.
26+
tags:
27+
- Waterpoint information
2628
parameters:
2729
- in: path
2830
name: waterpoints
2931
type: string
3032
required: true
33+
description: IDs of waterpoints you want to retrieve, separated by comma, for example 64d1bf1cc703fe54e05ee7d6,64d1bf1cc703fe54e05ee7d7
3134
- in: path
3235
name: language
3336
type: string
3437
required: false
38+
description: Language in which you want to view the content, currently we have three languages, **en**, **or**, and **am**
39+
3540
responses:
3641
200:
3742
description: Waterpoints profiles
@@ -104,37 +109,53 @@ def get(self, waterpoints=None,language=None):
104109
content__trace__enable=True)
105110
ws_contents = Wscontent.objects(watershed=str(waterpoint.watershed.id),
106111
content__trace__enable=True)
107-
#ws_contents = Wscontent.objects(watershed=str(waterpoint.watershed.id))
108-
#contents_list = [content.content for content in wp_contents if 'language' in content.content and content.content['language'] == language]
109112
ids=[]
110113
typecontent_name=[]
111114
for i in wp_contents:
112115
ids.append(str(i.type.id))
113116
typecontent=Typecontent.objects.get(id=str(i.type.id))
114117
typecontent_name.append(typecontent.name)
115118

116-
print(typecontent_name)
117-
118-
print(ids)
119-
#contents_list = [(content.content) for content in wp_contents if 'language' in content.content and content.content['language'] == language]
120-
contents_list = [(content["content"] if "language" not in content["content"]
119+
120+
contents_list = [(content["content"] if language not in content["content"]
121121
else {**content["content"], "typecontent_id": ids.pop(0)})
122122
for content in wp_contents]
123123

124124
for content, name in zip(contents_list, typecontent_name):
125-
# Agregamos el nuevo ID con la clave "id" al contenido existente
126125
content["typecontent_name"] = name
127126

128127

129128
for content in contents_list:
130129
if 'trace' in content:
131130
del content['trace']
132131

133-
contents_list_ws = [content.content for content in ws_contents if 'language' in content.content and content.content['language'] == language]
132+
133+
134+
idsws=[]
135+
typecontentws_name=[]
136+
for i in ws_contents:
137+
idsws.append(str(i.type.id))
138+
typecontent=Typecontent.objects.get(id=str(i.type.id))
139+
typecontentws_name.append(typecontent.name)
140+
141+
142+
contents_list_ws = [(content["content"] if language not in content["content"]
143+
else {**content["content"], "typecontent_id": idsws.pop(0)})
144+
for content in ws_contents]
145+
146+
for content, name in zip(contents_list_ws, typecontentws_name):
147+
content["typecontent_name"] = name
134148
for content in contents_list_ws:
135149
if 'trace' in content:
136150
del content['trace']
137-
print(contents_list)
151+
filtered_contents=[]
152+
for content in contents_list:
153+
if content['language']==language:
154+
filtered_contents.append(content)
155+
filtered_contentsws=[]
156+
for content in contents_list_ws:
157+
if content['language']==language:
158+
filtered_contentsws.append(content)
138159
waterpoint_data = {
139160
"id": str(waterpoint.id),
140161
"name": waterpoint.name,
@@ -148,8 +169,8 @@ def get(self, waterpoints=None,language=None):
148169
"adm3": adm3.name,
149170
"adm2": adm2.name,
150171
"adm1": adm1.name,
151-
"contents_wp": contents_list,
152-
"contents_ws": contents_list_ws,
172+
"contents_wp": filtered_contents,
173+
"contents_ws": filtered_contentsws,
153174
}
154175

155176
json_data.append(waterpoint_data)

src/tests/test_waterpoint_profile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def tearDown(self):
1616

1717
def test_single_waterpointprofile_valid_id(self):
1818
# Test a valid waterpointprofile ID
19-
response = self.app.get('http://127.0.0.1:5000/api/v1/waterpointsprofiles/en', headers={"Content-Type": "application/json"})
19+
response = self.app.get('http://127.0.0.1:5000/api/v1/waterpointsprofiles/64d1bf1cc703fe54e05ee7de/en', headers={"Content-Type": "application/json"})
2020
self.assertEqual(200, response.status_code)
2121
# Add more assertions to check the response content
2222

src/wpapi.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,45 @@
1616
from api_modules.waterpoint import Waterpoints
1717
from api_modules.sigle_waterpoint import SingleWaterpoints
1818
from api_modules.monitored_data import MonitoredData
19-
from api_modules.single_waterpoint_profile import SingleWaterpointsProfile
19+
from api_modules.waterpoint_profiles import SingleWaterpointsProfile
2020
from api_modules.monitored_latest import LastMonitoredData
2121
#from api_modules.layers import Layers
2222

23-
23+
2424
app = Flask(__name__)
2525
CORS(app)
2626
api = Api(app)
2727
swagger = Swagger(app)
2828

29+
# Define tus endpoints en el orden deseado
2930

30-
@app.route('/')
31+
@app.route('/api/v1/home')
3132
def home():
3233
return redirect("/apidocs")
3334

34-
35-
35+
# Endpoint para AdministrativeLevel1
3636
api.add_resource(AdministrativeLevel1, '/api/v1/adm1')
37+
38+
# Endpoint para AdministrativeLevel2
3739
api.add_resource(AdministrativeLevel2, '/api/v1/adm2/<adm1>')
40+
41+
# Endpoint para AdministrativeLevel3
3842
api.add_resource(AdministrativeLevel3, '/api/v1/adm3/<adm2>')
39-
api.add_resource(Waterpoints, '/api/v1/waterpoints')
40-
api.add_resource(SingleWaterpoints, '/api/v1/waterpoints/<waterpoint>')
41-
api.add_resource(MonitoredData, '/api/v1/monitored/<waterpoint>')
42-
api.add_resource(LastMonitoredData, '/api/v1/lastmonitored/<waterpoint>')
43-
api.add_resource(SingleWaterpointsProfile, '/api/v1/waterpointsprofiles/<waterpoints>/<language>')
4443

44+
# Endpoint para Waterpoints
45+
api.add_resource(Waterpoints, '/api/v1/waterpoints')
4546

47+
# Endpoint para SingleWaterpoints
48+
api.add_resource(SingleWaterpoints, '/api/v1/waterpoints/<waterpoint>')
4649

50+
# Endpoint para MonitoredData
51+
api.add_resource(MonitoredData, '/api/v1/monitored/<waterpoint>')
4752

53+
# Endpoint para LastMonitoredData
54+
api.add_resource(LastMonitoredData, '/api/v1/lastmonitored/<waterpoint>')
4855

56+
# Endpoint para SingleWaterpointsProfile
57+
api.add_resource(SingleWaterpointsProfile, '/api/v1/waterpointsprofiles/<waterpoints>/<language>')
4958

5059
if __name__ == '__main__':
5160
connect(host=config['CONNECTION_DB'])
@@ -54,6 +63,4 @@ def home():
5463
if config['DEBUG']:
5564
app.run(threaded=True, port=config['PORT'], debug=config['DEBUG'])
5665
else:
57-
app.run(host=config['HOST'], port=config['PORT'],
58-
debug=config['DEBUG'])
59-
66+
app.run(host=config['HOST'], port=config['PORT'], debug=config['DEBUG'])

0 commit comments

Comments
 (0)