Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Process Story Service #315

Merged
merged 3 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
.vscode
package-lock.json
package.json
*.docx
19 changes: 19 additions & 0 deletions backend/python/app/graphql/mutations/story_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,22 @@ def mutate(root, info, story_details, story_file):
except Exception as e:
error_message = getattr(e, "message", None)
raise Exception(error_message if error_message else str(e))


class ProcessStory(graphene.Mutation):
class Arguments:
story_file = Upload(required=True)

story_contents = graphene.Field(lambda: graphene.List(graphene.String))

def mutate(root, info, story_file):
try:
if not services["file"].validate_file(story_file.filename, "docx"):
raise Exception("File must be .docx")
resp = services["file"].create_file(story_file)
new_story_contents = services["story"].process_story(resp["path"])
services["file"].delete_file(resp["path"])
return ProcessStory(story_contents=new_story_contents)
except Exception as e:
error_message = getattr(e, "message", None)
raise Exception(error_message if error_message else str(e))
2 changes: 2 additions & 0 deletions backend/python/app/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CreateStoryTranslationTest,
FinishGradingStoryTranslation,
ImportStory,
ProcessStory,
RemoveReviewerFromStoryTranslation,
RemoveUserFromStoryTranslation,
SoftDeleteStory,
Expand Down Expand Up @@ -94,6 +95,7 @@ class Mutation(graphene.ObjectType):
finish_grading_story_translation = FinishGradingStoryTranslation.Field()
soft_delete_story = SoftDeleteStory.Field()
import_story = ImportStory.Field()
process_story = ProcessStory.Field()


class Query(graphene.ObjectType):
Expand Down
4 changes: 2 additions & 2 deletions backend/python/app/services/implementations/story_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create_story(self, story, content):

def import_story(self, details, file):
try:
story_contents = self._read_doc(file["path"])
story_contents = self.process_story(file["path"])
return self.create_story(details, story_contents)

except Exception as error:
Expand Down Expand Up @@ -1083,7 +1083,7 @@ def _update_story_translation_last_activity(self, story_translation, is_translat
self.logger.error(error)
raise error

def _read_doc(self, file):
def process_story(self, file):
try:
doc = docx.Document(file)
story_contents = []
Expand Down
15 changes: 15 additions & 0 deletions backend/python/app/services/interfaces/story_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,18 @@ def get_languages(self):
Get a list of languages currently used in the platform
"""
pass

@abstractmethod
def import_story(self, details, file):
"""
Import story from word doc and save as Story & StoryContents in db
:param detail: details of story
:param file: file information
"""

@abstractmethod
def process_story(self, story_file):
"""
Process story from word doc for preview
:param story_file: file information
"""
1 change: 1 addition & 0 deletions frontend/src/APIClients/mutations/StoryMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,5 @@ export const SOFT_DELETE_STORY = gql`
}
andrewyguo marked this conversation as resolved.
Show resolved Hide resolved
}
`;

andrewyguo marked this conversation as resolved.
Show resolved Hide resolved
export type SoftDeleteStoryResponse = { ok: boolean };