communityfollower-roles
All checks were successful
Deploy on push / deploy (push) Successful in 1m3s
All checks were successful
Deploy on push / deploy (push) Successful in 1m3s
This commit is contained in:
parent
0cf963240e
commit
635ff4285e
|
@ -6,6 +6,7 @@
|
||||||
- get_communities_all resolver fix
|
- get_communities_all resolver fix
|
||||||
- reaction filter by kinds
|
- reaction filter by kinds
|
||||||
- reaction sort enum added
|
- reaction sort enum added
|
||||||
|
- community follower roles enum added
|
||||||
|
|
||||||
[0.4.4]
|
[0.4.4]
|
||||||
- followers_stat removed for shout
|
- followers_stat removed for shout
|
||||||
|
|
|
@ -1,20 +1,29 @@
|
||||||
import time
|
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Integer, String, func
|
|
||||||
from sqlalchemy.ext.hybrid import hybrid_property
|
from sqlalchemy.ext.hybrid import hybrid_property
|
||||||
|
from sqlalchemy import ARRAY, Column, ForeignKey, Integer, String, func, Enum
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
import enum
|
||||||
|
import time
|
||||||
|
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
from services.db import Base
|
from services.db import Base
|
||||||
|
|
||||||
|
|
||||||
|
class CommunityRole(enum.Enum):
|
||||||
|
AUTHOR = "author"
|
||||||
|
READER = "reader"
|
||||||
|
EDITOR = "editor"
|
||||||
|
CRITIC = "critic"
|
||||||
|
EXPERT = "expert"
|
||||||
|
ARTIST = "artist"
|
||||||
|
|
||||||
|
|
||||||
class CommunityFollower(Base):
|
class CommunityFollower(Base):
|
||||||
__tablename__ = "community_author"
|
__tablename__ = "community_author"
|
||||||
|
|
||||||
author = Column(ForeignKey("author.id"), primary_key=True)
|
author = Column(ForeignKey("author.id"), primary_key=True)
|
||||||
community = Column(ForeignKey("community.id"), primary_key=True)
|
community = Column(ForeignKey("community.id"), primary_key=True)
|
||||||
joined_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
|
joined_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
|
||||||
role = Column(String, nullable=False)
|
roles = Column(ARRAY(Enum(CommunityRole)), nullable=False, default=[CommunityRole.READER])
|
||||||
|
|
||||||
|
|
||||||
class Community(Base):
|
class Community(Base):
|
||||||
|
@ -40,12 +49,17 @@ class CommunityStats:
|
||||||
@property
|
@property
|
||||||
def shouts(self):
|
def shouts(self):
|
||||||
from orm.shout import ShoutCommunity
|
from orm.shout import ShoutCommunity
|
||||||
return self.community.session.query(func.count(ShoutCommunity.shout_id))\
|
|
||||||
.filter(ShoutCommunity.community_id == self.community.id)\
|
return (
|
||||||
|
self.community.session.query(func.count(ShoutCommunity.shout_id))
|
||||||
|
.filter(ShoutCommunity.community_id == self.community.id)
|
||||||
.scalar()
|
.scalar()
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def followers(self):
|
def followers(self):
|
||||||
return self.community.session.query(func.count(CommunityFollower.author))\
|
return (
|
||||||
.filter(CommunityFollower.community == self.community.id)\
|
self.community.session.query(func.count(CommunityFollower.author))
|
||||||
|
.filter(CommunityFollower.community == self.community.id)
|
||||||
.scalar()
|
.scalar()
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user