From 44bd4f6edefccf1b7c7362d87715e6c73c9028b1 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 30 Nov 2022 09:27:12 +0300 Subject: [PATCH] old naming --- migration/tables/comments.py | 30 +++++++++++++++--------------- migration/tables/content_items.py | 20 ++++++++++---------- migration/tables/users.py | 6 +++--- orm/collab.py | 2 +- orm/collection.py | 2 +- orm/community.py | 2 +- orm/reaction.py | 2 +- orm/shout.py | 12 ++++++------ orm/topic.py | 4 ++-- orm/user.py | 12 ++++++------ orm/viewed.py | 2 +- resolvers/create/editor.py | 12 ++++++------ resolvers/inbox/search.py | 4 ++-- resolvers/zine/load.py | 2 +- resolvers/zine/profile.py | 26 +++++++++++++------------- resolvers/zine/reactions.py | 18 +++++++++--------- resolvers/zine/topics.py | 20 ++++++++++---------- services/stat/viewed.py | 4 ++-- 18 files changed, 90 insertions(+), 90 deletions(-) diff --git a/migration/tables/comments.py b/migration/tables/comments.py index 160d1dc7..138b3327 100644 --- a/migration/tables/comments.py +++ b/migration/tables/comments.py @@ -73,7 +73,7 @@ async def migrate(entry, storage): Shout ).where(Shout.slug == shout_dict["slug"]).one() - reaction_dict["shoutId"] = shout.id + reaction_dict["shout"] = shout.id reaction_dict["createdBy"] = author.id if author else 1 reaction_dict["kind"] = ReactionKind.COMMENT @@ -91,13 +91,13 @@ async def migrate(entry, storage): ).where( User.id == reaction_dict["createdBy"] ).filter( - ShoutReactionsFollower.shoutId == reaction.shoutId + ShoutReactionsFollower.shout == reaction.shout ).first() if not following1: following1 = ShoutReactionsFollower.create( - followerId=reaction_dict["createdBy"], - shoutId=reaction.shoutId, + follower=reaction_dict["createdBy"], + shout=reaction.shout, auto=True ) session.add(following1) @@ -109,7 +109,7 @@ async def migrate(entry, storage): ).join( Topic ).where( - TopicFollower.followerId == reaction_dict["createdBy"] + TopicFollower.follower == reaction_dict["createdBy"] ).filter( Topic.slug == t ).first() @@ -120,8 +120,8 @@ async def migrate(entry, storage): ).where(Topic.slug == t).one() topic_following = TopicFollower.create( - followerId=reaction_dict["createdBy"], - topicId=topic.id, + follower=reaction_dict["createdBy"], + topic=topic.id, auto=True ) session.add(topic_following) @@ -134,7 +134,7 @@ async def migrate(entry, storage): .first() ) re_reaction_dict = { - "shoutId": reaction_dict["shoutId"], + "shout": reaction_dict["shout"], "replyTo": reaction.id, "kind": ReactionKind.LIKE if comment_rating_old["value"] > 0 @@ -150,14 +150,14 @@ async def migrate(entry, storage): following2 = session.query( ShoutReactionsFollower ).where( - ShoutReactionsFollower.followerId == re_reaction_dict['createdBy'] + ShoutReactionsFollower.follower == re_reaction_dict['createdBy'] ).filter( - ShoutReactionsFollower.shoutId == rr.shoutId + ShoutReactionsFollower.shout == rr.shout ).first() if not following2: following2 = ShoutReactionsFollower.create( - followerId=re_reaction_dict['createdBy'], - shoutId=rr.shoutId, + follower=re_reaction_dict['createdBy'], + shout=rr.shout, auto=True ) session.add(following2) @@ -190,13 +190,13 @@ def migrate_2stage(rr, old_new_id): session.add(comment) srf = session.query(ShoutReactionsFollower).where( - ShoutReactionsFollower.shoutId == comment.shoutId + ShoutReactionsFollower.shout == comment.shout ).filter( - ShoutReactionsFollower.followerId == comment.createdBy + ShoutReactionsFollower.follower == comment.createdBy ).first() if not srf: - srf = ShoutReactionsFollower.create(shoutId=comment.shoutId, followerId=comment.createdBy, auto=True) + srf = ShoutReactionsFollower.create(shout=comment.shout, follower=comment.createdBy, auto=True) session.add(srf) session.commit() diff --git a/migration/tables/content_items.py b/migration/tables/content_items.py index 5d1b67e9..628a4a1b 100644 --- a/migration/tables/content_items.py +++ b/migration/tables/content_items.py @@ -91,12 +91,12 @@ async def create_shout(shout_dict, userslug): ).join( User ).where( - ShoutReactionsFollower.shoutId == s.id + ShoutReactionsFollower.shout == s.id ).filter( User.slug == userslug ).first() if not srf: - srf = ShoutReactionsFollower.create(shoutId=s.id, followerId=follower.id, auto=True) + srf = ShoutReactionsFollower.create(shout=s.id, follower=follower.id, auto=True) session.add(srf) session.commit() @@ -226,15 +226,15 @@ async def add_topics_follower(entry, storage, userslug): tf = session.query( TopicFollower ).where( - TopicFollower.followerId == follower.id + TopicFollower.follower == follower.id ).filter( - TopicFollower.topicId == topic.id + TopicFollower.topic == topic.id ).first() if not tf: tf = TopicFollower.create( - topicId=topic.id, - followerId=follower.id, + topic=topic.id, + follower=follower.id, auto=True ) session.add(tf) @@ -325,7 +325,7 @@ async def topics_aftermath(entry, storage): .first() ) if shout_topic_old: - shout_topic_old.update({"topicId": new_topic.id}) + shout_topic_old.update({"topic": new_topic.id}) else: shout_topic_new = ( session.query(ShoutTopic) @@ -338,7 +338,7 @@ async def topics_aftermath(entry, storage): if not shout_topic_new: try: ShoutTopic.create( - **{"shoutId": shout.id, "topicId": new_topic.id} + **{"shout": shout.id, "topic": new_topic.id} ) except Exception: print("[migration] shout topic error: " + newslug) @@ -373,14 +373,14 @@ async def content_ratings_to_reactions(entry, slug): if content_rating["value"] > 0 else ReactionKind.DISLIKE, "createdBy": reactedBy.id, - "shoutId": shout.id, + "shout": shout.id, } cts = content_rating.get("createdAt") if cts: reaction_dict["createdAt"] = date_parse(cts) reaction = ( session.query(Reaction).filter( - Reaction.shoutId == reaction_dict["shoutId"] + Reaction.shout == reaction_dict["shout"] ).filter( Reaction.createdBy == reaction_dict["createdBy"] ).filter( diff --git a/migration/tables/users.py b/migration/tables/users.py index 320dd50e..1917ed47 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -124,14 +124,14 @@ def migrate_2stage(entry, id_map): user_rating_dict = { "value": rating_entry["value"], "raterId": rater.id, - "userId": user.id, + "user": user.id, } user_rating = UserRating.create(**user_rating_dict) if user_rating_dict['value'] > 0: af = AuthorFollower.create( - authorId=user.id, - followerId=rater.id, + author=user.id, + follower=rater.id, auto=True ) session.add(af) diff --git a/orm/collab.py b/orm/collab.py index accf650c..094c6391 100644 --- a/orm/collab.py +++ b/orm/collab.py @@ -11,7 +11,7 @@ class CollabAuthor(Base): id = None # type: ignore collab = Column(ForeignKey("collab.id"), primary_key=True) - authorId = Column(ForeignKey("user.id"), primary_key=True) + author = Column(ForeignKey("user.id"), primary_key=True) accepted = Column(Boolean, default=False) diff --git a/orm/collection.py b/orm/collection.py index 3f6eee3d..27dc52e4 100644 --- a/orm/collection.py +++ b/orm/collection.py @@ -9,7 +9,7 @@ class ShoutCollection(Base): __tablename__ = "shout_collection" id = None # type: ignore - shoutId = Column(ForeignKey("shout.id"), primary_key=True) + shout = Column(ForeignKey("shout.id"), primary_key=True) collectionId = Column(ForeignKey("collection.id"), primary_key=True) diff --git a/orm/community.py b/orm/community.py index c9d718e3..66ea5891 100644 --- a/orm/community.py +++ b/orm/community.py @@ -8,7 +8,7 @@ class CommunityFollower(Base): __tablename__ = "community_followers" id = None # type: ignore - followerId = Column(ForeignKey("user.id"), primary_key=True) + follower = Column(ForeignKey("user.id"), primary_key=True) communityId = Column(ForeignKey("community.id"), primary_key=True) joinedAt = Column( DateTime, nullable=False, default=datetime.now, comment="Created at" diff --git a/orm/reaction.py b/orm/reaction.py index e7df502f..f484808a 100644 --- a/orm/reaction.py +++ b/orm/reaction.py @@ -33,7 +33,7 @@ class Reaction(Base): updatedBy = Column(ForeignKey("user.id"), nullable=True, index=True, comment="Last Editor") deletedAt = Column(DateTime, nullable=True, comment="Deleted at") deletedBy = Column(ForeignKey("user.id"), nullable=True, index=True, comment="Deleted by") - shoutId = Column(ForeignKey("shout.id"), nullable=False, index=True) + shout = Column(ForeignKey("shout.id"), nullable=False, index=True) replyTo = Column( ForeignKey("reaction.id"), nullable=True, comment="Reply to reaction ID" ) diff --git a/orm/shout.py b/orm/shout.py index 72cf9053..55435d5f 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -13,16 +13,16 @@ class ShoutTopic(Base): __tablename__ = "shout_topic" id = None # type: ignore - shoutId = Column(ForeignKey("shout.id"), primary_key=True, index=True) - topicId = Column(ForeignKey("topic.id"), primary_key=True, index=True) + shout = Column(ForeignKey("shout.id"), primary_key=True, index=True) + topic = Column(ForeignKey("topic.id"), primary_key=True, index=True) class ShoutReactionsFollower(Base): __tablename__ = "shout_reactions_followers" id = None # type: ignore - followerId = Column(ForeignKey("user.id"), primary_key=True, index=True) - shoutId = Column(ForeignKey("shout.id"), primary_key=True, index=True) + follower = Column(ForeignKey("user.id"), primary_key=True, index=True) + shout = Column(ForeignKey("shout.id"), primary_key=True, index=True) auto = Column(Boolean, nullable=False, default=False) createdAt = Column( DateTime, nullable=False, default=datetime.now, comment="Created at" @@ -34,8 +34,8 @@ class ShoutAuthor(Base): __tablename__ = "shout_author" id = None # type: ignore - shoutId = Column(ForeignKey("shout.id"), primary_key=True, index=True) - userId = Column(ForeignKey("user.id"), primary_key=True, index=True) + shout = Column(ForeignKey("shout.id"), primary_key=True, index=True) + user = Column(ForeignKey("user.id"), primary_key=True, index=True) caption = Column(String, nullable=True, default="") diff --git a/orm/topic.py b/orm/topic.py index 94ed3968..a37dc69a 100644 --- a/orm/topic.py +++ b/orm/topic.py @@ -9,8 +9,8 @@ class TopicFollower(Base): __tablename__ = "topic_followers" id = None # type: ignore - followerId = Column(ForeignKey("user.id"), primary_key=True, index=True) - topicId = Column(ForeignKey("topic.id"), primary_key=True, index=True) + follower = Column(ForeignKey("user.id"), primary_key=True, index=True) + topic = Column(ForeignKey("topic.id"), primary_key=True, index=True) createdAt = Column( DateTime, nullable=False, default=datetime.now, comment="Created at" ) diff --git a/orm/user.py b/orm/user.py index ab30d861..076c63e7 100644 --- a/orm/user.py +++ b/orm/user.py @@ -11,7 +11,7 @@ from orm.rbac import Role class UserNotifications(Base): __tablename__ = "user_notifications" # id auto - userId = Column(Integer, ForeignKey("user.id")) + user = Column(Integer, ForeignKey("user.id")) kind = Column(String, ForeignKey("notification.kind")) values = Column(JSONType, nullable=True) # [ , .. ] @@ -21,7 +21,7 @@ class UserRating(Base): id = None # type: ignore raterId = Column(ForeignKey("user.id"), primary_key=True, index=True) - userId = Column(ForeignKey("user.id"), primary_key=True, index=True) + user = Column(ForeignKey("user.id"), primary_key=True, index=True) value = Column(Integer) @staticmethod @@ -33,7 +33,7 @@ class UserRole(Base): __tablename__ = "user_role" id = None # type: ignore - userId = Column(ForeignKey("user.id"), primary_key=True, index=True) + user = Column(ForeignKey("user.id"), primary_key=True, index=True) roleId = Column(ForeignKey("role.id"), primary_key=True, index=True) @@ -41,8 +41,8 @@ class AuthorFollower(Base): __tablename__ = "author_follower" id = None # type: ignore - followerId = Column(ForeignKey("user.id"), primary_key=True, index=True) - authorId = Column(ForeignKey("user.id"), primary_key=True, index=True) + follower = Column(ForeignKey("user.id"), primary_key=True, index=True) + author = Column(ForeignKey("user.id"), primary_key=True, index=True) createdAt = Column( DateTime, nullable=False, default=datetime.now, comment="Created at" ) @@ -72,7 +72,7 @@ class User(Base): links = Column(JSONType, nullable=True, comment="Links") oauth = Column(String, nullable=True) notifications = relationship(lambda: UserNotifications) - ratings = relationship(UserRating, foreign_keys=UserRating.userId) + ratings = relationship(UserRating, foreign_keys=UserRating.user) roles = relationship(lambda: Role, secondary=UserRole.__tablename__) oid = Column(String, nullable=True) diff --git a/orm/viewed.py b/orm/viewed.py index 60ec5cf4..be8a88e8 100644 --- a/orm/viewed.py +++ b/orm/viewed.py @@ -7,7 +7,7 @@ class ViewedEntry(Base): __tablename__ = "viewed" viewerId = Column(ForeignKey("user.id"), index=True, default=1) - shoutId = Column(ForeignKey("shout.id"), index=True, default=1) + shout = Column(ForeignKey("shout.id"), index=True, default=1) amount = Column(Integer, default=1) createdAt = Column( DateTime, nullable=False, default=datetime.now, comment="Created at" diff --git a/resolvers/create/editor.py b/resolvers/create/editor.py index 78f5d292..ed431375 100644 --- a/resolvers/create/editor.py +++ b/resolvers/create/editor.py @@ -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 diff --git a/resolvers/inbox/search.py b/resolvers/inbox/search.py index 15aa822f..5a1289ac 100644 --- a/resolvers/inbox/search.py +++ b/resolvers/inbox/search.py @@ -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) diff --git a/resolvers/zine/load.py b/resolvers/zine/load.py index 31b0a21b..63896348 100644 --- a/resolvers/zine/load.py +++ b/resolvers/zine/load.py @@ -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 diff --git a/resolvers/zine/profile.py b/resolvers/zine/profile.py index 85d87fe1..652a602a 100644 --- a/resolvers/zine/profile.py +++ b/resolvers/zine/profile.py @@ -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) diff --git a/resolvers/zine/reactions.py b/resolvers/zine/reactions.py index c85ba3a9..c0648fcd 100644 --- a/resolvers/zine/reactions.py +++ b/resolvers/zine/reactions.py @@ -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"): diff --git a/resolvers/zine/topics.py b/resolvers/zine/topics.py index 0a0aa29f..2ee6809b 100644 --- a/resolvers/zine/topics.py +++ b/resolvers/zine/topics.py @@ -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) diff --git a/services/stat/viewed.py b/services/stat/viewed.py index d749fc92..792552b9 100644 --- a/services/stat/viewed.py +++ b/services/stat/viewed.py @@ -128,7 +128,7 @@ class ViewedStorage: try: shout = session.query(Shout).where(Shout.slug == shout_slug).one() shout_views = session.query(func.sum(ViewedEntry.amount)).where( - ViewedEntry.shoutId == shout.id + ViewedEntry.shout == shout.id ).all()[0][0] self.by_shouts[shout_slug] = shout_views self.update_topics(session, shout_slug) @@ -169,7 +169,7 @@ class ViewedStorage: viewed = ViewedEntry.create(**{ "viewerId": viewer.id, - "shoutId": shout.id, + "shout": shout.id, "amount": amount }) session.add(viewed)