diff --git a/orm/community.py b/orm/community.py new file mode 100644 index 00000000..25f27755 --- /dev/null +++ b/orm/community.py @@ -0,0 +1,17 @@ +from datetime import datetime +from sqlalchemy import Column, Integer, String, ForeignKey, DateTime +from sqlalchemy.orm import relationship, backref +from orm.base import Base + + +class Community(Base): + __tablename__ = 'community' + # id is auto number + name: str = Column(String, nullable=False, comment="Name") + slug: str = Column(String, unique = True, nullable = False) + desc: str = Column(String, nullable=False, default='') + pic: str = Column(String, nullable=False, default='') + org_id: str = Column(ForeignKey("organization.id"), nullable=True) + createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at") + createdBy: str = Column(ForeignKey("user.id"), nullable=False, comment="Creator") + \ No newline at end of file diff --git a/orm/like.py b/orm/like.py deleted file mode 100644 index 91996087..00000000 --- a/orm/like.py +++ /dev/null @@ -1,17 +0,0 @@ -from typing import List - -from sqlalchemy import Column, Integer, String, ForeignKey, Datetime - -from orm import Permission -from orm.base import Base - - -class Like(Base): - __tablename__ = 'like' - - id: int = None - user_id: str = Column(ForeignKey("user.id"), comment="Author", primary_key = True) - shout_id: int = Column(Integer, ForeignKey("shout.id"), comment="Liked shout id", primary_key = True) - value: int = Column(Integer, nullable=False, comment="Value") - - # TODO: add resolvers, debug, etc. diff --git a/orm/rbac.py b/orm/rbac.py index 07563a12..e205f233 100644 --- a/orm/rbac.py +++ b/orm/rbac.py @@ -27,18 +27,14 @@ class ClassType(TypeDecorator): warnings.warn(f"Can't find class <{value}>,find it yourself!", stacklevel=2) return class_ -class Organization(Base): - __tablename__ = 'organization' - name: str = Column(String, nullable=False, unique=True, comment="Organization Name") - class Role(Base): __tablename__ = 'role' - id: int = Column(Integer, primary_key=True) - + # id is auto field + name: str = Column(String, nullable=False, comment="Role Name") - org_id: int = Column(ForeignKey("organization.id", ondelete="CASCADE"), nullable=False, comment="Organization") - + desc: str = Colulm(String, nullable=True, comment="Role Description") + community: int = Column(ForeignKey("community.id", ondelete="CASCADE"), nullable=False, comment="Community") permissions = relationship(lambda: Permission) class Operation(Base): diff --git a/orm/shout.py b/orm/shout.py index f54a6889..a0a9113f 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -31,7 +31,7 @@ class Shout(Base): # NOTE: automatic ID here slug: str = Column(String, nullable=False, unique=True) - org_id: int = Column(Integer, ForeignKey("organization.id"), nullable=False, comment="Organization") + community: int = Column(Integer, ForeignKey("community.id"), nullable=True, comment="Community") body: str = Column(String, nullable=False, comment="Body") createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at") updatedAt: str = Column(DateTime, nullable=True, comment="Updated at") diff --git a/orm/topic.py b/orm/topic.py index f8edca43..6b9e3c97 100644 --- a/orm/topic.py +++ b/orm/topic.py @@ -1,8 +1,6 @@ -from typing import List from datetime import datetime from sqlalchemy import Table, Column, Integer, String, ForeignKey, DateTime, UniqueConstraint -from sqlalchemy.orm import relationship, backref -from orm import Permission +from sqlalchemy.orm import relationship from orm.base import Base @@ -18,7 +16,6 @@ class Topic(Base): __tablename__ = 'topic' slug: str = Column(String, unique = True, nullable = False) - org_id: str = Column(ForeignKey("organization.id"), nullable=False) createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at") createdBy: str = Column(ForeignKey("user.id"), nullable=False, comment="Author") value: str = Column(String, nullable=False, comment="Value") diff --git a/orm/user.py b/orm/user.py index f55fde40..48b31f74 100644 --- a/orm/user.py +++ b/orm/user.py @@ -30,6 +30,12 @@ UserRoles = Table("user_roles", Column('role_id', Integer, ForeignKey('role.id')) ) +UserTopics = Table("user_topics", + Base.metadata, + Column('user_id', Integer, ForeignKey('user.id')), + Column('topic_id', Integer, ForeignKey('topic.id')) +) + class User(Base): __tablename__ = "user" @@ -50,6 +56,7 @@ class User(Base): notifications = relationship(lambda: UserNotifications) ratings = relationship(UserRatings, foreign_keys=UserRatings.user_id) roles = relationship(lambda: Role, secondary=UserRoles) + topics = relationship(lambda: Topic, secondary=UserTopics) @classmethod def get_permission(cls, user_id): diff --git a/schema.graphql b/schema.graphql index fa658eb5..95f68453 100644 --- a/schema.graphql +++ b/schema.graphql @@ -120,8 +120,7 @@ type Subscription { type Role { id: Int! name: String! - org_id: Int! - # level: Int! # 1-8 + community: Int! desc: String permissions: [Int!]! } @@ -164,6 +163,8 @@ type User { ratings: [Rating] bio: String notifications: [Int] + topics: [String] # user subscribed topics + communities: [Int] # user participating communities } type Message { @@ -178,21 +179,21 @@ type Message { # is publication type Shout { - org_id: Int! - slug: String authors: [Int!]! - cover: String - layout: String + slug: String! body: String! createdAt: DateTime! updatedAt: DateTime! + community: Int + cover: String + layout: String deletedAt: DateTime deletedBy: Int rating: Int ratigns: [Rating] published: Boolean! publishedAt: DateTime # if there is no published field - it is not published - replyTo: String # another shout + replyTo: Int # another shout tags: [String] # actual values topics: [String] # topic-slugs, order has matter title: String @@ -204,6 +205,13 @@ type Shout { old_id: String } +type Community { + slug: String! + name: String! + desc: String + pic: String! +} + type Topic { slug: String! # ID createdBy: Int! # User @@ -231,12 +239,4 @@ type Token { ownerId: Int! usedAt: DateTime value: String! -} - -type Like { - author: Int! - id: Int! - value: Int! - shout: Int - user: Int -} +} \ No newline at end of file