Skip to content

Commit

Permalink
feat(histories): added serializers and updated space view
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeannesson committed Mar 11, 2024
1 parent 4ff9a64 commit a267240
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
Empty file.
18 changes: 18 additions & 0 deletions django_napse/api/histories/serializers/datapoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from typing import ClassVar

from rest_framework import serializers

from django_napse.api.histories.serializers.datapoint_field import HistoryDataPointFieldSerializer
from django_napse.core.models.histories.history import HistoryDataPoint


class HistoryDataPointSerializer(serializers.ModelSerializer):
"""Serialize a wallet instance."""

fields = HistoryDataPointFieldSerializer(many=True)

class Meta: # noqa: D106
model = HistoryDataPoint
fields: ClassVar[list[str]] = ["created_at", "fields"]
13 changes: 13 additions & 0 deletions django_napse/api/histories/serializers/datapoint_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations

from rest_framework import serializers

from django_napse.core.models.histories.history import HistoryDataPointField


class HistoryDataPointFieldSerializer(serializers.ModelSerializer):
"""Serialize a wallet instance."""

class Meta: # noqa: D106
model = HistoryDataPointField
fields: str = ["key", "value", "target_type"]
21 changes: 21 additions & 0 deletions django_napse/api/histories/serializers/history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations

from typing import ClassVar

from rest_framework import serializers

from django_napse.api.histories.serializers.datapoint import HistoryDataPointSerializer
from django_napse.core.models.histories.history import History


class HistorySerializer(serializers.ModelSerializer):
"""Serialize a wallet instance."""

data_points = HistoryDataPointSerializer(many=True)

class Meta: # noqa: D106
model = History
fields: ClassVar[list[str]] = [
"uuid",
"data_points",
]
5 changes: 4 additions & 1 deletion django_napse/api/wallets/serializers/wallet_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db.models import Q
from rest_framework import serializers

from django_napse.api.histories.serializers.history import HistorySerializer
from django_napse.api.transactions.serializers import CreditSerializer, DebitSerializer, TransactionSerializer
from django_napse.api.wallets.serializers.currency_serializer import CurrencySerializer
from django_napse.core.models import Transaction, Wallet
Expand All @@ -16,15 +17,17 @@ class WalletSerializer(serializers.ModelSerializer):
currencies = CurrencySerializer(many=True, read_only=True)
value = serializers.SerializerMethodField(read_only=True)
operations = serializers.SerializerMethodField(read_only=True)
history = HistorySerializer(many=False, read_only=True)

class Meta:
class Meta: # noqa: D106
model = Wallet
fields: ClassVar[list[str]] = [
"title",
"value",
"created_at",
"currencies",
"operations",
"history",
]
read_only_fields: ClassVar[list[str]] = [
"value",
Expand Down

0 comments on commit a267240

Please sign in to comment.