Added/deleted-type websocket messages

Events are now sent for not only when an object changes but also when one is created or deleted.

For now it's not really possible to subscribe to these events however.

This breaks backwards-compatibility with the websocket messages.
This commit is contained in:
Donkie
2023-10-15 19:46:10 +02:00
parent 3c5b3cea5a
commit a6d527aaf0
6 changed files with 92 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
"""Pydantic data models for typing the FastAPI request/responses."""
from datetime import datetime, timezone
from enum import Enum
from typing import Optional
from pydantic import BaseModel as PydanticBaseModel
@@ -228,3 +229,37 @@ class BackupResponse(BaseModel):
description="Path to the created backup file.",
example="/home/app/.local/share/spoolman/backups/spoolman.db",
)
class EventType(str, Enum):
"""Event types."""
ADDED = "added"
UPDATED = "updated"
DELETED = "deleted"
class Event(BaseModel):
"""Event."""
type: EventType = Field(description="Event type.")
date: datetime = Field(description="When the event occured. UTC Timezone.")
payload: BaseModel
class SpoolEvent(Event):
"""Event."""
payload: Spool = Field(description="Updated spool.")
class FilamentEvent(Event):
"""Event."""
payload: Filament = Field(description="Updated filament.")
class VendorEvent(Event):
"""Event."""
payload: Vendor = Field(description="Updated vendor.")