2022-08-27 06:34:59 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
from frog_api.models import AUTH_KEY_LEN
|
2022-08-28 13:59:52 +00:00
|
|
|
from frog_api.serializers.model_serializers import ProjectSerializer, VersionSerializer
|
2022-08-27 06:34:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ApiKeySerializer(serializers.CharField):
|
|
|
|
required = True
|
|
|
|
max_length = AUTH_KEY_LEN
|
|
|
|
|
|
|
|
|
2022-08-28 13:59:52 +00:00
|
|
|
class CreateProjectSerializer(serializers.Serializer): # type:ignore
|
|
|
|
api_key = ApiKeySerializer()
|
|
|
|
project = ProjectSerializer()
|
|
|
|
|
|
|
|
|
|
|
|
class CreateVersionSerializer(serializers.Serializer): # type:ignore
|
|
|
|
api_key = ApiKeySerializer()
|
|
|
|
version = VersionSerializer()
|
|
|
|
|
|
|
|
|
2022-08-27 12:28:16 +00:00
|
|
|
# Classes for valdating requests to create new entries
|
|
|
|
class CreateEntrySerializer(serializers.Serializer): # type:ignore
|
|
|
|
timestamp = serializers.IntegerField()
|
|
|
|
git_hash = serializers.CharField(max_length=40)
|
|
|
|
categories = serializers.DictField(
|
|
|
|
child=serializers.DictField(child=serializers.IntegerField())
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class CreateEntriesSerializer(serializers.Serializer): # type:ignore
|
|
|
|
api_key = ApiKeySerializer()
|
|
|
|
entries = serializers.ListField(
|
|
|
|
child=CreateEntrySerializer(), required=True, allow_empty=False
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-08-27 06:34:59 +00:00
|
|
|
class CreateCategoriesSerializer(serializers.Serializer): # type:ignore
|
|
|
|
api_key = ApiKeySerializer()
|
|
|
|
categories = serializers.DictField(
|
|
|
|
required=True, allow_empty=False, child=serializers.CharField()
|
|
|
|
)
|