Browse Source

Bauke review updates

merge-requests/160/head
pollev 4 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 type: string
default: "all" default: "all"
required: false 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 - in: query
name: tag name: tag
schema: schema:
@ -264,6 +264,7 @@ components:
- group - group
- content_metadata - content_metadata
- created_at - created_at
- edited_at
- posted_by_user - posted_by_user
- vote_count - vote_count
- comment_count - comment_count
@ -301,6 +302,9 @@ components:
type: string type: string
created_at: created_at:
type: string type: string
edited_at:
type: string
nullable: true
posted_by_user: posted_by_user:
type: string type: string
vote_count: vote_count:

2
tildes/tildes/lib/database.py

@ -179,7 +179,7 @@ class RecurrenceRule(TypeDecorator):
if value is None: if value is None:
return value return value
return rrulestr(value) # type: ignore
return rrulestr(value)
class TagList(TypeDecorator): 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 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: ) -> PaginatedQuery:
"""Apply pagination parameters to a query.""" """Apply pagination parameters to a query."""
# Start by parsing the before/after parameters and extracting the anchor type # Start by parsing the before/after parameters and extracting the anchor type
@ -46,7 +49,9 @@ def query_apply_pagination( # noqa
return query 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.""" """Get the next and previous links for pagination."""
next_link = None next_link = None
prev_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), "group": str(topic.group.path),
"content_metadata": topic.content_metadata_for_display, "content_metadata": topic.content_metadata_for_display,
"created_at": topic.created_time.isoformat(), "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, "posted_by_user": topic.user.username,
"vote_count": topic.num_votes, "vote_count": topic.num_votes,
"comment_count": topic.num_comments, "comment_count": topic.num_comments,

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

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

Loading…
Cancel
Save