Skip to content

Commit

Permalink
Unify star and unstar view functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt committed Feb 5, 2025
1 parent 4a02dbe commit fe47e36
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions dandiapi/api/views/dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
DandisetUnembargoInProgressError,
UnauthorizedEmbargoAccessError,
)
from dandiapi.api.services.exceptions import NotAllowedError, NotAuthenticatedError
from dandiapi.api.services.exceptions import DandiError, NotAllowedError, NotAuthenticatedError
from dandiapi.api.services.permissions.dandiset import (
get_dandiset_owners,
get_owned_dandisets,
Expand Down Expand Up @@ -610,13 +610,8 @@ def clear_uploads(self, request, dandiset__pk):
operation_summary='Star a dandiset.',
operation_description='Star a dandiset. User must be authenticated.',
)
@action(methods=['POST'], detail=True)
def star(self, request, dandiset__pk) -> Response:
dandiset = self.get_object()
star_count = star_dandiset(user=request.user, dandiset=dandiset)
return Response({'count': star_count}, status=status.HTTP_200_OK)

@swagger_auto_schema(
methods=['DELETE'],
manual_parameters=[DANDISET_PK_PARAM],
request_body=no_body,
responses={
Expand All @@ -626,8 +621,16 @@ def star(self, request, dandiset__pk) -> Response:
operation_summary='Unstar a dandiset.',
operation_description='Unstar a dandiset. User must be authenticated.',
)
@star.mapping.delete
def unstar(self, request, dandiset__pk) -> Response:
@action(methods=['POST', 'DELETE'], detail=True)
def star(self, request, dandiset__pk) -> Response:
dandiset = self.get_object()
star_count = unstar_dandiset(user=request.user, dandiset=dandiset)
if request.method == 'POST':
star_count = star_dandiset(user=request.user, dandiset=dandiset)
elif request.method == 'DELETE':
star_count = unstar_dandiset(user=request.user, dandiset=dandiset)
else:
raise DandiError(
message='Method not allowed.', http_status_code=status.HTTP_405_METHOD_NOT_ALLOWED
)

return Response({'count': star_count}, status=status.HTTP_200_OK)

0 comments on commit fe47e36

Please sign in to comment.