classic comments entity wip
This commit is contained in:
parent
abefcf5039
commit
8b8942225b
32
orm/comment.py
Normal file
32
orm/comment.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
from typing import List
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||||
|
|
||||||
|
from orm import Permission
|
||||||
|
from orm.base import Base
|
||||||
|
|
||||||
|
class CommentRating(Base):
|
||||||
|
__tablename__ = "comment_rating"
|
||||||
|
|
||||||
|
id = None
|
||||||
|
rater_id = Column(ForeignKey('user.id'), primary_key = True)
|
||||||
|
comment_id = Column(ForeignKey('comment.id'), primary_key = True)
|
||||||
|
ts: str = Column(DateTime, nullable=False, default = datetime.now, comment="Timestamp")
|
||||||
|
value = Column(Integer)
|
||||||
|
|
||||||
|
class Comment(Base):
|
||||||
|
__tablename__ = 'Comment'
|
||||||
|
|
||||||
|
author: int = Column(ForeignKey("user.id"), nullable=False, comment="Sender")
|
||||||
|
body: str = Column(String, nullable=False, comment="Body")
|
||||||
|
createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||||
|
updatedAt = Column(DateTime, nullable=True, comment="Updated at")
|
||||||
|
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
||||||
|
deletedBy = Column(ForeignKey("user.id"), nullable=True, comment="Deleted by")
|
||||||
|
shout: int = Column(ForeignKey("shout.id"), nullable=True, comment="Shout ID")
|
||||||
|
ratings = relationship(CommentRating, foreign_keys=CommentRating.comment_id)
|
||||||
|
old_id: str = Column(String, nullable = True)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: work in progress, udpate this code
|
|
@ -260,14 +260,14 @@ async def update_shout(_, info, id, input):
|
||||||
|
|
||||||
# TODO: get shout with comments query
|
# TODO: get shout with comments query
|
||||||
|
|
||||||
@query.field("getShout")
|
@query.field("getShout") #FIXME: add shout joined with comments
|
||||||
async def get_shout(_, info, shout_slug):
|
async def get_shout(_, info, shout_id):
|
||||||
month_ago = datetime.now() - timedelta(days = 30)
|
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(Comment, func.sum(CommentRating.value).label("rating")).\
|
||||||
join(ShoutRating).\
|
join(CommentRating).\
|
||||||
where(ShoutRating.ts > month_ago).\
|
where(CommentRating.ts > month_ago).\
|
||||||
# where(Shout.replyTo == shout_slug).\
|
where(Comment.shout == shout_id).\
|
||||||
# join(ShoutComment)
|
# join(ShoutComment)
|
||||||
group_by(Shout.id).\
|
group_by(Shout.id).\
|
||||||
order_by(desc("rating")).\
|
order_by(desc("rating")).\
|
||||||
|
|
|
@ -180,6 +180,21 @@ type Message {
|
||||||
visibleForUsers: [Int]!
|
visibleForUsers: [Int]!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Comment {
|
||||||
|
id: Int!
|
||||||
|
author: Int!
|
||||||
|
body: String!
|
||||||
|
createdAt: DateTime!
|
||||||
|
updatedAt: DateTime!
|
||||||
|
shout: Int!
|
||||||
|
deletedAt: DateTime
|
||||||
|
deletedBy: Int
|
||||||
|
rating: Int
|
||||||
|
ratigns: [Rating]
|
||||||
|
views: Int
|
||||||
|
old_id: String
|
||||||
|
}
|
||||||
|
|
||||||
# is publication
|
# is publication
|
||||||
type Shout {
|
type Shout {
|
||||||
id: Int!
|
id: Int!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user