-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
680 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# -*- coding: utf-8 -*- | ||
from rest_framework import serializers | ||
|
||
from app.api.v1.exceptions import NotFound | ||
from app.api.v1.serializers import ApiSerializer | ||
from app.api.v1.views import DetailAPIView, FindAPIView, ListAPIView | ||
from app.definitions.models import Column | ||
|
||
|
||
class ColumnSerializer(ApiSerializer): | ||
id = serializers.SerializerMethodField() | ||
|
||
tags = serializers.ListField( | ||
child=serializers.CharField(max_length=30), | ||
max_length=10, | ||
allow_empty=True, | ||
allow_null=True, | ||
required=False, | ||
) | ||
|
||
class Meta: | ||
model = Column | ||
fields = [ | ||
'id', | ||
'name', | ||
'tags', | ||
'created_at', | ||
'updated_at', | ||
] | ||
writable_fields = ['tags'] | ||
|
||
def get_id(self, obj): | ||
return obj.object_id | ||
|
||
def validate_tags(self, tags): | ||
return list(set(tags)) if isinstance(tags, (list,)) else [] | ||
|
||
def update(self, instance, validated_data): | ||
instance.tags = validated_data.get('tags', instance.tags) | ||
instance.save() | ||
return instance | ||
|
||
|
||
class ColumnList(ListAPIView): | ||
serializer_class = ColumnSerializer | ||
|
||
def get_queryset(self): | ||
filter_kwargs = { | ||
'table_id': self.kwargs['table_id'], | ||
'workspace': self.request.workspace, | ||
} | ||
return Column.objects.filter(**filter_kwargs) | ||
|
||
|
||
class ColumnDetail(DetailAPIView): | ||
serializer_class = ColumnSerializer | ||
|
||
def get_object(self, pk): | ||
get_kwargs = { | ||
'workspace': self.request.workspace, | ||
'object_id': pk, | ||
} | ||
try: | ||
return Column.objects.get(**get_kwargs) | ||
except Column.DoesNotExist: | ||
raise NotFound() | ||
|
||
|
||
class ColumnFind(FindAPIView): | ||
serializer_class = ColumnSerializer | ||
|
||
required_query_params = ['schema', 'table', 'name'] | ||
|
||
def find_object(self, datastore_id, query_params): | ||
filter_kwargs = { | ||
'workspace': self.request.workspace, | ||
'table__schema__datastore_id': datastore_id, | ||
'table__schema__name': query_params['schema'], | ||
'table__name': query_params['table'], | ||
'name': query_params['name'], | ||
} | ||
return Column.objects.filter(**filter_kwargs).first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# # -*- coding: utf-8 -*- | ||
# from rest_framework.decorators import api_view, permission_classes | ||
# from rest_framework.response import Response | ||
|
||
# from app.api.permissions import IsAuthenticated | ||
|
||
|
||
# @api_view(['GET']) | ||
# @permission_classes([IsAuthenticated]) | ||
# def get_datastores(request, format=None): | ||
# """GET /api/v1/datastores | ||
# """ | ||
# content = { | ||
# 'status': 'request was permitted' | ||
# } | ||
# return Response(content) | ||
|
||
|
||
# @api_view(['GET']) | ||
# @permission_classes([IsAuthenticated]) | ||
# def get_datastore(request, format=None): | ||
# """GET /api/v1/datastores/:datastoreId | ||
# """ | ||
# content = { | ||
# 'status': 'request was permitted' | ||
# } | ||
# return Response(content) | ||
|
||
|
||
# @api_view(['GET']) | ||
# @permission_classes([IsAuthenticated]) | ||
# def get_datastore_tables(request, format=None): | ||
# """GET /api/v1/datastores/:datastoreId/tables | ||
# """ | ||
# content = { | ||
# 'status': 'request was permitted' | ||
# } | ||
# return Response(content) | ||
|
||
|
||
# @api_view(['PATCH']) | ||
# @permission_classes([IsAuthenticated]) | ||
# def update_datastore(request, format=None): | ||
# """PATCH /api/v1/datastores/:datastoreId | ||
# """ | ||
# content = { | ||
# 'status': 'request was permitted' | ||
# } | ||
# return Response(content) | ||
|
||
|
||
# @api_view(['PATCH']) | ||
# @permission_classes([IsAuthenticated]) | ||
# def update_datastore_properties(request, format=None): | ||
# """PATCH /api/v1/datastores/:datastoreId/properties | ||
# """ | ||
# content = { | ||
# 'status': 'request was permitted' | ||
# } | ||
# return Response(content) | ||
|
||
|
||
# @api_view(['PATCH']) | ||
# @permission_classes([IsAuthenticated]) | ||
# def update_datastore_owners(request, format=None): | ||
# """PATCH /api/v1/datastores/:datastoreId/owners | ||
# """ | ||
# content = { | ||
# 'status': 'request was permitted' | ||
# } | ||
# return Response(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# -*- coding: utf-8 -*- | ||
from rest_framework import serializers | ||
|
||
from app.api.v1.exceptions import NotFound | ||
from app.api.v1.serializers import ApiSerializer | ||
from app.api.v1.views import DetailAPIView, FindAPIView, ListAPIView | ||
from app.definitions.models import Schema | ||
|
||
|
||
class SchemaSerializer(ApiSerializer): | ||
id = serializers.SerializerMethodField() | ||
|
||
tags = serializers.ListField( | ||
child=serializers.CharField(max_length=30), | ||
max_length=10, | ||
allow_empty=True, | ||
allow_null=True, | ||
required=False, | ||
) | ||
|
||
class Meta: | ||
model = Schema | ||
fields = [ | ||
'id', | ||
'name', | ||
'tags', | ||
'created_at', | ||
'updated_at', | ||
] | ||
writable_fields = ['tags'] | ||
|
||
def get_id(self, obj): | ||
return obj.object_id | ||
|
||
def validate_tags(self, tags): | ||
return list(set(tags)) if isinstance(tags, (list,)) else [] | ||
|
||
def update(self, instance, validated_data): | ||
instance.tags = validated_data.get('tags', instance.tags) | ||
instance.save() | ||
return instance | ||
|
||
|
||
class SchemaList(ListAPIView): | ||
serializer_class = SchemaSerializer | ||
|
||
def get_queryset(self): | ||
filter_kwargs = { | ||
'datastore_id': self.kwargs['datastore_id'], | ||
'workspace': self.request.workspace, | ||
} | ||
return Schema.objects.filter(**filter_kwargs) | ||
|
||
|
||
class SchemaDetail(DetailAPIView): | ||
serializer_class = SchemaSerializer | ||
|
||
def get_object(self, pk): | ||
get_kwargs = { | ||
'workspace': self.request.workspace, | ||
'object_id': pk, | ||
} | ||
try: | ||
return Schema.objects.get(**get_kwargs) | ||
except Schema.DoesNotExist: | ||
raise NotFound() | ||
|
||
|
||
class SchemaFind(FindAPIView): | ||
serializer_class = SchemaSerializer | ||
|
||
required_query_params = ['name'] | ||
|
||
def find_object(self, datastore_id, query_params): | ||
filter_kwargs = { | ||
'datastore_id': datastore_id, | ||
'workspace': self.request.workspace, | ||
'name': query_params['name'], | ||
} | ||
return Schema.objects.filter(**filter_kwargs).first() |
Oops, something went wrong.