core/resolvers/zine.py

54 lines
1.2 KiB
Python
Raw Normal View History

2021-07-27 04:58:06 +00:00
from orm import Shout, User
2021-08-07 16:14:20 +00:00
from orm.base import local_session
2021-07-27 04:58:06 +00:00
2021-08-07 16:14:20 +00:00
from resolvers.base import mutation, query
from auth.authenticate import login_required
from settings import SHOUTS_REPO
import subprocess
2021-07-27 04:58:06 +00:00
2021-07-27 05:41:45 +00:00
@query.field("topShouts")
2021-08-07 16:14:20 +00:00
async def top_shouts(_, info):
2021-07-27 05:41:45 +00:00
# TODO: implement top shouts
pass
@query.field("topAuthors")
2021-08-07 16:14:20 +00:00
async def top_shouts(_, info):
2021-07-27 05:41:45 +00:00
# TODO: implement top authors
pass
2021-07-27 04:58:06 +00:00
@mutation.field("createShout")
@login_required
2021-08-07 16:14:20 +00:00
async def create_shout(_, info, body):
2021-07-27 04:58:06 +00:00
auth = info.context["request"].auth
user_id = auth.user_id
new_shout = Shout.create(
2021-08-07 16:14:20 +00:00
author_id = user_id,
body = body
2021-07-27 04:58:06 +00:00
)
2021-08-07 16:14:20 +00:00
branch_name = "shout%s" % (new_shout.id)
cmd = "cd %s; git checkout master && git checkout -b %s && git branch %s-dev" % (SHOUTS_REPO, branch_name, branch_name)
output = subprocess.check_output(cmd, shell=True)
print(output)
shout_filename = "%s/body" % (SHOUTS_REPO)
with open(shout_filename, mode='w', encoding='utf-8') as shout_file:
shout_file.write(body)
cmd = "cd %s; git commit -a -m 'initial version'" % (SHOUTS_REPO)
output = subprocess.check_output(cmd, shell=True)
print(output)
2021-07-27 04:58:06 +00:00
return {
"shout" : new_shout
}
2021-08-07 16:14:20 +00:00
# TODO: paginate, get, update, delete