WIP: add /api/v1/followed_tags endpoint

pull/539/head
Christof Dorner 2023-03-12 20:12:08 +01:00
rodzic 2ea3aed3fd
commit 17ca48a2fd
2 zmienionych plików z 25 dodań i 2 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ from django.utils import timezone
from core.models import Config
from stator.models import State, StateField, StateGraph, StatorModel
from users.models import Identity
class HashtagStates(StateGraph):
@ -73,6 +74,9 @@ class HashtagQuerySet(models.QuerySet):
models.Q(hashtag=hashtag) | models.Q(aliases__contains=hashtag)
)
def followed_by(self, identity: Identity):
return self.filter(followers__identity=identity)
class HashtagManager(models.Manager):
def get_queryset(self):
@ -84,6 +88,9 @@ class HashtagManager(models.Manager):
def hashtag_or_alias(self, hashtag: str):
return self.get_queryset().hashtag_or_alias(hashtag)
def followed_by(self, identity: Identity):
return self.get_queryset().followed_by(identity)
class Hashtag(StatorModel):

Wyświetl plik

@ -1,8 +1,10 @@
from django.http import HttpRequest
from hatchway import api_view
from activities.models import Hashtag
from api import schemas
from api.decorators import scope_required
from api.pagination import MastodonPaginator, PaginatingApiResponse, PaginationResult
@scope_required("read:follows")
@ -14,5 +16,19 @@ def followed_tags(
min_id: str | None = None,
limit: int = 100,
) -> list[schemas.Tag]:
# We don't implement this yet
return []
queryset = Hashtag.objects.followed_by(request.identity)
paginator = MastodonPaginator()
# TODO: this fails due to the Hashtag model not having an `id` field
pager: PaginationResult[Hashtag] = paginator.paginate(
queryset,
min_id=min_id,
max_id=max_id,
since_id=since_id,
limit=limit,
)
return PaginatingApiResponse(
# TODO: add something like map_from_post to schemas.Tag
schemas.Tag.map_from_post(pager.results, request.identity),
request=request,
include_params=["limit"],
)