2022-08-27 06:34:59 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
from frog_api.models import AUTH_KEY_LEN
|
2022-09-22 20:40:44 +00:00
|
|
|
from frog_api.serializers.model_serializers import ProjectSerializer
|
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()
|
2022-09-22 20:40:44 +00:00
|
|
|
name = serializers.CharField()
|
|
|
|
|
|
|
|
|
|
|
|
class CreateCategorySerializer(serializers.Serializer): # type:ignore
|
|
|
|
api_key = ApiKeySerializer()
|
|
|
|
name = serializers.CharField()
|
2022-08-28 13:59:52 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|