Skip to content

Commit

Permalink
Merge pull request #1041 from centerofci/introduce-abstractions-api-n…
Browse files Browse the repository at this point in the history
…amespace

Introduce ui and db API namespaces
  • Loading branch information
kgodey authored Feb 10, 2022
2 parents 7018ca0 + 42d1ed3 commit d010e11
Show file tree
Hide file tree
Showing 29 changed files with 361 additions and 343 deletions.
Empty file added mathesar/api/db/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions mathesar/api/db/viewsets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from mathesar.api.db.viewsets.columns import ColumnViewSet # noqa
from mathesar.api.db.viewsets.constraints import ConstraintViewSet # noqa
from mathesar.api.db.viewsets.data_files import DataFileViewSet # noqa
from mathesar.api.db.viewsets.databases import DatabaseViewSet # noqa
from mathesar.api.db.viewsets.records import RecordViewSet # noqa
from mathesar.api.db.viewsets.schemas import SchemaViewSet # noqa
from mathesar.api.db.viewsets.tables import TableViewSet # noqa
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from rest_framework.response import Response

from mathesar.models import Database
from mathesar.api.filters import DatabaseFilter
from mathesar.api.dj_filters import DatabaseFilter
from mathesar.api.pagination import DefaultLimitOffsetPagination

from mathesar.api.serializers.databases import DatabaseSerializer, TypeSerializer
from mathesar.api.serializers.databases import DatabaseSerializer

from db.functions.operations.check_support import get_supported_db_functions
from mathesar.api.serializers.functions import DBFunctionSerializer
Expand All @@ -26,12 +26,6 @@ class DatabaseViewSet(viewsets.GenericViewSet, ListModelMixin, RetrieveModelMixi
def get_queryset(self):
return Database.objects.all().order_by('-created_at')

@action(methods=['get'], detail=True)
def types(self, request, pk=None):
database = self.get_object()
serializer = TypeSerializer(database.supported_types, many=True)
return Response(serializer.data)

@action(methods=['get'], detail=True)
def functions(self, request, pk=None):
database = self.get_object()
Expand All @@ -41,7 +35,7 @@ def functions(self, request, pk=None):
return Response(serializer.data)

@action(methods=['get'], detail=True)
def db_types(self, request, pk=None):
def types(self, request, pk=None):
database = self.get_object()
engine = database._sa_engine
available_known_db_types = get_available_known_db_types(engine)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.response import Response

from mathesar.api.filters import SchemaFilter
from mathesar.api.dj_filters import SchemaFilter
from mathesar.api.pagination import DefaultLimitOffsetPagination
from mathesar.api.serializers.schemas import SchemaSerializer
from mathesar.models import Schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from mathesar.api.exceptions.generic_exceptions import base_exceptions as base_api_exceptions
from db.types.exceptions import UnsupportedTypeException
from mathesar.api.filters import TableFilter
from mathesar.api.dj_filters import TableFilter
from mathesar.api.pagination import DefaultLimitOffsetPagination
from mathesar.api.serializers.tables import TableSerializer, TablePreviewSerializer
from mathesar.models import Table
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion mathesar/api/serializers/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from rest_framework import serializers

from mathesar.api.display_options import DISPLAY_OPTIONS_BY_TYPE_IDENTIFIER
from mathesar.api.dj_filters import FILTER_OPTIONS_BY_TYPE_IDENTIFIER
from mathesar.api.exceptions.mixins import MathesarErrorMessageMixin
from mathesar.api.filters import FILTER_OPTIONS_BY_TYPE_IDENTIFIER
from mathesar.models import Database


Expand Down
Empty file added mathesar/api/ui/__init__.py
Empty file.
1 change: 1 addition & 0 deletions mathesar/api/ui/viewsets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from mathesar.api.ui.viewsets.databases import DatabaseViewSet # noqa
27 changes: 27 additions & 0 deletions mathesar/api/ui/viewsets/databases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django_filters import rest_framework as filters
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.response import Response

from mathesar.models import Database
from mathesar.api.dj_filters import DatabaseFilter
from mathesar.api.pagination import DefaultLimitOffsetPagination

from mathesar.api.serializers.databases import DatabaseSerializer, TypeSerializer


class DatabaseViewSet(viewsets.GenericViewSet, ListModelMixin, RetrieveModelMixin):
serializer_class = DatabaseSerializer
pagination_class = DefaultLimitOffsetPagination
filter_backends = (filters.DjangoFilterBackend,)
filterset_class = DatabaseFilter

def get_queryset(self):
return Database.objects.all().order_by('-created_at')

@action(methods=['get'], detail=True)
def types(self, request, pk=None):
database = self.get_object()
serializer = TypeSerializer(database.supported_types, many=True)
return Response(serializer.data)
7 changes: 0 additions & 7 deletions mathesar/api/viewsets/__init__.py

This file was deleted.

Loading

0 comments on commit d010e11

Please sign in to comment.