2022-08-19 10:35:05 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2022-08-22 02:01:56 +00:00
|
|
|
from frog_api.models import Entry, Measure, Project, Version
|
2022-08-19 10:35:05 +00:00
|
|
|
|
|
|
|
|
2022-08-21 11:25:44 +00:00
|
|
|
class VersionSerializer(serializers.HyperlinkedModelSerializer):
|
2022-08-19 10:35:05 +00:00
|
|
|
class Meta:
|
2022-08-21 11:25:44 +00:00
|
|
|
model = Version
|
2022-08-19 10:35:05 +00:00
|
|
|
fields = ["slug", "name"]
|
|
|
|
|
|
|
|
|
2022-08-21 11:25:44 +00:00
|
|
|
class ProjectSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
versions = VersionSerializer(many=True)
|
|
|
|
|
2022-08-19 10:35:05 +00:00
|
|
|
class Meta:
|
2022-08-21 11:25:44 +00:00
|
|
|
model = Project
|
2022-08-26 10:18:58 +00:00
|
|
|
fields = [
|
|
|
|
"slug",
|
|
|
|
"name",
|
|
|
|
"versions",
|
|
|
|
"repository",
|
|
|
|
"discord",
|
|
|
|
"website",
|
|
|
|
]
|
2022-08-19 10:35:05 +00:00
|
|
|
|
|
|
|
|
2022-08-22 02:01:56 +00:00
|
|
|
class MeasureSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Measure
|
|
|
|
fields = ["type", "value"]
|
|
|
|
|
|
|
|
|
2022-08-19 10:35:05 +00:00
|
|
|
class EntrySerializer(serializers.HyperlinkedModelSerializer):
|
2022-08-26 02:16:04 +00:00
|
|
|
measures = serializers.SerializerMethodField()
|
2022-08-21 11:25:44 +00:00
|
|
|
|
2022-08-26 02:16:04 +00:00
|
|
|
def get_measures(self, instance: Entry) -> dict[str, int]:
|
|
|
|
return {m.type: m.value for m in instance.measures.all()}
|
2022-08-22 02:01:56 +00:00
|
|
|
|
2022-08-21 11:25:44 +00:00
|
|
|
class Meta:
|
|
|
|
model = Entry
|
|
|
|
fields = [
|
|
|
|
"timestamp",
|
2022-08-26 02:16:04 +00:00
|
|
|
"git_hash",
|
2022-08-22 02:01:56 +00:00
|
|
|
"measures",
|
2022-08-21 11:25:44 +00:00
|
|
|
]
|