Skip to content

Commit 148dd42

Browse files
committed
segment type and type specific data in graphql api
1 parent 08200b4 commit 148dd42

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

cesnet_service_path_plugin/graphql/filters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ class SegmentFilter(NetBoxModelFilterMixin):
4242
provider_segment_contract: FilterLookup[str] | None = strawberry_django.filter_field()
4343
comments: FilterLookup[str] | None = strawberry_django.filter_field()
4444

45-
# Path geometry fields - these are the key ones you're missing
45+
# Segment type field
46+
segment_type: FilterLookup[str] | None = strawberry_django.filter_field()
47+
48+
# Path geometry fields
4649
path_length_km: FilterLookup[float] | None = strawberry_django.filter_field()
4750
path_source_format: FilterLookup[str] | None = strawberry_django.filter_field()
4851
path_notes: FilterLookup[str] | None = strawberry_django.filter_field()

cesnet_service_path_plugin/graphql/types.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# 1. First, let's update your types.py to ensure it's importing correctly
2-
# cesnet_service_path_plugin/graphql/types.py
3-
41
from typing import Annotated, List, Optional
52

63
from circuits.graphql.types import CircuitType, ProviderType
@@ -45,6 +42,11 @@ class SegmentType(NetBoxObjectType):
4542
install_date: auto
4643
termination_date: auto
4744
status: auto
45+
46+
# Segment type fields
47+
segment_type: auto
48+
type_specific_data: auto
49+
4850
provider: Annotated["ProviderType", lazy("circuits.graphql.types")] | None
4951
provider_segment_id: auto
5052
provider_segment_name: auto
@@ -72,6 +74,36 @@ def has_path_data(self) -> bool:
7274
# Fallback: check if path_geometry field has data
7375
return bool(self.path_geometry)
7476

77+
@field
78+
def segment_type_display(self) -> Optional[str]:
79+
"""Display name for segment type"""
80+
if hasattr(self, "get_segment_type_display"):
81+
return self.get_segment_type_display()
82+
return None
83+
84+
@field
85+
def type_specific_display(self) -> Optional[strawberry.scalars.JSON]:
86+
"""Formatted display of type-specific data"""
87+
if hasattr(self, "get_type_specific_display"):
88+
return self.get_type_specific_display()
89+
return None
90+
91+
@field
92+
def type_specific_schema(self) -> Optional[strawberry.scalars.JSON]:
93+
"""Schema for the segment's type"""
94+
from cesnet_service_path_plugin.models.segment_types import SEGMENT_TYPE_SCHEMAS
95+
96+
if self.segment_type:
97+
return SEGMENT_TYPE_SCHEMAS.get(self.segment_type, {})
98+
return None
99+
100+
@field
101+
def has_type_specific_data(self) -> bool:
102+
"""Whether this segment has type-specific data"""
103+
if hasattr(self, "has_type_specific_data"):
104+
return self.has_type_specific_data()
105+
return bool(self.type_specific_data)
106+
75107
@field
76108
def path_geometry_geojson(self) -> Optional[strawberry.scalars.JSON]:
77109
"""Path geometry as GeoJSON Feature"""

0 commit comments

Comments
 (0)