old naming

This commit is contained in:
2022-11-30 09:27:12 +03:00
parent 8209cc744c
commit 44bd4f6ede
18 changed files with 90 additions and 90 deletions

View File

@@ -26,7 +26,7 @@ async def create_shout(_, info, inp):
new_shout = Shout.create(**inp)
# NOTE: shout made by one first author
sa = ShoutAuthor.create(shoutId=new_shout.id, userId=user.id)
sa = ShoutAuthor.create(shout=new_shout.id, user=user.id)
session.add(sa)
reactions_follow(user, new_shout.slug, True)
@@ -37,14 +37,14 @@ async def create_shout(_, info, inp):
for slug in topic_slugs:
topic = session.query(Topic).where(Topic.slug == slug).one()
st = ShoutTopic.create(shoutId=new_shout.id, topicId=topic.id)
st = ShoutTopic.create(shout=new_shout.id, topic=topic.id)
session.add(st)
tf = session.query(TopicFollower).where(
and_(TopicFollower.followerId == user.id, TopicFollower.topicId == topic.id)
and_(TopicFollower.follower == user.id, TopicFollower.topic == topic.id)
)
if not tf:
tf = TopicFollower.create(followerId=user.id, topicId=topic.id, auto=True)
tf = TopicFollower.create(follower=user.id, topic=topic.id, auto=True)
session.add(tf)
new_shout.topic_slugs = topic_slugs
@@ -74,7 +74,7 @@ async def update_shout(_, info, inp):
if user_id not in authors:
scopes = auth.scopes
print(scopes)
if Resource.shoutId not in scopes:
if Resource.shout not in scopes:
return {"error": "access denied"}
else:
shout.update(inp)
@@ -82,7 +82,7 @@ async def update_shout(_, info, inp):
session.add(shout)
if inp.get("topics"):
# remove old links
links = session.query(ShoutTopic).where(ShoutTopic.shoutId == shout.id).all()
links = session.query(ShoutTopic).where(ShoutTopic.shout == shout.id).all()
for topiclink in links:
session.delete(topiclink)
# add new topic links

View File

@@ -31,7 +31,7 @@ async def search_recipients(_, info, query: str, limit: int = 50, offset: int =
with local_session() as session:
# followings
result += session.query(AuthorFollower.author).join(
User, User.id == AuthorFollower.followerId
User, User.id == AuthorFollower.follower
).where(
User.slug.startswith(query)
).offset(offset + len(result)).limit(more_amount)
@@ -39,7 +39,7 @@ async def search_recipients(_, info, query: str, limit: int = 50, offset: int =
more_amount = limit
# followers
result += session.query(AuthorFollower.follower).join(
User, User.id == AuthorFollower.authorId
User, User.id == AuthorFollower.author
).where(
User.slug.startswith(query)
).offset(offset + len(result)).limit(offset + len(result) + limit)

View File

@@ -68,7 +68,7 @@ async def load_shout(_, info, slug):
for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug):
for author in shout.authors:
if author.id == author_caption.userId:
if author.id == author_caption.user:
author.caption = author_caption.caption
return shout

View File

@@ -23,19 +23,19 @@ def add_author_stat_columns(q):
user_rating_aliased = aliased(UserRating)
q = q.outerjoin(shout_author_aliased).add_columns(
func.count(distinct(shout_author_aliased.shoutId)).label('shouts_stat')
func.count(distinct(shout_author_aliased.shout)).label('shouts_stat')
)
q = q.outerjoin(author_followers, author_followers.authorId == User.id).add_columns(
func.count(distinct(author_followers.followerId)).label('followers_stat')
q = q.outerjoin(author_followers, author_followers.author == User.id).add_columns(
func.count(distinct(author_followers.follower)).label('followers_stat')
)
q = q.outerjoin(author_following, author_following.followerId == User.id).add_columns(
func.count(distinct(author_following.authorId)).label('followings_stat')
q = q.outerjoin(author_following, author_following.follower == User.id).add_columns(
func.count(distinct(author_following.author)).label('followings_stat')
)
q = q.add_columns(literal(0).label('rating_stat'))
# FIXME
# q = q.outerjoin(user_rating_aliased, user_rating_aliased.userId == User.id).add_columns(
# q = q.outerjoin(user_rating_aliased, user_rating_aliased.user == User.id).add_columns(
# # TODO: check
# func.sum(user_rating_aliased.value).label('rating_stat')
# )
@@ -120,7 +120,7 @@ async def get_followed_authors(_, _info, slug) -> List[User]:
async def followed_authors(slug) -> List[User]:
q = select(User)
q = add_author_stat_columns(q)
q = q.join(AuthorFollower).join(User, User.id == AuthorFollower.followerId).where(User.slug == slug)
q = q.join(AuthorFollower).join(User, User.id == AuthorFollower.follower).where(User.slug == slug)
return get_authors_from_query(q)
@@ -132,7 +132,7 @@ async def user_followers(_, _info, slug) -> List[User]:
aliased_user = aliased(User)
q = q.join(AuthorFollower).join(
aliased_user, aliased_user.id == AuthorFollower.authorId
aliased_user, aliased_user.id == AuthorFollower.author
).where(
aliased_user.slug == slug
)
@@ -147,7 +147,7 @@ async def get_user_roles(slug):
session.query(Role)
.options(joinedload(Role.permissions))
.join(UserRole)
.where(UserRole.userId == user.id)
.where(UserRole.user == user.id)
.all()
)
@@ -193,7 +193,7 @@ async def rate_user(_, info, rated_userslug, value):
def author_follow(user, slug):
with local_session() as session:
author = session.query(User).where(User.slug == slug).one()
af = AuthorFollower.create(followerId=user.id, authorId=author.id)
af = AuthorFollower.create(follower=user.id, author=author.id)
session.add(af)
session.commit()
@@ -204,9 +204,9 @@ def author_unfollow(user, slug):
flw = (
session.query(
AuthorFollower
).join(User, User.id == AuthorFollower.authorId).filter(
).join(User, User.id == AuthorFollower.author).filter(
and_(
AuthorFollower.followerId == user.id, User.slug == slug
AuthorFollower.follower == user.id, User.slug == slug
)
).first()
)
@@ -221,7 +221,7 @@ def author_unfollow(user, slug):
async def get_authors_all(_, _info):
q = select(User)
q = add_author_stat_columns(q)
q = q.join(ShoutAuthor, User.id == ShoutAuthor.userId)
q = q.join(ShoutAuthor, User.id == ShoutAuthor.user)
return get_authors_from_query(q)

View File

@@ -20,15 +20,15 @@ def reactions_follow(user: User, slug: str, auto=False):
following = (
session.query(ShoutReactionsFollower).where(and_(
ShoutReactionsFollower.followerId == user.id,
ShoutReactionsFollower.shoutId == shout.id,
ShoutReactionsFollower.follower == user.id,
ShoutReactionsFollower.shout == shout.id,
)).first()
)
if not following:
following = ShoutReactionsFollower.create(
followerId=user.id,
shoutId=shout.id,
follower=user.id,
shout=shout.id,
auto=auto
)
session.add(following)
@@ -41,8 +41,8 @@ def reactions_unfollow(user, slug):
following = (
session.query(ShoutReactionsFollower).where(and_(
ShoutReactionsFollower.followerId == user.id,
ShoutReactionsFollower.shoutId == shout.id
ShoutReactionsFollower.follower == user.id,
ShoutReactionsFollower.shout == shout.id
)).first()
)
@@ -74,7 +74,7 @@ def check_to_publish(session, user, reaction):
]:
if is_published_author(user):
# now count how many approvers are voted already
approvers_reactions = session.query(Reaction).where(Reaction.shoutId == reaction.shoutId).all()
approvers_reactions = session.query(Reaction).where(Reaction.shout == reaction.shout).all()
approvers = [user.slug, ]
for ar in approvers_reactions:
a = ar.createdBy
@@ -93,7 +93,7 @@ def check_to_hide(session, user, reaction):
ReactionKind.UNPROOF
]:
# if is_published_author(user):
approvers_reactions = session.query(Reaction).where(Reaction.shoutId == reaction.shoutId).all()
approvers_reactions = session.query(Reaction).where(Reaction.shout == reaction.shout).all()
declines = 0
for r in approvers_reactions:
if r.kind in [
@@ -232,7 +232,7 @@ async def load_reactions_by(_, _info, by, limit=50, offset=0):
).join(
CreatedByUser, Reaction.createdBy == CreatedByUser.id
).join(
ReactedShout, Reaction.shoutId == ReactedShout.id
ReactedShout, Reaction.shout == ReactedShout.id
)
if by.get("shout"):

View File

@@ -8,16 +8,16 @@ from orm import Shout, User
def add_topic_stat_columns(q):
q = q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topicId).add_columns(
func.count(distinct(ShoutTopic.shoutId)).label('shouts_stat')
).outerjoin(ShoutAuthor, ShoutTopic.shoutId == ShoutAuthor.shoutId).add_columns(
func.count(distinct(ShoutAuthor.userId)).label('authors_stat')
q = q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topic).add_columns(
func.count(distinct(ShoutTopic.shout)).label('shouts_stat')
).outerjoin(ShoutAuthor, ShoutTopic.shout == ShoutAuthor.shout).add_columns(
func.count(distinct(ShoutAuthor.user)).label('authors_stat')
).outerjoin(TopicFollower,
and_(
TopicFollower.topicId == Topic.id,
TopicFollower.followerId == ShoutAuthor.id
TopicFollower.topic == Topic.id,
TopicFollower.follower == ShoutAuthor.id
)).add_columns(
func.count(distinct(TopicFollower.followerId)).label('followers_stat')
func.count(distinct(TopicFollower.follower)).label('followers_stat')
)
q = q.group_by(Topic.id)
@@ -119,7 +119,7 @@ async def topic_follow(user, slug):
with local_session() as session:
topic = session.query(Topic).where(Topic.slug == slug).one()
following = TopicFollower.create(topicId=topic.id, followerId=user.id)
following = TopicFollower.create(topic=topic.id, follower=user.id)
session.add(following)
session.commit()
@@ -129,7 +129,7 @@ async def topic_unfollow(user, slug):
sub = (
session.query(TopicFollower).join(Topic).filter(
and_(
TopicFollower.followerId == user.id,
TopicFollower.follower == user.id,
Topic.slug == slug
)
).first()
@@ -145,7 +145,7 @@ async def topic_unfollow(user, slug):
async def topics_random(_, info, amount=12):
q = select(Topic)
q = add_topic_stat_columns(q)
q = q.join(Shout, ShoutTopic.shoutId == Shout.id).group_by(Topic.id).having(func.count(Shout.id) > 2)
q = q.join(Shout, ShoutTopic.shout == Shout.id).group_by(Topic.id).having(func.count(Shout.id) > 2)
q = q.order_by(func.random()).limit(amount)
return get_topics_from_query(q)