Skip to content

Commit

Permalink
fix(api): exchangeAccounts endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeannesson committed Oct 20, 2023
1 parent 4c11e7a commit 62d24d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
16 changes: 15 additions & 1 deletion django_napse/api/exchanges/views/exchange_account_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def create(self, request):
return Response({"error": "Missing exchange"}, status=status.HTTP_400_BAD_REQUEST)
if "testing" not in request.data:
return Response({"error": "Missing testing"}, status=status.HTTP_400_BAD_REQUEST)
print(request.data)
exchange = Exchange.objects.get(name=request.data["exchange"])
exchange_account = ExchangeAccount.objects.create(
exchange=exchange,
Expand All @@ -53,6 +52,21 @@ def create(self, request):
serializer = self.get_serializer(exchange_account)
return Response(serializer.data, status=status.HTTP_201_CREATED)

def destroy(self, request, pk=None):
instance = self.get_object()
instance.delete()
return Response(status=status.HTTP_204_NO_CONTENT)

def patch(self, request, pk=None):
instance = self.get_object()
if "name" in request.data:
instance.name = request.data["name"]
if "description" in request.data:
instance.description = request.data["description"]
instance.save()
serializer = self.get_serializer(instance)
return Response(serializer.data, status=status.HTTP_200_OK)

@action(detail=False, methods=["GET"])
def possible_exchanges(self, request):
return Response(list(EXCHANGES), status=status.HTTP_200_OK)
16 changes: 8 additions & 8 deletions django_napse/api/keys/views/key_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def create(self, request):

return Response({"key": key}, status=status.HTTP_201_CREATED)

def retrieve(self, request, pk):
key = self.get_object()
if "space" not in request.query_params:
serializer = NapseAPIKeySerializer(key)
return Response(serializer.data, status=status.HTTP_200_OK)
serializer = NapseAPIKeySpaceSerializer(key, context={"space": request.query_params["space"]})
return Response(serializer.data, status=status.HTTP_200_OK)

def list(self, request):
keys = self.get_queryset()
if "space" not in request.query_params:
Expand All @@ -53,14 +61,6 @@ def list(self, request):
data["master_key"] = serializer.data
return Response(data, status=status.HTTP_200_OK)

def retrieve(self, request, pk):
key = self.get_object()
if "space" not in request.query_params:
serializer = NapseAPIKeySerializer(key)
return Response(serializer.data, status=status.HTTP_200_OK)
serializer = NapseAPIKeySpaceSerializer(key, context={"space": request.query_params["space"]})
return Response(serializer.data, status=status.HTTP_200_OK)

def destroy(self, request, pk):
key = self.get_object()
key.delete()
Expand Down

0 comments on commit 62d24d5

Please sign in to comment.