Skip to content

Commit

Permalink
Validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Sánchez committed May 25, 2021
1 parent 2261434 commit ed2ee39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions fast_agave/blueprints/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def retrieve_object(
self, resource_class: Any, resource_id: str
) -> Any:
query = Q(id=resource_id)
if self.user_id_filter_required():
if self.user_id_filter_required() and hasattr(resource_class.model, 'user_id'):
query = query & Q(user_id=self.current_user_id)
try:
data = await resource_class.model.objects.async_get(query)
Expand Down Expand Up @@ -73,8 +73,12 @@ def wrapper_resource_class(cls):
Use "delete" method (if exists) to create the FastApi endpoint
"""
if hasattr(cls, 'delete'):
route = self.delete(path + '/{id}')
route(cls.delete)

@self.delete(path + '/{id}')
@copy_attributes(cls)
async def delete(id: str):
obj = await self.retrieve_object(cls, id)
return await cls.delete(obj)

""" PATCH /resource/{id}
Enable PATCH method if Resource.update method exist. It validates
Expand Down
2 changes: 1 addition & 1 deletion fast_agave/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.2.dev3'
__version__ = '0.0.2.dev4'

0 comments on commit ed2ee39

Please sign in to comment.