create shout in db and under git
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from resolvers.auth import sign_in, sign_out, register, confirm
|
||||
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
||||
from resolvers.zine import create_shout
|
||||
|
||||
__all__ = [
|
||||
"sign_in",
|
||||
@@ -11,5 +12,6 @@ __all__ = [
|
||||
"create_message",
|
||||
"delete_message",
|
||||
"get_messages",
|
||||
"update_messages"
|
||||
"update_messages",
|
||||
"create_shout"
|
||||
]
|
||||
|
@@ -1,38 +1,53 @@
|
||||
from orm import Shout, User
|
||||
from orm.base import global_session
|
||||
from orm.base import local_session
|
||||
|
||||
from resolvers.base import mutation, query, subscription
|
||||
from resolvers.base import mutation, query
|
||||
|
||||
from auth.authenticate import login_required
|
||||
from settings import SHOUTS_REPO
|
||||
|
||||
import subprocess
|
||||
|
||||
@query.field("topShouts")
|
||||
async def top_shouts(_, info: GraphQLResolveInfo):
|
||||
async def top_shouts(_, info):
|
||||
# TODO: implement top shouts
|
||||
pass
|
||||
|
||||
|
||||
@query.field("topAuthors")
|
||||
async def top_shouts(_, info: GraphQLResolveInfo):
|
||||
async def top_shouts(_, info):
|
||||
# TODO: implement top authors
|
||||
pass
|
||||
|
||||
|
||||
# TODO: debug me
|
||||
@mutation.field("createShout")
|
||||
@login_required
|
||||
async def create_post(_, info, input):
|
||||
async def create_shout(_, info, body):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
|
||||
new_shout = Shout.create(
|
||||
author = user_id,
|
||||
body = input["body"], # TODO: add createShoutInput in scheme.graphql
|
||||
title = input.get("title")
|
||||
# TODO: generate slug
|
||||
author_id = user_id,
|
||||
body = body
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
return {
|
||||
"status": True,
|
||||
"shout" : new_shout
|
||||
}
|
||||
|
||||
|
||||
# TODO: paginate, get, update, delete
|
||||
# TODO: paginate, get, update, delete
|
||||
|
Reference in New Issue
Block a user