Beispiel #1
0
class LatestNotifications(View, Controller):
    """List and Update Latest Notifications Private Endpoint Controller"""
    def __init__(self):
        self.__notification = NotificationModule()

    @allow_if_authenticated
    def get(self, request):
        self.__user_id = request.user.id

        return self.json([],
                         self.__notification.user_latest_notifications(
                             self.__user_id))

    @allow_if_authenticated
    def post(self, request):

        self.__user_id = request.user.id

        request_data = self.get_request_data(request, "post",
                                             {"notification_id": ""})

        try:
            notification_id = int(request_data["notification_id"])
        except Exception:
            return self.json([])

        self.__notification.mark_notification(self.__user_id, notification_id)

        return self.json([])
Beispiel #2
0
class LatestNotifications(View):

    __request = None
    __response = None
    __helpers = None
    __form = None
    __logger = None
    __user_id = None
    __notification = None
    __correlation_id = None

    def __init__(self):
        self.__helpers = Helpers()
        self.__form = Form()
        self.__logger = self.__helpers.get_logger(__name__)
        self.__response = Response()
        self.__request = Request()
        self.__notification = NotificationModule()
        self.__form.add_validator(ExtraRules())

    @allow_if_authenticated
    def get(self, request):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__user_id = request.user.id

        return JsonResponse(
            self.__response.send_private_success(
                [],
                self.__notification.user_latest_notifications(self.__user_id),
                self.__correlation_id))

    @allow_if_authenticated
    def post(self, request):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__user_id = request.user.id
        self.__request.set_request(request)

        request_data = self.__request.get_request_data("post",
                                                       {"notification_id": ""})

        try:
            notification_id = int(request_data["notification_id"])
        except Exception:
            return JsonResponse(
                self.__response.send_private_success([], {},
                                                     self.__correlation_id))

        self.__notification.mark_notification(self.__user_id, notification_id)

        return JsonResponse(
            self.__response.send_private_success([], {},
                                                 self.__correlation_id))