API: fix for queries by community name

This commit is contained in:
freamon 2024-09-22 09:56:17 +00:00
parent ea1564cc87
commit 506becc41c
2 changed files with 4 additions and 2 deletions

View file

@ -13,7 +13,8 @@ from sqlalchemy import desc
def cached_post_list(type, sort, user_id, community_id, community_name, person_id): def cached_post_list(type, sort, user_id, community_id, community_name, person_id):
if type == "All": if type == "All":
if community_name: if community_name:
posts = Post.query.filter_by(deleted=False).join(Community, Community.id == Post.community_id).filter_by(show_all=True, name=community_name) name, ap_domain = community_name.split('@')
posts = Post.query.filter_by(deleted=False).join(Community, Community.id == Post.community_id).filter_by(show_all=True, name=name, ap_domain=ap_domain)
elif community_id: elif community_id:
posts = Post.query.filter_by(deleted=False).join(Community, Community.id == Post.community_id).filter_by(show_all=True, id=community_id) posts = Post.query.filter_by(deleted=False).join(Community, Community.id == Post.community_id).filter_by(show_all=True, id=community_id)
elif person_id: elif person_id:

View file

@ -172,7 +172,8 @@ def community_view(community: Community | int | str, variant, stub=False, user_i
if isinstance(community, int): if isinstance(community, int):
community = Community.query.get(community) community = Community.query.get(community)
elif isinstance(community, str): elif isinstance(community, str):
community = Community.query.filter_by(name=community).first() name, ap_domain = community.split('@')
community = Community.query.filter_by(name=name, ap_domain=ap_domain).first()
if not community: if not community:
raise Exception('community_not_found') raise Exception('community_not_found')