diff --git a/orm/notification.py b/orm/notification.py new file mode 100644 index 00000000..aa9cfab1 --- /dev/null +++ b/orm/notification.py @@ -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) # [ , .. ] + +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) # [ , .. ] \ No newline at end of file diff --git a/orm/rating.py b/orm/rating.py new file mode 100644 index 00000000..86b62031 --- /dev/null +++ b/orm/rating.py @@ -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) \ No newline at end of file diff --git a/orm/shout.py b/orm/shout.py index dd43f5ec..45459473 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -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 diff --git a/orm/user.py b/orm/user.py index 804c7b2b..a73da42b 100644 --- a/orm/user.py +++ b/orm/user.py @@ -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 diff --git a/schema.graphql b/schema.graphql index c682f3aa..de0b0af7 100644 --- a/schema.graphql +++ b/schema.graphql @@ -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 { diff --git a/settings.py b/settings.py index 124750c0..5660bdc6 100644 --- a/settings.py +++ b/settings.py @@ -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