Skip to content

Commit

Permalink
fix(history): remove history serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenepix38 committed Oct 21, 2023
1 parent 7f6d69d commit 76c467e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 40 deletions.
1 change: 0 additions & 1 deletion django_napse/api/histories/serializers/__init__.py

This file was deleted.

32 changes: 0 additions & 32 deletions django_napse/api/histories/serializers/history_serializers.py

This file was deleted.

22 changes: 15 additions & 7 deletions django_napse/api/spaces/serializers/space_serializers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from json import loads

from rest_framework import serializers

from django_napse.api.fleets.serializers import FleetSerializer
from django_napse.api.histories.serializers import HistorySerializer # noqa: F401
from django_napse.api.wallets.serializers.wallet_serializers import WalletSerializer
from django_napse.core.models import NapseSpace
from django_napse.core.models import NapseSpace, SpaceHistory


class SpaceSerializer(serializers.ModelSerializer):
Expand All @@ -15,14 +16,13 @@ class Meta:
fields = [
"name",
"description",
"exchange_account",
# read-only
"uuid",
"exchange_account",
"value",
"fleet_count",
]
read_only_fields = [
"exchange_account",
"uuid",
"value",
"fleet_count",
Expand All @@ -37,7 +37,7 @@ class SpaceDetailSerializer(serializers.ModelSerializer):
exchange_account = serializers.CharField(source="exchange_account.uuid", read_only=True)
statistics = serializers.SerializerMethodField(read_only=True)
wallet = WalletSerializer(read_only=True)
# history = HistorySerializer(read_only=True)
history = serializers.SerializerMethodField(read_only=True)

class Meta:
model = NapseSpace
Expand All @@ -50,7 +50,7 @@ class Meta:
"created_at",
"statistics",
"wallet",
# "history",
"history",
"fleets",
]
read_only_fields = [
Expand All @@ -59,9 +59,17 @@ class Meta:
"created_at",
"statistics",
"wallet",
# "history",
"history",
"fleet",
]

def get_statistics(self, instance) -> dict:
return instance.get_stats()

def get_history(self, instance) -> list:
try:
history = SpaceHistory.objects.get(owner=instance)
except SpaceHistory.DoesNotExist:
return []

return loads(history.to_dataframe().to_json(orient="records"))

0 comments on commit 76c467e

Please sign in to comment.