mirror of
https://github.com/Manuel83/craftbeerpi3
synced 2026-08-10 02:55:27 +02:00
First Refactoring
- Major API Changes in Core Module - Will be changed further. Still work in progress
This commit is contained in:
@@ -1,30 +1,46 @@
|
||||
import json
|
||||
from flask_classy import FlaskView, route
|
||||
from modules import cbpi
|
||||
from modules.core.core import cbpi
|
||||
|
||||
class NotificationView(FlaskView):
|
||||
|
||||
@route('/', methods=['GET'])
|
||||
def getMessages(self):
|
||||
"""
|
||||
Get all messages
|
||||
:return: current messages
|
||||
Get all Messages
|
||||
---
|
||||
tags:
|
||||
- notification
|
||||
responses:
|
||||
200:
|
||||
description: All messages
|
||||
"""
|
||||
|
||||
return json.dumps(cbpi.cache["messages"])
|
||||
|
||||
@route('/<id>', methods=['DELETE'])
|
||||
def dismiss(self, id):
|
||||
"""
|
||||
Delete message from cache by id
|
||||
:param id: message id to be deleted
|
||||
:return: empty response HTTP 204
|
||||
Delete Message
|
||||
---
|
||||
tags:
|
||||
- notification
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
required: true
|
||||
description: Numeric ID of the message
|
||||
responses:
|
||||
200:
|
||||
description: Message deleted
|
||||
"""
|
||||
for idx, m in enumerate(cbpi.cache.get("messages", [])):
|
||||
if (m.get("id") == id):
|
||||
cbpi.cache["messages"].pop(idx)
|
||||
return ('', 204)
|
||||
|
||||
@cbpi.event("MESSAGE", async=True)
|
||||
#@cbpi.event("MESSAGE", async=True)
|
||||
def messageEvent(message, **kwargs):
|
||||
"""
|
||||
React on message event. add the message to the cache and push the message to the clients
|
||||
@@ -36,7 +52,7 @@ def messageEvent(message, **kwargs):
|
||||
cbpi.cache["messages"].append(message)
|
||||
cbpi.emit("NOTIFY", message)
|
||||
|
||||
@cbpi.initalizer(order=2)
|
||||
@cbpi.addon.core.initializer(order=2)
|
||||
def init(cbpi):
|
||||
"""
|
||||
Initializer for the message module
|
||||
@@ -47,4 +63,4 @@ def init(cbpi):
|
||||
msg = {"id": len(cbpi.cache["messages"]), "type": "info", "headline": "Support CraftBeerPi with your donation", "message": "You will find the PayPay Donation button in the system menu" , "read": False}
|
||||
cbpi.cache["messages"].append(msg)
|
||||
|
||||
NotificationView.register(cbpi.app, route_base='/api/notification')
|
||||
NotificationView.register(cbpi._app, route_base='/api/notification')
|
||||
|
||||
Reference in New Issue
Block a user