From 0f6e5057064f8e6ac6e4964c70dfd8d6bd4fd37f Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Tue, 28 Jun 2022 22:40:44 +0300 Subject: [PATCH] community model and resolver fixes --- resolvers/community.py | 27 ++++++++++++++------------- schema.graphql | 11 +++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/resolvers/community.py b/resolvers/community.py index f3ce65b1..335dea9e 100644 --- a/resolvers/community.py +++ b/resolvers/community.py @@ -9,46 +9,47 @@ from sqlalchemy import and_ @mutation.field("createCommunity") @login_required -async def create_community(_, info, title, desc): +async def create_community(_, info, input): auth = info.context["request"].auth user_id = auth.user_id community = Community.create( - title = title, - desc = desc + slug = input.get('slug', ''), + title = input.get('title', ''), + desc = input.get('desc', ''), + pic = input.get('pic', '') ) return {"community": community} @mutation.field("updateCommunity") @login_required -async def update_community(_, info, id, title, desc, pic): +async def update_community(_, info, input): auth = info.context["request"].auth user_id = auth.user_id with local_session() as session: - community = session.query(Community).filter(Community.id == id).first() + community = session.query(Community).filter(Community.slug == inpit.get('slug', '')).first() if not community: return {"error": "invalid community id"} - if community.owner != user_id: + if community.createdBy != user_id: return {"error": "access denied"} - community.title = title - community.desc = desc - community.pic = pic + community.title = input.get('title', '') + community.desc = input.get('desc', '') + community.pic = input.get('pic', '') community.updatedAt = datetime.now() - session.commit() @mutation.field("deleteCommunity") @login_required -async def delete_community(_, info, id): +async def delete_community(_, info, slug): auth = info.context["request"].auth user_id = auth.user_id with local_session() as session: - community = session.query(Community).filter(Community.id == id).first() + community = session.query(Community).filter(Community.slug == slug).first() if not community: - return {"error": "invalid community id"} + return {"error": "invalid community slug"} if community.owner != user_id: return {"error": "access denied"} community.deletedAt = datetime.now() diff --git a/schema.graphql b/schema.graphql index a5b77615..4c386da7 100644 --- a/schema.graphql +++ b/schema.graphql @@ -29,7 +29,7 @@ type UserResult { input ShoutInput { slug: String! body: String! - community: Int! + community: String! mainTopic: String topic_slugs: [String] title: String @@ -133,9 +133,9 @@ type Mutation { rateComment(id: Int!, value: Int!): Result! # community - createCommunity(title: String!, desc: String!): Community! + createCommunity(community: CommunityInput!): Community! updateCommunity(community: CommunityInput!): Community! - deleteCommunity(id: Int!): Result! + deleteCommunity(slug: String!): Result! # collab inviteAuthor(author: String!, shout: String!): Result! @@ -239,7 +239,7 @@ type Permission { type Role { id: Int! name: String! - community: Int! + community: String! desc: String permissions: [Permission!]! } @@ -318,7 +318,7 @@ type Shout { authors: [User!]! ratings: [Rating] visibleFor: [User] - community: Int + community: String cover: String layout: String # replyTo: Shout @@ -334,7 +334,6 @@ type Shout { deletedBy: Int publishedBy: Int # if there is no published field - it is not published publishedAt: DateTime - stat: ShoutStat }