Skip to content

Commit

Permalink
šŸ› [BUG] Fix missing Annotation Categories in APIv2 for annotations otā€¦
Browse files Browse the repository at this point in the history
ā€¦her than Points (refs #4032)
  • Loading branch information
Chatewgne committed Sep 18, 2024
1 parent a14910b commit 2b4968c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CHANGELOG
- Apidae tourism parser now handles missing contact properties
- ApidaeTrekParser now handles missing source website
- Fix Aggregator does not retrieve unpublished Tour Steps (#3569)"
- Fix missing Annotation Categories in APIv2 for annotations other than Points (#4032)"

**Documentation**

Expand Down
48 changes: 47 additions & 1 deletion geotrek/api/tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,34 @@ def setUpTestData(cls):
"annotationId": 2,
"annotationType": "point",
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
296.59070688800216,
107.85521976008415
],
[
295.2543114908704,
27.671495932178686
]
]
},
"properties": {
"name": "Line 6",
"annotationId": 12345,
"annotationType": "line",
}
}
]
}
annotations_categories = {'1234': str(cls.annotationcategory.pk)}
annotations_categories = {
'1234': str(cls.annotationcategory.pk),
'12345': str(cls.annotationcategory.pk)
}
cls.hdviewpoint_trek = common_factory.HDViewPointFactory(
content_object=cls.treks[0],
annotations=annotations,
Expand Down Expand Up @@ -2561,6 +2585,28 @@ def test_hdviewpoint_detail_content(self):
"annotationType": "point",
"category": None
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
296.59070688800216,
107.85521976008415
],
[
295.2543114908704,
27.671495932178686
]
]
},
"properties": {
"name": "Line 6",
"annotationId": 12345,
"annotationType": "line",
"category": self.annotationcategory.pk
}
}
]
}
Expand Down
3 changes: 1 addition & 2 deletions geotrek/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ def get_annotations(self, obj):
annotations_categories = obj.annotations_categories
for feature in annotations.get("features", []):
feat_id = feature["properties"]["annotationId"]
feat_type = feature["geometry"]["type"]
if feat_type == "Point" and str(feat_id) in annotations_categories.keys():
if str(feat_id) in annotations_categories.keys():
feature["properties"]['category'] = int(annotations_categories[str(feat_id)])
else:
feature["properties"]['category'] = None
Expand Down

0 comments on commit 2b4968c

Please sign in to comment.