From 9908683e45b40a6a72ce3380f986dfe773e7b59b Mon Sep 17 00:00:00 2001 From: Stef Date: Wed, 3 Sep 2025 16:05:01 +0200 Subject: [PATCH] Added a function that turns a service instance into a dictionary. --- models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/models.py b/models.py index fe1ae50..4ecb55d 100644 --- a/models.py +++ b/models.py @@ -1,6 +1,7 @@ from mem import db from datetime import datetime, timezone from validators import url as is_url +from typing import Any class log(db.Model): @@ -25,8 +26,19 @@ class service(db.Model): ): if not is_url(url): raise Exception("URL IS NOT A VALID URL") + if len(label) > 15: + raise Exception("LABEL EXCEEDS MAXIMUM LENGTH (15)") super().__init__() self.url = url self.label = label self.public_access = public_access self.ping_method = ping_method + + def to_dict(self) -> dict[str, Any]: + return { + "url": self.url, + "public_access": self.public_access, + "label": self.label, + "id": self.id, + "ping_method": self.ping_method, + }