This commit is contained in:
parent
1c04125921
commit
5f4e30866f
|
@ -9,7 +9,7 @@ from orm.author import Author, AuthorFollower, AuthorRating
|
||||||
from orm.reaction import Reaction, ReactionKind
|
from orm.reaction import Reaction, ReactionKind
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||||
from orm.topic import Topic
|
from orm.topic import Topic
|
||||||
from resolvers.follower import get_follows_by_user_id
|
from resolvers.follower import query_follows
|
||||||
from resolvers.stat import get_authors_from_query, add_author_stat_columns
|
from resolvers.stat import get_authors_from_query, add_author_stat_columns
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
|
@ -235,7 +235,7 @@ async def get_author_follows(
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
if user:
|
if user:
|
||||||
follows = await get_follows_by_user_id(user)
|
follows = query_follows(user)
|
||||||
return follows
|
return follows
|
||||||
else:
|
else:
|
||||||
raise ValueError('Author not found')
|
raise ValueError('Author not found')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from sqlalchemy import select, or_, column
|
from sqlalchemy import select, or_
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
from sqlalchemy.sql import and_
|
from sqlalchemy.sql import and_
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ from orm.author import Author, AuthorFollower
|
||||||
from orm.reaction import Reaction
|
from orm.reaction import Reaction
|
||||||
from orm.shout import Shout, ShoutReactionsFollower
|
from orm.shout import Shout, ShoutReactionsFollower
|
||||||
from orm.topic import Topic, TopicFollower
|
from orm.topic import Topic, TopicFollower
|
||||||
from resolvers.stat import add_author_stat_columns
|
|
||||||
from resolvers.community import community_follow, community_unfollow
|
from resolvers.community import community_follow, community_unfollow
|
||||||
from resolvers.topic import topic_follow, topic_unfollow
|
from resolvers.topic import topic_follow, topic_unfollow
|
||||||
from resolvers.stat import add_topic_stat_columns, get_topics_from_query
|
from resolvers.stat import add_topic_stat_columns, get_topics_from_query
|
||||||
|
@ -94,76 +93,88 @@ def query_follows(user_id: str):
|
||||||
if isinstance(author, Author):
|
if isinstance(author, Author):
|
||||||
author_id = author.id
|
author_id = author.id
|
||||||
authors_query = (
|
authors_query = (
|
||||||
select(
|
select([
|
||||||
column('name'),
|
Author.name,
|
||||||
column('id'),
|
Author.id,
|
||||||
column('slug'),
|
Author.slug,
|
||||||
column('pic'),
|
Author.pic,
|
||||||
column('bio'),
|
Author.bio,
|
||||||
)
|
Author.shouts_stat,
|
||||||
|
Author.followers_stat,
|
||||||
|
Author.followings_stat,
|
||||||
|
])
|
||||||
.select_from(Author)
|
.select_from(Author)
|
||||||
.join(AuthorFollower, AuthorFollower.follower == author_id)
|
.join(AuthorFollower, AuthorFollower.follower == author_id)
|
||||||
.filter(AuthorFollower.author == Author.id)
|
.filter(AuthorFollower.author == Author.id)
|
||||||
)
|
)
|
||||||
authors_query = add_author_stat_columns(authors_query)
|
|
||||||
|
|
||||||
topics_query = (
|
|
||||||
select(column('title'), column('id'), column('slug'), column('body'))
|
|
||||||
.select_from(Topic)
|
|
||||||
.join(TopicFollower, TopicFollower.follower == author_id)
|
|
||||||
.filter(TopicFollower.topic == Topic.id)
|
|
||||||
)
|
|
||||||
topics_query = add_topic_stat_columns(topics_query)
|
|
||||||
|
|
||||||
# Convert query results to lists of dictionaries
|
|
||||||
authors = [
|
authors = [
|
||||||
{
|
{
|
||||||
'id': author.id,
|
'id': author_id,
|
||||||
'name': author.name,
|
'name': name,
|
||||||
'slug': author.slug,
|
'slug': slug,
|
||||||
'pic': author.pic,
|
'pic': pic,
|
||||||
'bio': author.bio,
|
'bio': bio,
|
||||||
'stat': {
|
'stat': {
|
||||||
'shouts': shouts_stat,
|
'shouts': shouts_stat,
|
||||||
'followers': followers_stat,
|
'followers': followers_stat,
|
||||||
'followings': followings_stat,
|
'followings': followings_stat,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for [author, shouts_stat, followers_stat, followings_stat] in session.execute(authors_query)
|
for (
|
||||||
|
name,
|
||||||
|
author_id,
|
||||||
|
slug,
|
||||||
|
pic,
|
||||||
|
bio,
|
||||||
|
shouts_stat,
|
||||||
|
followers_stat,
|
||||||
|
followings_stat,
|
||||||
|
) in session.execute(authors_query)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
topics_query = (
|
||||||
|
select([
|
||||||
|
Topic.title,
|
||||||
|
Topic.id,
|
||||||
|
Topic.slug,
|
||||||
|
Topic.body,
|
||||||
|
Topic.shouts_stat,
|
||||||
|
Topic.authors_stat,
|
||||||
|
Topic.followers_stat,
|
||||||
|
])
|
||||||
|
.select_from(Topic)
|
||||||
|
.join(TopicFollower, TopicFollower.follower == author_id)
|
||||||
|
.filter(TopicFollower.topic == Topic.id)
|
||||||
|
)
|
||||||
topics = [
|
topics = [
|
||||||
{
|
{
|
||||||
'id': topic.id,
|
'id': topic_id,
|
||||||
'title': topic.title,
|
'title': title,
|
||||||
'slug': topic.slug,
|
'slug': slug,
|
||||||
'body': topic.body,
|
'body': body,
|
||||||
'stat': {
|
'stat': {
|
||||||
'shouts': shouts_stat,
|
'shouts': shouts_stat,
|
||||||
'authors': authors_stat,
|
'authors': authors_stat,
|
||||||
'followers': followers_stat,
|
'followers': followers_stat,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for [
|
for (
|
||||||
topic,
|
title,
|
||||||
|
topic_id,
|
||||||
|
slug,
|
||||||
|
body,
|
||||||
shouts_stat,
|
shouts_stat,
|
||||||
authors_stat,
|
authors_stat,
|
||||||
followers_stat,
|
followers_stat,
|
||||||
] in session.execute(topics_query)
|
) in session.execute(topics_query)
|
||||||
]
|
]
|
||||||
# shouts_query = (
|
|
||||||
# session.query(Shout)
|
# Include other queries (e.g., shouts_query) if needed
|
||||||
# .join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id)
|
|
||||||
# .filter(ShoutReactionsFollower.shout == Shout.id)
|
|
||||||
# .options(load_only(Shout.id)) # Exclude unnecessary columns
|
|
||||||
# .all()
|
|
||||||
# )
|
|
||||||
# shouts = [shout.to_dict() for shout in shouts_query]
|
|
||||||
# communities = session.query(Community).all()
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'topics': topics,
|
'topics': topics,
|
||||||
'authors': authors,
|
'authors': authors,
|
||||||
# "shouts": shouts,
|
# Include other results (e.g., shouts) if needed
|
||||||
'communities': [{'id': 1, 'name': 'Дискурс', 'slug': 'discours'}],
|
'communities': [{'id': 1, 'name': 'Дискурс', 'slug': 'discours'}],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user