Browse Source

Bauke review updates

merge-requests/160/head
pollev 2 months ago
parent
commit
7a0db43f6b
  1. 6
      tildes/openapi_beta.yaml
  2. 2
      tildes/tildes/lib/database.py
  3. 9
      tildes/tildes/views/api/beta/api_utils.py
  4. 3
      tildes/tildes/views/api/beta/topic.py
  5. 4
      tildes/tildes/views/api/beta/user.py

6
tildes/openapi_beta.yaml

@ -23,7 +23,7 @@ paths:
type: string
default: "all"
required: false
description: The time period for which to retrieve topics. For example 4h" or "2d".
description: The time period for which to retrieve topics. For example "4h" or "2d".
- in: query
name: tag
schema:
@ -264,6 +264,7 @@ components:
- group
- content_metadata
- created_at
- edited_at
- posted_by_user
- vote_count
- comment_count
@ -301,6 +302,9 @@ components:
type: string
created_at:
type: string
edited_at:
type: string
nullable: true
posted_by_user:
type: string
vote_count:

2
tildes/tildes/lib/database.py

@ -179,7 +179,7 @@ class RecurrenceRule(TypeDecorator):
if value is None:
return value
return rrulestr(value) # type: ignore
return rrulestr(value)
class TagList(TypeDecorator):

9
tildes/tildes/views/api/beta/api_utils.py

@ -11,7 +11,10 @@ from tildes.models.pagination import PaginatedQuery, PaginatedResults
def query_apply_pagination( # noqa
query, before, after, error_if_no_anchor: bool = False
query: PaginatedQuery,
before: str | None,
after: str | None,
error_if_no_anchor: bool = False,
) -> PaginatedQuery:
"""Apply pagination parameters to a query."""
# Start by parsing the before/after parameters and extracting the anchor type
@ -46,7 +49,9 @@ def query_apply_pagination( # noqa
return query
def get_next_and_prev_link(request: Request, page: PaginatedResults) -> Tuple[str, str]:
def get_next_and_prev_link(
request: Request, page: PaginatedResults
) -> Tuple[str | None, str | None]:
"""Get the next and previous links for pagination."""
next_link = None
prev_link = None

3
tildes/tildes/views/api/beta/topic.py

@ -30,6 +30,9 @@ def topic_to_dict(topic: Topic) -> dict:
"group": str(topic.group.path),
"content_metadata": topic.content_metadata_for_display,
"created_at": topic.created_time.isoformat(),
"edited_at": (
topic.last_edited_time.isoformat() if topic.last_edited_time else None
),
"posted_by_user": topic.user.username,
"vote_count": topic.num_votes,
"comment_count": topic.num_comments,

4
tildes/tildes/views/api/beta/user.py

@ -3,6 +3,7 @@
"""JSON API endpoints related to users."""
from typing import Union
from pyramid.request import Request
from pyramid.view import view_config
from tildes.models.user.user import User
@ -62,7 +63,8 @@ def get_user(request: Request) -> dict: # noqa
result_sets = []
# For the main user API endpoint, combine topics and comments
for type_to_query in [Topic, Comment]:
types_to_query: list[Union[type[Topic], type[Comment]]] = [Topic, Comment]
for type_to_query in types_to_query:
query = request.query(type_to_query).filter(type_to_query.user == user)
try:
query = query_apply_pagination(

Loading…
Cancel
Save