2022-01-21 15:26:08 +01:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
|
|
Created on: 21.01.22
|
|
|
|
|
|
|
|
"""
|
2022-01-21 18:34:01 +01:00
|
|
|
from django.http import JsonResponse, HttpRequest
|
2022-01-21 15:26:08 +01:00
|
|
|
|
2022-01-24 10:31:48 +01:00
|
|
|
from api.utils.v1.compensation import CompensationAPISerializerV1
|
|
|
|
from api.utils.v1.ecoaccount import EcoAccountAPISerializerV1
|
|
|
|
from api.utils.v1.ema import EmaAPISerializerV1
|
|
|
|
from api.utils.v1.intervention import InterventionAPISerializerV1
|
2022-01-21 15:26:08 +01:00
|
|
|
from api.views.views import AbstractModelAPIView
|
|
|
|
|
|
|
|
|
|
|
|
class AbstractModelAPIViewV1(AbstractModelAPIView):
|
|
|
|
""" Holds general serialization functions for API v1
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2022-01-21 18:34:01 +01:00
|
|
|
def get(self, request: HttpRequest, id):
|
|
|
|
""" Handles the GET request
|
|
|
|
|
|
|
|
Performs the fetching and serialization of the data
|
|
|
|
|
|
|
|
Args:
|
|
|
|
request (HttpRequest): The incoming request
|
|
|
|
id (str): The entries id
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
try:
|
2022-01-24 10:31:48 +01:00
|
|
|
self.serializer.prepare_lookup(id, self.user)
|
|
|
|
data = self.serializer.fetch_and_serialize()
|
2022-01-21 18:34:01 +01:00
|
|
|
except Exception as e:
|
|
|
|
return self.return_error_response(e, 500)
|
|
|
|
return JsonResponse(data)
|
|
|
|
|
2022-01-21 15:26:08 +01:00
|
|
|
|
2022-01-24 10:31:48 +01:00
|
|
|
class InterventionAPIViewV1(AbstractModelAPIViewV1):
|
|
|
|
serializer = InterventionAPISerializerV1
|
2022-01-21 15:26:08 +01:00
|
|
|
|
|
|
|
|
2022-01-24 10:31:48 +01:00
|
|
|
class CompensationAPIViewV1(AbstractModelAPIViewV1):
|
|
|
|
serializer = CompensationAPISerializerV1
|
2022-01-21 15:26:08 +01:00
|
|
|
|
|
|
|
|
2022-01-24 10:31:48 +01:00
|
|
|
class EcoAccountAPIViewV1(AbstractModelAPIViewV1):
|
|
|
|
serializer = EcoAccountAPISerializerV1
|
2022-01-21 18:34:01 +01:00
|
|
|
|
|
|
|
|
2022-01-24 10:31:48 +01:00
|
|
|
class EmaAPIViewV1(AbstractModelAPIViewV1):
|
|
|
|
serializer = EmaAPISerializerV1
|