Skip to content

Commit

Permalink
Use DELETE rest method for dandiset un-star
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt committed Feb 5, 2025
1 parent c35352d commit afe79a3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
6 changes: 2 additions & 4 deletions dandiapi/api/tests/test_dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,7 @@ def test_dandiset_rest_create_with_contributor(api_client, admin_user):
'version': 'draft',
'url': url,
'dateCreated': UTC_ISO_TIMESTAMP_RE,
'citation': (
f'Jane Doe ({year}) {name} ' f'(Version draft) [Data set]. DANDI Archive. {url}'
),
'citation': (f'Jane Doe ({year}) {name} (Version draft) [Data set]. DANDI Archive. {url}'),
'@context': f'https://raw.githubusercontent.com/dandi/schema/master/releases/{settings.DANDI_SCHEMA_VERSION}/context.json',
'schemaVersion': settings.DANDI_SCHEMA_VERSION,
'schemaKey': 'Dandiset',
Expand Down Expand Up @@ -1268,7 +1266,7 @@ def test_dandiset_unstar(api_client, user, dandiset):
assert dandiset.stars.count() == 1

# Then unstar it
response = api_client.post(f'/api/dandisets/{dandiset.identifier}/unstar/')
response = api_client.delete(f'/api/dandisets/{dandiset.identifier}/star/')
assert response.status_code == 200
assert response.data == {'count': 0}
assert dandiset.stars.count() == 0
Expand Down
3 changes: 1 addition & 2 deletions dandiapi/api/views/dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ def star(self, request, dandiset__pk) -> Response:
return Response({'count': star_count}, status=status.HTTP_200_OK)

@swagger_auto_schema(
methods=['POST'],
manual_parameters=[DANDISET_PK_PARAM],
request_body=no_body,
responses={
Expand All @@ -627,7 +626,7 @@ def star(self, request, dandiset__pk) -> Response:
operation_summary='Unstar a dandiset.',
operation_description='Unstar a dandiset. User must be authenticated.',
)
@action(methods=['POST'], detail=True)
@star.mapping.delete
def unstar(self, request, dandiset__pk) -> Response:
dandiset = self.get_object()
star_count = unstar_dandiset(user=request.user, dandiset=dandiset)
Expand Down
2 changes: 1 addition & 1 deletion web/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const dandiRest = {
await client.post(`dandisets/${identifier}/star/`);
},
async unstarDandiset(identifier: string): Promise<void> {
await client.post(`dandisets/${identifier}/unstar/`);
await client.delete(`dandisets/${identifier}/star/`);
},
};

Expand Down

0 comments on commit afe79a3

Please sign in to comment.