diff --git a/docs/changelog.rst b/docs/changelog.rst index af65d32466..5cce1c2b4b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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** diff --git a/geotrek/api/tests/test_v2.py b/geotrek/api/tests/test_v2.py index c7829b78f1..41ac39cbfb 100644 --- a/geotrek/api/tests/test_v2.py +++ b/geotrek/api/tests/test_v2.py @@ -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, @@ -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 + } } ] } diff --git a/geotrek/api/v2/serializers.py b/geotrek/api/v2/serializers.py index d831bf01f4..435cc81b1b 100644 --- a/geotrek/api/v2/serializers.py +++ b/geotrek/api/v2/serializers.py @@ -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