user model upgrade, rating, notificaiton

This commit is contained in:
Untone 2021-08-19 13:02:28 +03:00
parent 5bb4553360
commit 0cb0b85bce
6 changed files with 82 additions and 17 deletions

17
orm/notification.py Normal file
View File

@ -0,0 +1,17 @@
from sqlalchemy import Column, Integer, String, ForeignKey, JSON as JSONType
from orm.base import Base
class Notification(Base):
__tablename__ = 'notification'
kind: str = Column(String, primary_key = True)
template: str = Column(String, nullable = False)
variables: JSONType = Column(JSONType, nullable = True) # [ <var1>, .. ]
class UserNotification(Base):
__tablename__ = 'user_notification'
id: int = Column(Integer, primary_key = True)
user: int = Column(ForeignKey("user.id"))
kind: int = Column(ForeignKey("notification.kind"), nullable = False)
values: JSONType = Column(JSONType, nullable = True) # [ <var1>, .. ]

10
orm/rating.py Normal file
View File

@ -0,0 +1,10 @@
from sqlalchemy import Column, Integer, String, ForeignKey
from orm.base import Base
class Rating(Base):
__tablename__ = 'rating'
id: int = Column(Integer, primary_key = True)
createdBy: int = Column(ForeignKey("user.id"), primary_key = True)
value: int = Column(Integer, nullable=False)

View File

@ -21,5 +21,6 @@ class Shout(Base):
versionOf: str = Column(ForeignKey("shout.slug"), nullable=True)
tags: str = Column(String, nullable=True)
topics: str = Column(String, nullable=True)
views: int = Column(Integer, default=0)
# TODO: add all the fields

View File

@ -1,28 +1,39 @@
from typing import List
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, DateTime
from sqlalchemy.orm import relationship
from orm import Permission
from orm.base import Base, local_session
from orm.rating import Rating
from orm.notification import UserNotification
class UserRole(Base):
__tablename__ = 'user_role'
id = None
id: int = Column(Integer, primary_key = True)
user_id: int = Column(ForeignKey("user.id"), primary_key = True)
role_id: int = Column(ForeignKey("role.id"), primary_key = True)
role: str = Column(ForeignKey("role.name"), primary_key = True)
class User(Base):
__tablename__ = 'user'
email: str = Column(String, unique=True, nullable=False)
username: str = Column(String, nullable=False, comment="Name")
email: str = Column(String, unique=True, nullable=False, comment="Email")
username: str = Column(String, nullable=False, comment="Login")
password: str = Column(String, nullable=True, comment="Password")
oauth_id: str = Column(String, nullable=True)
bio: str = Column(String, nullable=True, comment="Bio")
userpic: str = Column(String, nullable=True, comment="Userpic")
viewname: str = Column(String, nullable=True, comment="Display name")
rating: int = Column(Integer, nullable=True, comment="Rating")
slug: str = Column(String, unique=True, nullable=True, comment="Slug")
muted: bool = Column(Boolean, default=False)
emailConfirmed: bool = Column(Boolean, default=False)
createdAt: DateTime = Column(DateTime, nullable=False, comment="Created at")
wasOnlineAt: DateTime = Column(DateTime, nullable=False, comment="Was online at")
links: JSON = Column(JSON, nullable=True, comment="Links")
oauth: str = Column(String, nullable=True)
notifications = relationship("Notification", secondary=UserNotification.__table__)
ratings = relationship("Rating", secondary=Rating.__table__)
roles = relationship("Role", secondary=UserRole.__table__)
@classmethod

View File

@ -55,13 +55,14 @@ type Mutation {
deleteMessage(messageId: Int!): Result!
# auth
# resetPassword(password: String!, token: String!): Token!
confirmEmail(token: String!): AuthResult!
requestPasswordReset(email: String!): Boolean!
confirmPasswordReset(token: String!): Boolean!
registerUser(email: String!, password: String!): AuthResult!
# updatePassword(password: String!, token: String!): Token!
# invalidateAllTokens: Boolean!
# invalidateTokenById(id: Int!): Boolean!
# requestEmailConfirmation: User!
# requestPasswordReset(email: String!): Boolean!
registerUser(email: String!, password: String!): AuthResult!
# shout
createShout(input: ShoutInput!): ShoutResult!
@ -123,21 +124,44 @@ type Role {
desc: String
}
type Rating {
createdBy: String!
value: Int!
}
type Notification {
kind: String! # unique primary key
template: String!
variables: [String]
}
type UserNotification {
id: Int! # primary key
user: Int!
kind: String! # NotificationTemplate.name
values: [String]
}
type User {
username: String! # email
createdAt: DateTime!
email: String
password: String
oauth: String # provider:token
viewname: String # to display
userpic: String
links: [String]
emailConfirmed: Boolean
emailConfirmed: Boolean # should contain all emails too # TODO: pagination here
id: Int!
muted: Boolean
rating: Int
roles: [Role!]!
createdAt: DateTime!
updatedAt: DateTime!
roles: [Role]
updatedAt: DateTime
wasOnlineAt: DateTime
ratings: [Rating]
slug: String
bio: String
notifications: [Int]
}
type Message {
@ -161,6 +185,7 @@ type Shout {
deletedAt: DateTime
deletedBy: Int
rating: Int
ratigns: [Rating]
published: DateTime # if there is no published field - it is not published
replyTo: String # another shout
tags: [String] # actual values
@ -169,6 +194,7 @@ type Shout {
versionOf: String
visibleForRoles: [String] # role ids are strings
visibleForUsers: [Int]
views: Int
}
type Topic {

View File

@ -3,7 +3,7 @@ from os import environ
PORT = 8080
DB_URL = environ.get("DB_URL") or "sqlite:///database.sqlite3"
DB_URL = environ.get("DB_URL") or "sqlite:///db.sqlite3"
JWT_ALGORITHM = "HS256"
JWT_SECRET_KEY = "8f1bd7696ffb482d8486dfbc6e7d16dd-secret-key"
JWT_LIFE_SPAN = 24 * 60 * 60 # seconds