slugs fix, dev friendly, readme
This commit is contained in:
parent
1bd868b800
commit
8e57e8b7fb
18
README.md
18
README.md
|
@ -7,26 +7,26 @@ Tech stack:
|
|||
- ariadne
|
||||
- starlette
|
||||
|
||||
# Local development
|
||||
# Local development
|
||||
|
||||
Install redis and pipenv first
|
||||
Install redis and poetry (or any python env manager) first
|
||||
|
||||
on osx
|
||||
```
|
||||
brew install redis pipenv
|
||||
brew install redis poetry
|
||||
brew services start redis
|
||||
```
|
||||
|
||||
Create certificate files
|
||||
|
||||
```sh
|
||||
./create_crt.sh
|
||||
on debian/ubuntu
|
||||
```
|
||||
apt install redis python-poetry
|
||||
```
|
||||
|
||||
Then run API server
|
||||
|
||||
```
|
||||
pipenv install
|
||||
pipenv run python server.py
|
||||
poetry install
|
||||
poetry run python server.py
|
||||
```
|
||||
|
||||
Also see `Dockerfile`
|
||||
|
|
|
@ -7,8 +7,12 @@ from sqlalchemy.sql.schema import Table
|
|||
|
||||
from settings import DB_URL
|
||||
|
||||
engine = create_engine(DB_URL, convert_unicode=True, echo=False, \
|
||||
pool_size=10, max_overflow=20)
|
||||
if not DB_URL.startswith('sqlite'):
|
||||
engine = create_engine(DB_URL)
|
||||
else:
|
||||
|
||||
engine = create_engine(DB_URL, convert_unicode=True, echo=False, \
|
||||
pool_size=10, max_overflow=20)
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from resolvers.auth import login, sign_out, is_email_free, register, confirm
|
||||
from resolvers.zine import create_shout, get_shout_by_slug, top_month, top_overall, \
|
||||
recent_shouts, top_viewed, shouts_by_author, shouts_by_topic, \
|
||||
from resolvers.zine import create_shout, get_shout_by_slug, \
|
||||
top_month, top_overall, recent_shouts, top_viewed, shouts_by_authors, shouts_by_topics, shouts_by_communities, \
|
||||
shouts_candidates, shouts_reviewed, shouts_subscribed
|
||||
from resolvers.profile import get_users_by_slugs, get_current_user
|
||||
from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \
|
||||
|
@ -20,8 +20,9 @@ __all__ = [
|
|||
"get_users_by_slugs",
|
||||
"get_shout_by_slug",
|
||||
"recent_shouts",
|
||||
"shouts_by_topic",
|
||||
"shouts_by_author",
|
||||
"shouts_by_topics",
|
||||
"shouts_by_authors",
|
||||
"shouts_by_communities",
|
||||
"shouts_subscribed",
|
||||
"shouts_reviewed",
|
||||
"shouts_candidates",
|
||||
|
|
|
@ -376,38 +376,33 @@ async def get_shout_comments(_, info, slug):
|
|||
comment.author = await UserStorage.get_user(comment.author)
|
||||
return comments
|
||||
|
||||
@query.field("shoutsByTopic")
|
||||
async def shouts_by_topic(_, info, topic, page, size):
|
||||
@query.field("shoutsByTopics")
|
||||
async def shouts_by_topics(_, info, slugs, page, size):
|
||||
page = page - 1
|
||||
with local_session() as session:
|
||||
shouts = session.query(Shout).\
|
||||
join(ShoutTopic).\
|
||||
where(and_(ShoutTopic.topic == topic, Shout.publishedAt != None)).\
|
||||
where(and_(ShoutTopic.topic.in_(slugs), Shout.publishedAt != None)).\
|
||||
order_by(desc(Shout.publishedAt)).\
|
||||
limit(size).\
|
||||
offset(page * size)
|
||||
return shouts
|
||||
|
||||
@query.field("shoutsByAuthor")
|
||||
async def shouts_by_author(_, info, author, page, size):
|
||||
@query.field("shoutsByAuthors")
|
||||
async def shouts_by_authors(_, info, slugs, page, size):
|
||||
page = page - 1
|
||||
with local_session() as session:
|
||||
user = session.query(User).\
|
||||
filter(User.slug == author).first()
|
||||
if not user:
|
||||
print("author not exist")
|
||||
return
|
||||
|
||||
shouts = session.query(Shout).\
|
||||
join(ShoutAuthor).\
|
||||
where(and_(ShoutAuthor.user == author, Shout.publishedAt != None)).\
|
||||
where(and_(ShoutAuthor.user.in_(slugs), Shout.publishedAt != None)).\
|
||||
order_by(desc(Shout.publishedAt)).\
|
||||
limit(size).\
|
||||
offset(page * size)
|
||||
return shouts
|
||||
|
||||
@query.field("shoutsByCommunity")
|
||||
async def shouts_by_community(_, info, community, page, size):
|
||||
@query.field("shoutsByCommunities")
|
||||
async def shouts_by_communities(_, info, slugs, page, size):
|
||||
page = page - 1
|
||||
with local_session() as session:
|
||||
#TODO fix postgres high load
|
||||
|
@ -415,7 +410,7 @@ async def shouts_by_community(_, info, community, page, size):
|
|||
join(ShoutTopic).\
|
||||
where(and_(Shout.publishedAt != None,\
|
||||
ShoutTopic.topic.in_(\
|
||||
select(Topic.slug).where(Topic.community == community)\
|
||||
select(Topic.slug).where(Topic.community.in_(slugs))\
|
||||
))).\
|
||||
order_by(desc(Shout.publishedAt)).\
|
||||
limit(size).\
|
||||
|
|
|
@ -157,9 +157,9 @@ type Query {
|
|||
|
||||
# shouts
|
||||
getShoutBySlug(slug: String!): Shout!
|
||||
shoutsByTopic(topic: String!, page: Int!, size: Int!): [Shout]!
|
||||
shoutsByAuthor(author: String!, page: Int!, size: Int!): [Shout]!
|
||||
shoutsByCommunity(community: String!, page: Int!, size: Int!): [Shout]!
|
||||
shoutsByTopics(slugs: [String]!, page: Int!, size: Int!): [Shout]!
|
||||
shoutsByAuthors(slugs: [String]!, page: Int!, size: Int!): [Shout]!
|
||||
shoutsByCommunities(slugs: [String]!, page: Int!, size: Int!): [Shout]!
|
||||
getShoutComments(slug: String!): [Comment]!
|
||||
|
||||
# mainpage
|
||||
|
|
Loading…
Reference in New Issue
Block a user