diff --git a/orm/__init__.py b/orm/__init__.py index 0a22acb3..09586bf8 100644 --- a/orm/__init__.py +++ b/orm/__init__.py @@ -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) diff --git a/orm/shout.py b/orm/shout.py index fe6ca3fe..d8d9aae9 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -1,17 +1,17 @@ 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 class Shout(Base): - __tablename__ = 'shout' + __tablename__ = 'shout' - 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") + 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, default = datetime.now, comment="Created at") + updatedAt: str = Column(DateTime, nullable=True, comment="Updated at") - # TODO: add all the fields \ No newline at end of file + # TODO: add all the fields diff --git a/resolvers/__init__.py b/resolvers/__init__.py index d71c26dd..c3d304fc 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -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" ] diff --git a/resolvers/zine.py b/resolvers/zine.py index 5c669443..f03597a4 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -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 \ No newline at end of file +# TODO: paginate, get, update, delete diff --git a/schema.graphql b/schema.graphql index 91682309..1bf3f8cd 100644 --- a/schema.graphql +++ b/schema.graphql @@ -45,9 +45,9 @@ type Mutation { registerUser(email: String!, password: String!): SignInResult! # shout - createShout: ShoutResult! - deleteShout(shoutId: Int!): Result! - rateShout(value: Int!): Result! + createShout(body: String!): ShoutResult! + deleteShout(shoutId: 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 diff --git a/settings.py b/settings.py index bd7b2277..191c2361 100644 --- a/settings.py +++ b/settings.py @@ -17,3 +17,5 @@ for provider in OAUTH_PROVIDERS: "id" : environ.get(provider + "_OAUTH_ID"), "key" : environ.get(provider + "_OAUTH_KEY") } + +SHOUTS_REPO = "content"