create shout in db and under git
This commit is contained in:
parent
93c6f88435
commit
46941749b6
|
@ -1,8 +1,9 @@
|
||||||
from orm.rbac import Operation, Permission, Role
|
from orm.rbac import Operation, Permission, Role
|
||||||
from orm.user import User
|
from orm.user import User
|
||||||
from orm.message import Message
|
from orm.message import Message
|
||||||
|
from orm.shout import Shout
|
||||||
from orm.base import Base, engine
|
from orm.base import Base, engine
|
||||||
|
|
||||||
__all__ = ["User", "Role", "Operation", "Permission", "Message"]
|
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout"]
|
||||||
|
|
||||||
Base.metadata.create_all(engine)
|
Base.metadata.create_all(engine)
|
||||||
|
|
14
orm/shout.py
14
orm/shout.py
|
@ -1,17 +1,17 @@
|
||||||
from typing import List
|
from typing import List
|
||||||
from datetime import datetime
|
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 import Permission
|
||||||
from orm.base import Base
|
from orm.base import Base
|
||||||
|
|
||||||
|
|
||||||
class Shout(Base):
|
class Shout(Base):
|
||||||
__tablename__ = 'shout'
|
__tablename__ = 'shout'
|
||||||
|
|
||||||
author_id: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
|
author_id: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
|
||||||
body: str = Column(String, nullable=False, comment="Body")
|
body: str = Column(String, nullable=False, comment="Body")
|
||||||
createdAt: str = Column(datetime, nullable=False, comment="Created at")
|
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||||
updatedAt: str = Column(datetime, nullable=False, comment="Updated at")
|
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
|
||||||
|
|
||||||
# TODO: add all the fields
|
# TODO: add all the fields
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from resolvers.auth import sign_in, sign_out, register, confirm
|
from resolvers.auth import sign_in, sign_out, register, confirm
|
||||||
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
||||||
|
from resolvers.zine import create_shout
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"sign_in",
|
"sign_in",
|
||||||
|
@ -11,5 +12,6 @@ __all__ = [
|
||||||
"create_message",
|
"create_message",
|
||||||
"delete_message",
|
"delete_message",
|
||||||
"get_messages",
|
"get_messages",
|
||||||
"update_messages"
|
"update_messages",
|
||||||
|
"create_shout"
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,36 +1,51 @@
|
||||||
from orm import Shout, User
|
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")
|
@query.field("topShouts")
|
||||||
async def top_shouts(_, info: GraphQLResolveInfo):
|
async def top_shouts(_, info):
|
||||||
# TODO: implement top shouts
|
# TODO: implement top shouts
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@query.field("topAuthors")
|
@query.field("topAuthors")
|
||||||
async def top_shouts(_, info: GraphQLResolveInfo):
|
async def top_shouts(_, info):
|
||||||
# TODO: implement top authors
|
# TODO: implement top authors
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# TODO: debug me
|
|
||||||
@mutation.field("createShout")
|
@mutation.field("createShout")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_post(_, info, input):
|
async def create_shout(_, info, body):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
new_shout = Shout.create(
|
new_shout = Shout.create(
|
||||||
author = user_id,
|
author_id = user_id,
|
||||||
body = input["body"], # TODO: add createShoutInput in scheme.graphql
|
body = body
|
||||||
title = input.get("title")
|
|
||||||
# TODO: generate slug
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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 {
|
return {
|
||||||
"status": True,
|
|
||||||
"shout" : new_shout
|
"shout" : new_shout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,9 @@ type Mutation {
|
||||||
registerUser(email: String!, password: String!): SignInResult!
|
registerUser(email: String!, password: String!): SignInResult!
|
||||||
|
|
||||||
# shout
|
# shout
|
||||||
createShout: ShoutResult!
|
createShout(body: String!): ShoutResult!
|
||||||
deleteShout(shoutId: Int!): Result!
|
deleteShout(shoutId: Int!): Result!
|
||||||
rateShout(value: Int!): Result!
|
rateShout(shoutId: Int!, value: Int!): Result!
|
||||||
|
|
||||||
# profile
|
# profile
|
||||||
# rateUser(value: Int!): ResultPayload!
|
# rateUser(value: Int!): ResultPayload!
|
||||||
|
@ -77,8 +77,8 @@ type Query {
|
||||||
# shoutsByTime(time: DateTime): [Shout]!
|
# shoutsByTime(time: DateTime): [Shout]!
|
||||||
|
|
||||||
# getOnlineUsers: [User!]!
|
# getOnlineUsers: [User!]!
|
||||||
# topAuthors: [User]!
|
topAuthors: [User]!
|
||||||
# topShouts: [Shout]!
|
topShouts: [Shout]!
|
||||||
}
|
}
|
||||||
|
|
||||||
############################################ Subscription
|
############################################ Subscription
|
||||||
|
|
|
@ -17,3 +17,5 @@ for provider in OAUTH_PROVIDERS:
|
||||||
"id" : environ.get(provider + "_OAUTH_ID"),
|
"id" : environ.get(provider + "_OAUTH_ID"),
|
||||||
"key" : environ.get(provider + "_OAUTH_KEY")
|
"key" : environ.get(provider + "_OAUTH_KEY")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHOUTS_REPO = "content"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user