type fix
This commit is contained in:
parent
aaca27ba88
commit
d5c654eace
|
@ -6,6 +6,7 @@ from orm.topic import Topic
|
||||||
from orm.notification import Notification
|
from orm.notification import Notification
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay
|
||||||
from orm.base import Base, engine
|
from orm.base import Base, engine
|
||||||
|
from orm.comment import Comment
|
||||||
|
|
||||||
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Notification"]
|
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Notification"]
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ from typing import List
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from orm import Permission
|
|
||||||
from orm.base import Base
|
from orm.base import Base
|
||||||
|
|
||||||
class CommentRating(Base):
|
class CommentRating(Base):
|
||||||
|
@ -16,17 +16,17 @@ class CommentRating(Base):
|
||||||
value = Column(Integer)
|
value = Column(Integer)
|
||||||
|
|
||||||
class Comment(Base):
|
class Comment(Base):
|
||||||
__tablename__ = 'Comment'
|
__tablename__ = 'comment'
|
||||||
|
|
||||||
author: int = Column(ForeignKey("user.id"), nullable=False, comment="Sender")
|
author: int = Column(ForeignKey("user.id"), nullable=False, comment="Sender")
|
||||||
body: str = Column(String, nullable=False, comment="Body")
|
body: str = Column(String, nullable=False, comment="Body")
|
||||||
createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||||
updatedAt = Column(DateTime, nullable=True, comment="Updated at")
|
updatedAt = Column(DateTime, nullable=True, comment="Updated at")
|
||||||
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
||||||
deletedBy = Column(ForeignKey("user.id"), nullable=True, comment="Deleted by")
|
deletedBy = Column(ForeignKey("user.id"), nullable=True, comment="Deleted by")
|
||||||
shout: int = Column(ForeignKey("shout.id"), nullable=True, comment="Shout ID")
|
shout: int = Column(ForeignKey("shout.id"), nullable=True, comment="Shout ID")
|
||||||
ratings = relationship(CommentRating, foreign_keys=CommentRating.comment_id)
|
ratings = relationship(CommentRating, foreign_keys=CommentRating.comment_id)
|
||||||
old_id: str = Column(String, nullable = True)
|
old_id: str = Column(String, nullable = True)
|
||||||
|
|
||||||
|
|
||||||
# TODO: work in progress, udpate this code
|
# TODO: work in progress, udpate this code
|
||||||
|
|
11
orm/shout.py
11
orm/shout.py
|
@ -2,7 +2,8 @@ from typing import List
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import Table, Column, Integer, String, ForeignKey, DateTime, Boolean
|
from sqlalchemy import Table, Column, Integer, String, ForeignKey, DateTime, Boolean
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from orm import Permission, User, Topic, Comment
|
from orm import Permission, User, Topic
|
||||||
|
from orm.comment import Comment
|
||||||
from orm.base import Base
|
from orm.base import Base
|
||||||
|
|
||||||
class ShoutAuthor(Base):
|
class ShoutAuthor(Base):
|
||||||
|
@ -13,11 +14,11 @@ class ShoutAuthor(Base):
|
||||||
user = Column(ForeignKey('user.id'), primary_key = True)
|
user = Column(ForeignKey('user.id'), primary_key = True)
|
||||||
|
|
||||||
class ShoutViewer(Base):
|
class ShoutViewer(Base):
|
||||||
__tablename__ = "shout_viewer"
|
__tablename__ = "shout_viewer"
|
||||||
|
|
||||||
id = None
|
id = None
|
||||||
shout = Column(ForeignKey('shout.id'), primary_key = True)
|
shout = Column(ForeignKey('shout.id'), primary_key = True)
|
||||||
user = Column(ForeignKey('user.id'), primary_key = True)
|
user = Column(ForeignKey('user.id'), primary_key = True)
|
||||||
|
|
||||||
class ShoutTopic(Base):
|
class ShoutTopic(Base):
|
||||||
__tablename__ = 'shout_topic'
|
__tablename__ = 'shout_topic'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from resolvers.auth import login, sign_out, get_user, is_email_free, register, confirm
|
from resolvers.auth import login, sign_out, is_email_free, register, confirm
|
||||||
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
||||||
from resolvers.zine import create_shout, get_shout_by_slug
|
from resolvers.zine import create_shout, get_shout_by_slug
|
||||||
from resolvers.profile import get_user_by_slug, get_current_user
|
from resolvers.profile import get_user_by_slug, get_current_user
|
||||||
|
|
|
@ -6,14 +6,14 @@ import asyncio
|
||||||
|
|
||||||
@query.field("getUserBySlug") # get a public profile
|
@query.field("getUserBySlug") # get a public profile
|
||||||
async def get_user_by_slug(_, info, slug):
|
async def get_user_by_slug(_, info, slug):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).filter(User.slug == slug).first()
|
user = session.query(User).filter(User.slug == slug).first()
|
||||||
return { "user": user } # TODO: remove some fields for public
|
return { "user": user } # TODO: remove some fields for public
|
||||||
|
|
||||||
|
|
||||||
@query.field("getCurrentUser")
|
@query.field("getCurrentUser")
|
||||||
@login_required
|
@login_required
|
||||||
async def get_user(_, info):
|
async def get_current_user(_, info):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
|
|
|
@ -260,13 +260,10 @@ async def update_shout(_, info, id, input):
|
||||||
|
|
||||||
@query.field("getShoutBySlug") #FIXME: add shout joined with comments
|
@query.field("getShoutBySlug") #FIXME: add shout joined with comments
|
||||||
async def get_shout_by_slug(_, info, slug):
|
async def get_shout_by_slug(_, info, slug):
|
||||||
# month_ago = datetime.now() - timedelta(days = 30)
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
stmt = select(Shout, func.sum(ShoutRating.value).label("rating")).\
|
stmt = select(Shout, func.sum(ShoutRating.value).label("rating")).\
|
||||||
join(ShoutRating).\
|
join(ShoutRating).\
|
||||||
# where(ShoutRating.ts > month_ago).\
|
|
||||||
where(Shout.slug == slug).\
|
where(Shout.slug == slug).\
|
||||||
# TODO: join(Comment) to .comments
|
|
||||||
limit(limit)
|
limit(limit)
|
||||||
shouts = []
|
shouts = []
|
||||||
for row in session.execute(stmt):
|
for row in session.execute(stmt):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user