Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 6 additions & 36 deletions fastapi_jsonapi/data_layers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
you must inherit from this base class
"""

import types
from typing import Dict, List, Optional, Tuple, Type

from fastapi import Request

from fastapi_jsonapi.data_typing import TypeModel, TypeSchema
from fastapi_jsonapi.querystring import QueryStringManager
from fastapi_jsonapi.schema import BaseJSONAPIItemInSchema
Expand All @@ -16,31 +17,9 @@
class BaseDataLayer:
"""Base class of a data layer"""

REWRITABLE_METHODS = (
"query",
"before_create_object",
"after_create_object",
"before_get_object",
"after_get_object",
"before_get_collection",
"after_get_collection",
"before_update_object",
"after_update_object",
"before_delete_object",
"after_delete_object",
"before_create_relationship",
"after_create_relationship",
"before_get_relationship",
"after_get_relationship",
"before_update_relationship",
"after_update_relationship",
"before_delete_relationship",
"after_delete_relationship",
"retrieve_object_query",
)

def __init__(
self,
request: Request,
schema: Type[TypeSchema],
model: Type[TypeModel],
url_id_field: str,
Expand All @@ -51,7 +30,7 @@ def __init__(
**kwargs,
):
"""

:param request:
:param schema:
:param model:
:param url_id_field:
Expand All @@ -61,8 +40,9 @@ def __init__(
:param type_: resource type
:param kwargs:
"""
self.model = model
self.request = request
self.schema = schema
self.model = model
self.url_id_field = url_id_field
self.id_name_field = id_name_field
self.disable_collection_count: bool = disable_collection_count
Expand Down Expand Up @@ -561,13 +541,3 @@ async def after_delete_relationship(
:param view_kwargs: kwargs from the resource view
"""
raise NotImplementedError

def bound_rewritable_methods(self, methods):
"""
Bound additional methods to current instance

:param class methods: methods
"""
for key, value in methods.items():
if key in self.REWRITABLE_METHODS:
setattr(self, key, types.MethodType(value, self))
1 change: 1 addition & 0 deletions fastapi_jsonapi/views/view_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self, *, request: Request, jsonapi: RoutersJSONAPI, **options):

def _get_data_layer(self, schema: Type[BaseModel], **dl_kwargs):
return self.data_layer_cls(
request=self.request,
schema=schema,
model=self.jsonapi.model,
type_=self.jsonapi.type_,
Expand Down