community added, like removed

This commit is contained in:
Untone 2021-08-27 00:14:20 +03:00
parent b1dd4c52b5
commit 85f697addd
7 changed files with 46 additions and 46 deletions

17
orm/community.py Normal file
View 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")

View File

@ -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.

View File

@ -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):

View File

@ -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")

View File

@ -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")

View File

@ -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):

View File

@ -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
}
}