Skip to content
Snippets Groups Projects
Commit 002032e9 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

fix: add proper type info for radio settings API

parent 62c01d4d
No related branches found
No related tags found
No related merge requests found
Pipeline #8115 passed
......@@ -19,7 +19,7 @@
#
import re
from typing import TypedDict
from typing import NotRequired, TypedDict
from drf_jsonschema_serializer import JSONSchemaField
from rest_framework import serializers
......@@ -1085,6 +1085,25 @@ class NoteSerializer(serializers.ModelSerializer):
return instance
class RadioCBASettings(TypedDict):
api_key: NotRequired[str]
domains: list[str]
class RadioProgrammeSettings(TypedDict):
fallback_show_id: int | None
class RadioPlayoutSettings(TypedDict):
line_in_channels: dict[str, str]
class RadioStationSettings(TypedDict):
name: str
logo_id: int | None
website: str
class RadioSettingsSerializer(serializers.ModelSerializer):
cba = serializers.SerializerMethodField()
playout = serializers.SerializerMethodField()
......@@ -1096,7 +1115,7 @@ class RadioSettingsSerializer(serializers.ModelSerializer):
fields = read_only_fields
model = RadioSettings
def get_cba(self, obj) -> dict[str, str] | dict[str, list[str]]:
def get_cba(self, obj) -> RadioCBASettings:
if self.context.get("request").user.is_authenticated:
return {
"api_key": obj.cba_api_key,
......@@ -1106,15 +1125,15 @@ class RadioSettingsSerializer(serializers.ModelSerializer):
return {"domains": obj.cba_domains}
@staticmethod
def get_programme(obj) -> dict[str, int]:
def get_programme(obj) -> RadioProgrammeSettings:
return {"fallback_show_id": obj.fallback_show.id if obj.fallback_show else None}
@staticmethod
def get_playout(obj) -> dict[str, dict[str, str]]:
def get_playout(obj) -> RadioPlayoutSettings:
return {"line_in_channels": obj.line_in_channels}
@staticmethod
def get_station(obj) -> dict[str, int | str]:
def get_station(obj) -> RadioStationSettings:
return {
"name": obj.station_name,
"logo_id": obj.station_logo.id if obj.station_logo else None,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment