fix(schema):add subscriptions_count in channel

This commit is contained in:
Petitminion 2025-03-27 01:34:55 +01:00
parent 0b2e457052
commit f9d9376aa4
3 changed files with 9 additions and 2 deletions

View File

@ -263,6 +263,7 @@ class ChannelSerializer(serializers.ModelSerializer):
attributed_to = federation_serializers.APIActorSerializer()
rss_url = serializers.CharField(source="get_rss_url")
url = serializers.SerializerMethodField()
subscriptions_count = serializers.SerializerMethodField()
class Meta:
model = models.Channel
@ -276,6 +277,7 @@ class ChannelSerializer(serializers.ModelSerializer):
"rss_url",
"url",
"downloads_count",
"subscriptions_count",
]
def to_representation(self, obj):
@ -284,6 +286,7 @@ class ChannelSerializer(serializers.ModelSerializer):
data["subscriptions_count"] = self.get_subscriptions_count(obj)
return data
@extend_schema_field(OpenApiTypes.INT)
def get_subscriptions_count(self, obj) -> int:
return obj.actor.received_follows.exclude(approved=False).count()

View File

@ -20288,12 +20288,16 @@ components:
downloads_count:
type: integer
readOnly: true
subscriptions_count:
type: integer
readOnly: true
required:
- actor
- artist
- attributed_to
- downloads_count
- rss_url
- subscriptions_count
- url
ChannelCreate:
type: object
@ -25766,7 +25770,6 @@ components:
- import_details
- metadata
- mimetype
- privacy_level
- size
- uuid
UploadForOwnerRequest:
@ -25804,7 +25807,6 @@ components:
writeOnly: true
required:
- audio_file
- privacy_level
Usage:
type: object
properties:

View File

@ -230,6 +230,7 @@ def test_channel_serializer_representation(factories, to_api_date):
"rss_url": channel.get_rss_url(),
"url": channel.actor.url,
"downloads_count": 12,
"subscriptions_count": 0,
}
expected["artist"]["description"] = common_serializers.ContentSerializer(
content
@ -254,6 +255,7 @@ def test_channel_serializer_external_representation(factories, to_api_date):
"rss_url": channel.get_rss_url(),
"url": channel.actor.url,
"downloads_count": 0,
"subscriptions_count": 0,
}
expected["artist"]["description"] = common_serializers.ContentSerializer(
content