create shout in db and under git

This commit is contained in:
knst-kotov 2021-08-07 16:14:20 +00:00
parent 93c6f88435
commit 46941749b6
6 changed files with 46 additions and 26 deletions

View File

@ -1,8 +1,9 @@
from orm.rbac import Operation, Permission, Role
from orm.user import User
from orm.message import Message
from orm.shout import Shout
from orm.base import Base, engine
__all__ = ["User", "Role", "Operation", "Permission", "Message"]
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout"]
Base.metadata.create_all(engine)

View File

@ -1,6 +1,6 @@
from typing import List
from datetime import datetime
from sqlalchemy import Column, Integer, String, ForeignKey, Datetime
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from orm import Permission
from orm.base import Base
@ -11,7 +11,7 @@ class Shout(Base):
author_id: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
body: str = Column(String, nullable=False, comment="Body")
createdAt: str = Column(datetime, nullable=False, comment="Created at")
updatedAt: str = Column(datetime, nullable=False, comment="Updated at")
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
# TODO: add all the fields

View File

@ -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"
]

View File

@ -1,36 +1,51 @@
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
}

View File

@ -45,9 +45,9 @@ type Mutation {
registerUser(email: String!, password: String!): SignInResult!
# shout
createShout: ShoutResult!
createShout(body: String!): ShoutResult!
deleteShout(shoutId: Int!): Result!
rateShout(value: Int!): Result!
rateShout(shoutId: Int!, value: Int!): Result!
# profile
# rateUser(value: Int!): ResultPayload!
@ -77,8 +77,8 @@ type Query {
# shoutsByTime(time: DateTime): [Shout]!
# getOnlineUsers: [User!]!
# topAuthors: [User]!
# topShouts: [Shout]!
topAuthors: [User]!
topShouts: [Shout]!
}
############################################ Subscription

View File

@ -17,3 +17,5 @@ for provider in OAUTH_PROVIDERS:
"id" : environ.get(provider + "_OAUTH_ID"),
"key" : environ.get(provider + "_OAUTH_KEY")
}
SHOUTS_REPO = "content"