diff --git a/api/urls/v1/urls.py b/api/urls/v1/urls.py index 75720e8..3350c6b 100644 --- a/api/urls/v1/urls.py +++ b/api/urls/v1/urls.py @@ -9,6 +9,7 @@ from django.urls import path from api.views.v1.compensation import APICompensationViewV1 from api.views.v1.ecoaccount import APIEcoAccountViewV1 +from api.views.v1.ema import APIEmaViewV1 from api.views.v1.intervention import APIInterventionViewV1 app_name = "v1" @@ -16,4 +17,5 @@ urlpatterns = [ path("intervention/", APIInterventionViewV1.as_view(), name="intervention"), path("compensation/", APICompensationViewV1.as_view(), name="compensation"), path("ecoaccount/", APIEcoAccountViewV1.as_view(), name="ecoaccount"), + path("ema/", APIEmaViewV1.as_view(), name="ema"), ] diff --git a/api/views/v1/ema.py b/api/views/v1/ema.py new file mode 100644 index 0000000..ba07e50 --- /dev/null +++ b/api/views/v1/ema.py @@ -0,0 +1,41 @@ +""" +Author: Michel Peltriaux +Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany +Contact: michel.peltriaux@sgdnord.rlp.de +Created on: 21.01.22 + +""" +import json + +from django.http import JsonResponse, HttpRequest + +from api.views.v1.ecoaccount import APIEcoAccountViewV1 +from ema.models import Ema + + +class APIEmaViewV1(APIEcoAccountViewV1): + model = Ema + + def get(self, request: HttpRequest, id): + self.lookup["id"] = id + self.lookup["users__in"] = [self.user] + + data = self.fetch_and_serialize() + return JsonResponse(data) + + def model_to_json(self, entry): + entry_json = { + "identifier": entry.identifier, + "title": entry.title, + "responsible": self.responsible_to_json(entry.responsible), + "before_states": self.compensation_state_to_json(entry.before_states.all()), + "after_states": self.compensation_state_to_json(entry.after_states.all()), + "actions": self.compensation_actions_to_json(entry.actions.all()), + "deadlines": self.deadlines_to_json(entry.deadlines.all()), + "modified_on": self.modified_on_to_json(entry), + "created_on": self.created_on_to_json(entry), + } + geom = entry.geometry.geom.geojson + geo_json = json.loads(geom) + geo_json["properties"] = entry_json + return geo_json \ No newline at end of file