Skip to content

Commit 48ba427

Browse files
committed
added satellite model
1 parent 3a71de5 commit 48ba427

4 files changed

Lines changed: 181 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from enum import Enum
2+
3+
class AccessTypeEnum(str, Enum):
4+
PUBLIC = "PUBLIC"
5+
PRIVATE = "PRIVATE"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import jsonschema
2+
3+
from beanie import Document, Indexed, before_event, Replace, Save, Link
4+
from datetime import datetime
5+
from pydantic import Field, Any, field_validator
6+
from .access_types import AccessTypeEnum
7+
8+
from app.project.models.project_database_model import Project
9+
10+
11+
class Satellite(Document):
12+
13+
name: Indexed(str, unique=True) = Field(..., description="Name of the satellite")
14+
15+
friendly_name: str = Field(..., description="Friendly name of the satellite")
16+
17+
description: str = Field(..., description="Description of the satellite")
18+
19+
access_type: AccessTypeEnum = Field(..., description="Access type of the satellite")
20+
21+
configs: dict[str, Any] = Field(..., description="Configurations of the satellite, a valid jsonschema object for the configs")
22+
inputs: dict[str, Any] = Field(..., description="Input data fothe satellite, a valid jsonschema object for the inputs")
23+
metrics: dict[str, Any] = Field(..., description="Metrics of the satellite, a valid jsonschema object for the metrics")
24+
outputs: dict[str, Any] = Field(..., description="Outputs of the satellite, a valid jsonschema object for the outputs")
25+
26+
project: Link[Project] = Field(..., description="Project of the satellite")
27+
28+
created_at: datetime = Field(default_factory=datetime.now, description="Date and time when the satellite was created")
29+
30+
updated_at: datetime = Field(default_factory=datetime.now, description="Date and time when the satellite was last updated")
31+
32+
33+
@field_validator("configs", "inputs", "metrics", "outputs")
34+
def validate_jsonschema(cls, v: dict[str, Any]) -> dict[str, Any]:
35+
validator = jsonschema.validators.validator_for(v)
36+
37+
try:
38+
validator.check_schema(v)
39+
except jsonschema.exceptions.SchemaError as e:
40+
raise ValueError(f"Invalid JSON schema: {e.message}")
41+
42+
return v
43+
44+
45+
@before_event([Save, Replace])
46+
def update_updated_at(self):
47+
self.updated_at = datetime.now()

api-server/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies = [
88
"bcrypt>=4.3.0",
99
"beanie>=1.30.0",
1010
"fastapi>=0.115.14",
11+
"jsonschema>=4.24.0",
1112
"pyjwt>=2.10.1",
1213
"python-dotenv>=1.1.1",
1314
"structlog>=25.4.0",

0 commit comments

Comments
 (0)