community added, like removed
This commit is contained in:
parent
b1dd4c52b5
commit
85f697addd
17
orm/community.py
Normal file
17
orm/community.py
Normal file
|
@ -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")
|
||||||
|
|
17
orm/like.py
17
orm/like.py
|
@ -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.
|
|
10
orm/rbac.py
10
orm/rbac.py
|
@ -27,18 +27,14 @@ class ClassType(TypeDecorator):
|
||||||
warnings.warn(f"Can't find class <{value}>,find it yourself!", stacklevel=2)
|
warnings.warn(f"Can't find class <{value}>,find it yourself!", stacklevel=2)
|
||||||
return class_
|
return class_
|
||||||
|
|
||||||
class Organization(Base):
|
|
||||||
__tablename__ = 'organization'
|
|
||||||
name: str = Column(String, nullable=False, unique=True, comment="Organization Name")
|
|
||||||
|
|
||||||
class Role(Base):
|
class Role(Base):
|
||||||
__tablename__ = 'role'
|
__tablename__ = 'role'
|
||||||
|
|
||||||
id: int = Column(Integer, primary_key=True)
|
# id is auto field
|
||||||
|
|
||||||
name: str = Column(String, nullable=False, comment="Role Name")
|
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)
|
permissions = relationship(lambda: Permission)
|
||||||
|
|
||||||
class Operation(Base):
|
class Operation(Base):
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Shout(Base):
|
||||||
# NOTE: automatic ID here
|
# NOTE: automatic ID here
|
||||||
|
|
||||||
slug: str = Column(String, nullable=False, unique=True)
|
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")
|
body: str = Column(String, nullable=False, comment="Body")
|
||||||
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||||
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
|
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
from typing import List
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import Table, Column, Integer, String, ForeignKey, DateTime, UniqueConstraint
|
from sqlalchemy import Table, Column, Integer, String, ForeignKey, DateTime, UniqueConstraint
|
||||||
from sqlalchemy.orm import relationship, backref
|
from sqlalchemy.orm import relationship
|
||||||
from orm import Permission
|
|
||||||
from orm.base import Base
|
from orm.base import Base
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +16,6 @@ class Topic(Base):
|
||||||
__tablename__ = 'topic'
|
__tablename__ = 'topic'
|
||||||
|
|
||||||
slug: str = Column(String, unique = True, nullable = False)
|
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")
|
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||||
createdBy: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
|
createdBy: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
|
||||||
value: str = Column(String, nullable=False, comment="Value")
|
value: str = Column(String, nullable=False, comment="Value")
|
||||||
|
|
|
@ -30,6 +30,12 @@ UserRoles = Table("user_roles",
|
||||||
Column('role_id', Integer, ForeignKey('role.id'))
|
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):
|
class User(Base):
|
||||||
__tablename__ = "user"
|
__tablename__ = "user"
|
||||||
|
|
||||||
|
@ -50,6 +56,7 @@ class User(Base):
|
||||||
notifications = relationship(lambda: UserNotifications)
|
notifications = relationship(lambda: UserNotifications)
|
||||||
ratings = relationship(UserRatings, foreign_keys=UserRatings.user_id)
|
ratings = relationship(UserRatings, foreign_keys=UserRatings.user_id)
|
||||||
roles = relationship(lambda: Role, secondary=UserRoles)
|
roles = relationship(lambda: Role, secondary=UserRoles)
|
||||||
|
topics = relationship(lambda: Topic, secondary=UserTopics)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_permission(cls, user_id):
|
def get_permission(cls, user_id):
|
||||||
|
|
|
@ -120,8 +120,7 @@ type Subscription {
|
||||||
type Role {
|
type Role {
|
||||||
id: Int!
|
id: Int!
|
||||||
name: String!
|
name: String!
|
||||||
org_id: Int!
|
community: Int!
|
||||||
# level: Int! # 1-8
|
|
||||||
desc: String
|
desc: String
|
||||||
permissions: [Int!]!
|
permissions: [Int!]!
|
||||||
}
|
}
|
||||||
|
@ -164,6 +163,8 @@ type User {
|
||||||
ratings: [Rating]
|
ratings: [Rating]
|
||||||
bio: String
|
bio: String
|
||||||
notifications: [Int]
|
notifications: [Int]
|
||||||
|
topics: [String] # user subscribed topics
|
||||||
|
communities: [Int] # user participating communities
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message {
|
type Message {
|
||||||
|
@ -178,21 +179,21 @@ type Message {
|
||||||
|
|
||||||
# is publication
|
# is publication
|
||||||
type Shout {
|
type Shout {
|
||||||
org_id: Int!
|
|
||||||
slug: String
|
|
||||||
authors: [Int!]!
|
authors: [Int!]!
|
||||||
cover: String
|
slug: String!
|
||||||
layout: String
|
|
||||||
body: String!
|
body: String!
|
||||||
createdAt: DateTime!
|
createdAt: DateTime!
|
||||||
updatedAt: DateTime!
|
updatedAt: DateTime!
|
||||||
|
community: Int
|
||||||
|
cover: String
|
||||||
|
layout: String
|
||||||
deletedAt: DateTime
|
deletedAt: DateTime
|
||||||
deletedBy: Int
|
deletedBy: Int
|
||||||
rating: Int
|
rating: Int
|
||||||
ratigns: [Rating]
|
ratigns: [Rating]
|
||||||
published: Boolean!
|
published: Boolean!
|
||||||
publishedAt: DateTime # if there is no published field - it is not published
|
publishedAt: DateTime # if there is no published field - it is not published
|
||||||
replyTo: String # another shout
|
replyTo: Int # another shout
|
||||||
tags: [String] # actual values
|
tags: [String] # actual values
|
||||||
topics: [String] # topic-slugs, order has matter
|
topics: [String] # topic-slugs, order has matter
|
||||||
title: String
|
title: String
|
||||||
|
@ -204,6 +205,13 @@ type Shout {
|
||||||
old_id: String
|
old_id: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Community {
|
||||||
|
slug: String!
|
||||||
|
name: String!
|
||||||
|
desc: String
|
||||||
|
pic: String!
|
||||||
|
}
|
||||||
|
|
||||||
type Topic {
|
type Topic {
|
||||||
slug: String! # ID
|
slug: String! # ID
|
||||||
createdBy: Int! # User
|
createdBy: Int! # User
|
||||||
|
@ -232,11 +240,3 @@ type Token {
|
||||||
usedAt: DateTime
|
usedAt: DateTime
|
||||||
value: String!
|
value: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Like {
|
|
||||||
author: Int!
|
|
||||||
id: Int!
|
|
||||||
value: Int!
|
|
||||||
shout: Int
|
|
||||||
user: Int
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user