Skip to content

Commit

Permalink
add type to api url path
Browse files Browse the repository at this point in the history
  • Loading branch information
alphatownsman committed May 24, 2024
1 parent 024b01a commit c41e38e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 70 deletions.
74 changes: 38 additions & 36 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@
path("v1/accounts/familiar_followers", accounts.familiar_followers),
path("v1/accounts/search", accounts.accounts_search),
path("v1/accounts/lookup", accounts.lookup),
path("v1/accounts/<id>", accounts.account),
path("v1/accounts/<id>/statuses", accounts.account_statuses),
path("v1/accounts/<id>/follow", accounts.account_follow),
path("v1/accounts/<id>/unfollow", accounts.account_unfollow),
path("v1/accounts/<id>/block", accounts.account_block),
path("v1/accounts/<id>/unblock", accounts.account_unblock),
path("v1/accounts/<id>/mute", accounts.account_mute),
path("v1/accounts/<id>/unmute", accounts.account_unmute),
path("v1/accounts/<id>/following", accounts.account_following),
path("v1/accounts/<id>/followers", accounts.account_followers),
path("v1/accounts/<id>/featured_tags", accounts.account_featured_tags),
path("v1/accounts/<int:id>", accounts.account),
path("v1/accounts/<int:id>/statuses", accounts.account_statuses),
path("v1/accounts/<int:id>/follow", accounts.account_follow),
path("v1/accounts/<int:id>/unfollow", accounts.account_unfollow),
path("v1/accounts/<int:id>/block", accounts.account_block),
path("v1/accounts/<int:id>/unblock", accounts.account_unblock),
path("v1/accounts/<int:id>/mute", accounts.account_mute),
path("v1/accounts/<int:id>/unmute", accounts.account_unmute),
path("v1/accounts/<int:id>/following", accounts.account_following),
path("v1/accounts/<int:id>/followers", accounts.account_followers),
path("v1/accounts/<int:id>/featured_tags", accounts.account_featured_tags),
# Announcements
path("v1/announcements", announcements.announcement_list),
path("v1/announcements/<pk>/dismiss", announcements.announcement_dismiss),
path("v1/announcements/<int:pk>/dismiss", announcements.announcement_dismiss),
# Apps
path("v1/apps", apps.add_app),
path("v1/apps/verify_credentials", apps.verify_credentials),
Expand All @@ -58,8 +58,10 @@
path("v1/filters", filters.list_filters),
# Follow requests
path("v1/follow_requests", follow_requests.follow_requests),
path("v1/follow_requests/<id>/authorize", follow_requests.accept_follow_request),
path("v1/follow_requests/<id>/reject", follow_requests.reject_follow_request),
path(
"v1/follow_requests/<int:id>/authorize", follow_requests.accept_follow_request
),
path("v1/follow_requests/<int:id>/reject", follow_requests.reject_follow_request),
# Instance
path("v1/instance", instance.instance_info_v1),
path("v1/instance/activity", instance.activity),
Expand All @@ -70,24 +72,24 @@
# Media
path("v1/media", media.upload_media),
path("v2/media", media.upload_media),
path("v1/media/<id>", methods(get=media.get_media, put=media.update_media)),
path("v1/media/<int:id>", methods(get=media.get_media, put=media.update_media)),
path(
"v1/statuses/<id>",
"v1/statuses/<int:id>",
methods(
get=statuses.status,
put=statuses.edit_status,
delete=statuses.delete_status,
),
),
path("v1/statuses/<id>/source", statuses.status_source),
path("v1/statuses/<int:id>/source", statuses.status_source),
# Notifications
path("v1/notifications", notifications.notifications),
path("v1/notifications/clear", notifications.dismiss_notifications),
path("v1/notifications/<id>", notifications.get_notification),
path("v1/notifications/<id>/dismiss", notifications.dismiss_notification),
path("v1/notifications/<int:id>", notifications.get_notification),
path("v1/notifications/<int:id>/dismiss", notifications.dismiss_notification),
# Polls
path("v1/polls/<id>", polls.get_poll),
path("v1/polls/<id>/votes", polls.vote_poll),
path("v1/polls/<int:id>", polls.get_poll),
path("v1/polls/<int:id>/votes", polls.vote_poll),
# Preferences
path("v1/preferences", preferences.preferences),
# Push
Expand All @@ -105,26 +107,26 @@
path("v2/search", search.search),
# Statuses
path("v1/statuses", statuses.post_status),
path("v1/statuses/<id>/context", statuses.status_context),
path("v1/statuses/<id>/favourite", statuses.favourite_status),
path("v1/statuses/<id>/unfavourite", statuses.unfavourite_status),
path("v1/statuses/<id>/favourited_by", statuses.favourited_by),
path("v1/statuses/<id>/reblog", statuses.reblog_status),
path("v1/statuses/<id>/unreblog", statuses.unreblog_status),
path("v1/statuses/<id>/reblogged_by", statuses.reblogged_by),
path("v1/statuses/<id>/bookmark", statuses.bookmark_status),
path("v1/statuses/<id>/unbookmark", statuses.unbookmark_status),
path("v1/statuses/<id>/pin", statuses.pin_status),
path("v1/statuses/<id>/unpin", statuses.unpin_status),
path("v1/statuses/<int:id>/context", statuses.status_context),
path("v1/statuses/<int:id>/favourite", statuses.favourite_status),
path("v1/statuses/<int:id>/unfavourite", statuses.unfavourite_status),
path("v1/statuses/<int:id>/favourited_by", statuses.favourited_by),
path("v1/statuses/<int:id>/reblog", statuses.reblog_status),
path("v1/statuses/<int:id>/unreblog", statuses.unreblog_status),
path("v1/statuses/<int:id>/reblogged_by", statuses.reblogged_by),
path("v1/statuses/<int:id>/bookmark", statuses.bookmark_status),
path("v1/statuses/<int:id>/unbookmark", statuses.unbookmark_status),
path("v1/statuses/<int:id>/pin", statuses.pin_status),
path("v1/statuses/<int:id>/unpin", statuses.unpin_status),
# Tags
path("v1/followed_tags", tags.followed_tags),
path("v1/tags/<hashtag>", tags.hashtag),
path("v1/tags/<id>/follow", tags.follow),
path("v1/tags/<id>/unfollow", tags.unfollow),
path("v1/tags/<str:hashtag>", tags.hashtag),
path("v1/tags/<str:id>/follow", tags.follow),
path("v1/tags/<str:id>/unfollow", tags.unfollow),
# Timelines
path("v1/timelines/home", timelines.home),
path("v1/timelines/public", timelines.public),
path("v1/timelines/tag/<hashtag>", timelines.hashtag),
path("v1/timelines/tag/<str:hashtag>", timelines.hashtag),
path("v1/conversations", timelines.conversations),
path("v1/favourites", timelines.favourites),
# Trends
Expand Down
22 changes: 11 additions & 11 deletions api/views/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def lookup(request: HttpRequest, acct: str) -> schemas.Account:

@scope_required("read:accounts")
@api_view.get
def account(request, id: str) -> schemas.Account:
def account(request, id: int) -> schemas.Account:
identity = get_object_or_404(
Identity.objects.exclude(restriction=Identity.Restriction.blocked),
pk=id,
Expand All @@ -175,7 +175,7 @@ def account(request, id: str) -> schemas.Account:
@api_view.get
def account_statuses(
request: HttpRequest,
id: str,
id: int,
exclude_reblogs: bool = False,
exclude_replies: bool = False,
only_media: bool = False,
Expand Down Expand Up @@ -238,7 +238,7 @@ def account_statuses(

@scope_required("write:follows")
@api_view.post
def account_follow(request, id: str, reblogs: bool = True) -> schemas.Relationship:
def account_follow(request, id: int, reblogs: bool = True) -> schemas.Relationship:
identity = get_object_or_404(
Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id
)
Expand All @@ -249,7 +249,7 @@ def account_follow(request, id: str, reblogs: bool = True) -> schemas.Relationsh

@scope_required("write:follows")
@api_view.post
def account_unfollow(request, id: str) -> schemas.Relationship:
def account_unfollow(request, id: int) -> schemas.Relationship:
identity = get_object_or_404(
Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id
)
Expand All @@ -260,7 +260,7 @@ def account_unfollow(request, id: str) -> schemas.Relationship:

@scope_required("write:blocks")
@api_view.post
def account_block(request, id: str) -> schemas.Relationship:
def account_block(request, id: int) -> schemas.Relationship:
identity = get_object_or_404(Identity, pk=id)
service = IdentityService(request.identity)
service.block(identity)
Expand All @@ -269,7 +269,7 @@ def account_block(request, id: str) -> schemas.Relationship:

@scope_required("write:blocks")
@api_view.post
def account_unblock(request, id: str) -> schemas.Relationship:
def account_unblock(request, id: int) -> schemas.Relationship:
identity = get_object_or_404(Identity, pk=id)
service = IdentityService(request.identity)
service.unblock(identity)
Expand All @@ -280,7 +280,7 @@ def account_unblock(request, id: str) -> schemas.Relationship:
@api_view.post
def account_mute(
request,
id: str,
id: int,
notifications: QueryOrBody[bool] = True,
duration: QueryOrBody[int] = 0,
) -> schemas.Relationship:
Expand All @@ -296,7 +296,7 @@ def account_mute(

@scope_required("write:blocks")
@api_view.post
def account_unmute(request, id: str) -> schemas.Relationship:
def account_unmute(request, id: int) -> schemas.Relationship:
identity = get_object_or_404(Identity, pk=id)
service = IdentityService(request.identity)
service.unmute(identity)
Expand All @@ -306,7 +306,7 @@ def account_unmute(request, id: str) -> schemas.Relationship:
@api_view.get
def account_following(
request: HttpRequest,
id: str,
id: int,
max_id: str | None = None,
since_id: str | None = None,
min_id: str | None = None,
Expand Down Expand Up @@ -339,7 +339,7 @@ def account_following(
@api_view.get
def account_followers(
request: HttpRequest,
id: str,
id: int,
max_id: str | None = None,
since_id: str | None = None,
min_id: str | None = None,
Expand Down Expand Up @@ -370,6 +370,6 @@ def account_followers(


@api_view.get
def account_featured_tags(request: HttpRequest, id: str) -> list[schemas.FeaturedTag]:
def account_featured_tags(request: HttpRequest, id: int) -> list[schemas.FeaturedTag]:
# Not implemented yet
return []
2 changes: 1 addition & 1 deletion api/views/announcements.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def announcement_list(request) -> list[schemas.Announcement]:

@scope_required("write:notifications")
@api_view.post
def announcement_dismiss(request, pk: str):
def announcement_dismiss(request, pk: int):
announcement = get_object_or_404(Announcement, pk=pk)
AnnouncementService(request.user).mark_seen(announcement)
4 changes: 2 additions & 2 deletions api/views/follow_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def follow_requests(
@api_view.post
def accept_follow_request(
request: HttpRequest,
id: str | None = None,
id: int | None = None,
) -> schemas.Relationship:
source_identity = get_object_or_404(
Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id
Expand All @@ -51,7 +51,7 @@ def accept_follow_request(
@api_view.post
def reject_follow_request(
request: HttpRequest,
id: str | None = None,
id: int | None = None,
) -> schemas.Relationship:
source_identity = get_object_or_404(
Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id
Expand Down
4 changes: 2 additions & 2 deletions api/views/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def upload_media(
@api_view.get
def get_media(
request,
id: str,
id: int,
) -> schemas.MediaAttachment:
attachment = get_object_or_404(PostAttachment, pk=id)
if attachment.post:
Expand All @@ -67,7 +67,7 @@ def get_media(
@api_view.put
def update_media(
request,
id: str,
id: int,
description: QueryOrBody[str] = "",
focus: QueryOrBody[str] = "0,0",
) -> schemas.MediaAttachment:
Expand Down
4 changes: 2 additions & 2 deletions api/views/polls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class PostVoteSchema(Schema):

@scope_required("read:statuses")
@api_view.get
def get_poll(request, id: str) -> schemas.Poll:
def get_poll(request, id: int) -> schemas.Poll:
post = get_object_or_404(Post, pk=id, type=Post.Types.question)
return schemas.Poll.from_post(post, identity=request.identity)


@scope_required("write:statuses")
@api_view.post
def vote_poll(request, id: str, details: PostVoteSchema) -> schemas.Poll:
def vote_poll(request, id: int, details: PostVoteSchema) -> schemas.Poll:
post = get_object_or_404(Post, pk=id, type=Post.Types.question)
PostInteraction.create_votes(post, request.identity, details.choices)
post.refresh_from_db()
Expand Down
Loading

0 comments on commit c41e38e

Please sign in to comment.