Skip to content

Commit

Permalink
Merge pull request #224 from unicef-drp/develop
Browse files Browse the repository at this point in the history
Fix documentation typo
  • Loading branch information
danangmassandy authored May 28, 2024
2 parents 6ad545c + 272b817 commit ec57aa0
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 21 deletions.
55 changes: 54 additions & 1 deletion django_project/core/static/drf-yasg-custom/swagger-ui-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,46 @@ var KEY_AUTH = slugify(window.location.pathname) + "-drf-yasg-auth";
// load the saved authorization state from localStorage; ImmutableJS is used for consistency with swagger-ui state
var savedAuth = Immutable.fromJS({});

// ordering API
var API_ORDERS = {
"02-search-dataset": [
"search-dataset-list",
"search-dataset-detail"
],
"04-search-view-entity": [
"search-entity-by-ucode",
"search-entity-by-concept-ucode",
"search-view-entity-by-id",
"search-view-entity-by-level",
"search-view-entity-by-level-and-ucode",
"search-view-entity-by-level-and-concept-ucode",
"search-view-entity-by-level-0",
"search-view-entity-by-type",
"search-view-entity-by-type-and-ucode",
"search-view-entity-versions-by-ucode",
"search-view-entity-versions-by-concept-ucode",
"search-view-entity-by-name",
"search-view-entity-children-by-ucode",
"search-view-entity-parents-by-ucode",
"search-view-entity-by-geometry",
"batch-search-view-by-id",
"check-batch-status-search-view-by-id",
"get-result-batch-search-view-by-id",
],
"05-operation-view-entity": [
"operation-view-bbox",
"operation-view-containment-check",
"batch-geocoding",
"check-status-batch-geocoding",
"get-result-batch-geocoding"
],
"06-download": [
"submit-download-job",
"fetch-download-job-status"
],
}


// global SwaggerUI config object; can be changed directly or by hooking initSwaggerUiConfig
var swaggerUiConfig = {
url: defaultSpecUrl,
Expand All @@ -44,7 +84,20 @@ var swaggerUiConfig = {
}

return request;
}
},
operationsSorter: function (a, b) {
var a_operationId = a.get("operation").get("operationId");
var b_operationId = b.get("operation").get("operationId");
var a_tags = a.get("operation").get("tags");
var a_tag = a_tags.get(0, '');
if (!(a_tag in API_ORDERS)) {
var order = { 'get': '0', 'post': '1', 'put': '2', 'delete': '3' };
return order[a.get("method")].localeCompare(order[b.get("method")]);
}
var a_idx = API_ORDERS[a_tag].indexOf(a_operationId);
var b_idx = API_ORDERS[a_tag].indexOf(b_operationId);
return a_idx === b_idx ? 0 : a_idx < b_idx ? -1 : 1;
},
};

function patchSwaggerUi() {
Expand Down
6 changes: 3 additions & 3 deletions django_project/georepo/api_views/entity_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3273,7 +3273,7 @@ class FindEntityByCUCode(FindEntityByUCode):
"""
permission_classes = [IsAuthenticated]
renderer_classes = [JSONRenderer, GeojsonRenderer]
id_type = 'cucode'
id_type = 'concept_ucode'

def get_queryset(self, id_raw):
return GeographicalEntity.objects.select_related(
Expand All @@ -3299,10 +3299,10 @@ def generate_response(self, entities, context=None) -> Tuple[dict, dict]:
return output, None

@swagger_auto_schema(
operation_id='search-entity-by-cucode',
operation_id='search-entity-by-concept-ucode',
tags=[SEARCH_VIEW_ENTITY_TAG],
manual_parameters=[openapi.Parameter(
'cucode', openapi.IN_PATH,
'concept_ucode', openapi.IN_PATH,
description='Entity Concept UCode',
type=openapi.TYPE_STRING
), openapi.Parameter(
Expand Down
22 changes: 11 additions & 11 deletions django_project/georepo/tests/test_api_entity_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2856,11 +2856,11 @@ def test_find_entity_by_ucode_in_prev_version(self):
def test_find_entity_by_cucode_not_found(self):
view = FindEntityByCUCode.as_view()
kwargs = {
'cucode': '#TEST_EMPTY_V1'
'concept_ucode': '#TEST_EMPTY_V1'
}
request = self.factory.get(
reverse(
'v1:search-entity-by-cucode',
'v1:search-entity-by-concept-ucode',
kwargs=kwargs
),
)
Expand All @@ -2869,11 +2869,11 @@ def test_find_entity_by_cucode_not_found(self):
self.assertEqual(response.status_code, 404)
# user_2 should not be able to view the entity
kwargs = {
'cucode': self.pak0_2.concept_ucode
'concept_ucode': self.pak0_2.concept_ucode
}
request = self.factory.get(
reverse(
'v1:search-entity-by-cucode',
'v1:search-entity-by-concept-ucode',
kwargs=kwargs
),
)
Expand All @@ -2883,7 +2883,7 @@ def test_find_entity_by_cucode_not_found(self):
# user_4 should not be able to view at all
request = self.factory.get(
reverse(
'v1:search-entity-by-cucode',
'v1:search-entity-by-concept-ucode',
kwargs=kwargs
),
)
Expand All @@ -2894,11 +2894,11 @@ def test_find_entity_by_cucode_not_found(self):
def test_find_entity_by_cucode(self):
view = FindEntityByCUCode.as_view()
kwargs = {
'cucode': self.pak0_2.concept_ucode
'concept_ucode': self.pak0_2.concept_ucode
}
request = self.factory.get(
reverse(
'v1:search-entity-by-cucode',
'v1:search-entity-by-concept-ucode',
kwargs=kwargs
),
)
Expand All @@ -2915,7 +2915,7 @@ def test_find_entity_by_cucode(self):
# test using user 1, should have access
request = self.factory.get(
reverse(
'v1:search-entity-by-cucode',
'v1:search-entity-by-concept-ucode',
kwargs=kwargs
),
)
Expand All @@ -2932,7 +2932,7 @@ def test_find_entity_by_cucode(self):
# test using user 3, should have access to only custom_view
request = self.factory.get(
reverse(
'v1:search-entity-by-cucode',
'v1:search-entity-by-concept-ucode',
kwargs=kwargs
),
)
Expand All @@ -2958,11 +2958,11 @@ def test_find_entity_by_cucode_in_prev_version(self):
calculate_entity_count_in_view(all_versions_view)
view = FindEntityByCUCode.as_view()
kwargs = {
'cucode': self.pak0_1.concept_ucode
'concept_ucode': self.pak0_1.concept_ucode
}
request = self.factory.get(
reverse(
'v1:search-entity-by-cucode',
'v1:search-entity-by-concept-ucode',
kwargs=kwargs
),
)
Expand Down
4 changes: 2 additions & 2 deletions django_project/georepo/urls_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@
FindEntityByUCode.as_view(),
name='search-entity-by-ucode'),
path(
'search/entity/cucode/<str:cucode>/',
'search/entity/concept_ucode/<str:concept_ucode>/',
FindEntityByCUCode.as_view(),
name='search-entity-by-cucode'),
name='search-entity-by-concept-ucode'),
path(
'search/view/<uuid:uuid>/entity/identifier/<str:id_type>/<str:id>/',
FindViewEntityById.as_view(),
Expand Down
2 changes: 1 addition & 1 deletion django_project/version/commit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
383ac2ef6e5a7d8dbd3c5e394a1e90c902409385
66e26183f7697d997dede48aab6ba3755eeea5a9
2 changes: 1 addition & 1 deletion django_project/version/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.74
0.0.75
1 change: 1 addition & 0 deletions docs/mkdocs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ nav:
- API:
- user/api/index.md
- Guide: user/api/guide/index.md
- Vector Tiles: user/api/vector_tiles/index.md
- Manual: https://georepo.unicef.org/api/v1/docs/
- Administrators:
- Overview:
Expand Down
8 changes: 6 additions & 2 deletions docs/src/user/api/vector_tiles/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where `809ad72b-f083-4f2f-aca0-e756482dbd6d` is the resource ID from the View. T

## How to authenticate to the vector tiles

The vector tiles requires [API KEY](../guide/index.md#generating-an-api-key) and your `email address` for the authentication. This is similar to how to call the GeoRepo API, but the different is the `API KEY` and your `email address` need to be appened to the vector tiles URL as a request parameters. Below format is a complete vector tiles URL with the `API KEY` and `email address`:
The vector tiles requires [API KEY](../guide/index.md#generating-an-api-key) and your `email address` for the authentication. This is similar to how to call the GeoRepo API, but the different is the `API KEY` and your `email address` need to be appended to the vector tiles URL as a request parameters. Below format is a complete vector tiles URL with the `API KEY` and `email address`:

```
https://georepo.unicef.org/layer_tiles/809ad72b-f083-4f2f-aca0-e756482dbd6d/{z}/{x}/{y}?t=1700218824&&token=YOUR_API_KEY&georepo_user_key=YOUR_EMAIL_ADDRESS
Expand Down Expand Up @@ -63,7 +63,7 @@ The GeoRepo APIs that return the vector tiles URL will also return bounding box

### Apply Overzoom in the Map

The GeoRepo APIs also returns the maximum zoom (`max_zoom` field) for the view. The map client can use this value to apply the overzoom so the map does not request vector tiles above the `max_zoom`.
The GeoRepo APIs also return the maximum zoom (`max_zoom` field) for the view. The map client can use this value to apply the overzoom so the map does not request vector tiles above the `max_zoom`.

### Sample code

Expand Down Expand Up @@ -91,3 +91,7 @@ map.on('load', function () {
map.addLayer({'id': 'Level-0', 'source': 'World (Latest)', 'source-layer': 'Level-0', 'type': 'line', 'paint': {'line-color': '#69C868', 'line-width': 1}, 'minzoom': 0})
});
```

**Notes**
- BOUNDING_BOX_VALUE is in [sw, ne] order, or an array of numbers in [west, south, east, north] order. For example: [[-73.9876, 40.7661], [-73.9397, 40.8002]]
- source-layer is available in the vector tiles using ID with format: `Level-N` where N is the admin level. Please use the available admin levels from Find View Detail API (`dataset_levels` field).

0 comments on commit ec57aa0

Please sign in to comment.