From 9b0ee9d9d55cab90bd03e1f86971e42c1bca4b1a Mon Sep 17 00:00:00 2001 From: Hieu Nv Date: Tue, 20 Aug 2019 10:54:03 +0700 Subject: [PATCH 1/2] add files to module --- Model/Answers/CreateAnswer.php | 82 ++++++++++++ Model/Answers/FilterArgument.php | 59 +++++++++ Model/Questions/CreateQuestion.php | 82 ++++++++++++ Model/Questions/FilterArgument.php | 59 +++++++++ Model/Resolver/Answer.php | 93 +++++++++++++ Model/Resolver/Answers.php | 79 +++++++++++ Model/Resolver/DataProvider/Answer.php | 81 ++++++++++++ Model/Resolver/DataProvider/Question.php | 82 ++++++++++++ Model/Resolver/Question.php | 93 +++++++++++++ Model/Resolver/Questions.php | 79 +++++++++++ Model/Resolver/SubmitAnswer.php | 159 +++++++++++++++++++++++ Model/Resolver/SubmitQuestion.php | 157 ++++++++++++++++++++++ composer.json | 26 ++++ etc/di.xml | 33 +++++ etc/module.xml | 30 +++++ etc/schema.graphqls | 114 ++++++++++++++++ registration.php | 30 +++++ 17 files changed, 1338 insertions(+) create mode 100644 Model/Answers/CreateAnswer.php create mode 100644 Model/Answers/FilterArgument.php create mode 100644 Model/Questions/CreateQuestion.php create mode 100644 Model/Questions/FilterArgument.php create mode 100644 Model/Resolver/Answer.php create mode 100755 Model/Resolver/Answers.php create mode 100644 Model/Resolver/DataProvider/Answer.php create mode 100755 Model/Resolver/DataProvider/Question.php create mode 100644 Model/Resolver/Question.php create mode 100755 Model/Resolver/Questions.php create mode 100644 Model/Resolver/SubmitAnswer.php create mode 100644 Model/Resolver/SubmitQuestion.php create mode 100755 composer.json create mode 100644 etc/di.xml create mode 100644 etc/module.xml create mode 100644 etc/schema.graphqls create mode 100755 registration.php diff --git a/Model/Answers/CreateAnswer.php b/Model/Answers/CreateAnswer.php new file mode 100644 index 0000000..591c3b6 --- /dev/null +++ b/Model/Answers/CreateAnswer.php @@ -0,0 +1,82 @@ +dataObjectHelper = $dataObjectHelper; + $this->answerRepository = $answerRepository; + $this->answerFactory = $answerFactory; + } + + /** + * @param array $args + * @return AnswerInterface + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function execute(array $args): AnswerInterface + { + $answerDataObject = $this->answerFactory->create(); + $this->dataObjectHelper->populateWithArray( + $answerDataObject, + $args, + AnswerInterface::class + ); + + return $this->answerRepository->save($answerDataObject); + } +} diff --git a/Model/Answers/FilterArgument.php b/Model/Answers/FilterArgument.php new file mode 100644 index 0000000..cccb788 --- /dev/null +++ b/Model/Answers/FilterArgument.php @@ -0,0 +1,59 @@ +config = $config; + } + /** + * Get the attributes for an entity + * + * @return array + */ + public function getEntityAttributes(): array + { + $fields = []; + /** @var \Magento\Framework\GraphQl\Config\Element\Field $field */ + $questionFields = $this->config->getConfigElement('AnswerInterFace')->getFields(); + foreach ($questionFields as $field) { + $fields[$field->getName()] = 'String'; + } + return array_keys($fields); + } +} diff --git a/Model/Questions/CreateQuestion.php b/Model/Questions/CreateQuestion.php new file mode 100644 index 0000000..19cc66b --- /dev/null +++ b/Model/Questions/CreateQuestion.php @@ -0,0 +1,82 @@ +dataObjectHelper = $dataObjectHelper; + $this->questionRepository = $questionRepository; + $this->questionFactory = $questionFactory; + } + + /** + * @param array $args + * @return QuestionInterface + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function execute(array $args): QuestionInterface + { + $questionDataObject = $this->questionFactory->create(); + $this->dataObjectHelper->populateWithArray( + $questionDataObject, + $args, + QuestionInterface::class + ); + + return $this->questionRepository->save($questionDataObject); + } +} diff --git a/Model/Questions/FilterArgument.php b/Model/Questions/FilterArgument.php new file mode 100644 index 0000000..2cdf2b9 --- /dev/null +++ b/Model/Questions/FilterArgument.php @@ -0,0 +1,59 @@ +config = $config; + } + /** + * Get the attributes for an entity + * + * @return array + */ + public function getEntityAttributes(): array + { + $fields = []; + /** @var \Magento\Framework\GraphQl\Config\Element\Field $field */ + $questionFields = $this->config->getConfigElement('QuestionInterFace')->getFields(); + foreach ($questionFields as $field) { + $fields[$field->getName()] = 'String'; + } + return array_keys($fields); + } +} diff --git a/Model/Resolver/Answer.php b/Model/Resolver/Answer.php new file mode 100644 index 0000000..e931721 --- /dev/null +++ b/Model/Resolver/Answer.php @@ -0,0 +1,93 @@ +answerDataProvider = $answerDataProvider; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + $answerId = $this->getAnswerId($args); + $answerData = $this->getAnswerData($answerId); + + return $answerData; + } + + /** + * @param array $args + * @return int + * @throws GraphQlInputException + */ + private function getAnswerId(array $args): int + { + if (!isset($args['id'])) { + throw new GraphQlInputException(__('"Answer id should be specified')); + } + + return (int)$args['id']; + } + + /** + * @param int $answerId + * @return array + * @throws GraphQlNoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + private function getAnswerData(int $answerId): array + { + try { + $answerData = $this->answerDataProvider->getData($answerId); + } catch (NoSuchEntityException $e) { + throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + } + return $answerData; + } +} diff --git a/Model/Resolver/Answers.php b/Model/Resolver/Answers.php new file mode 100755 index 0000000..624058d --- /dev/null +++ b/Model/Resolver/Answers.php @@ -0,0 +1,79 @@ +searchCriteriaBuilder = $searchCriteriaBuilder; + $this->answerRepository = $answerRepository; + } + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + $searchCriteria = $this->searchCriteriaBuilder->build('di_build_answer_build_filter', $args); + $searchCriteria->setCurrentPage($args['currentPage']); + $searchCriteria->setPageSize($args['pageSize']); + + $searchResult = $this->answerRepository->getList($searchCriteria); + return [ + 'total_count' => $searchResult->getTotalCount(), + 'items' => $searchResult->getItems() + ]; + } +} diff --git a/Model/Resolver/DataProvider/Answer.php b/Model/Resolver/DataProvider/Answer.php new file mode 100644 index 0000000..7213f81 --- /dev/null +++ b/Model/Resolver/DataProvider/Answer.php @@ -0,0 +1,81 @@ +answerRepository = $answerRepository; + } + + /** + * @param int $answerId + * @return array + * @throws NoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function getData(int $answerId): array + { + $answer = $this->answerRepository->getById($answerId); + + if (false === $answer->getAnswerStatusId()) { + throw new NoSuchEntityException(); + } + + $answerData = [ + AnswerInterface::ANSWER_ID => $answer->getId(), + AnswerInterface::ANSWER_DETAIL => $answer->getAnswerDetail(), + AnswerInterface::ANSWER_AUTHOR_NAME => $answer->getAnswerAuthorName(), + AnswerInterface::ANSWER_AUTHOR_EMAIL => $answer->getAnswerAuthorEmail(), + AnswerInterface::QUESTION_ID => $answer->getQuestionId(), + AnswerInterface::ANSWER_STATUS_ID => $answer->getAnswerStatusId(), + AnswerInterface::ANSWER_USER_TYPE_ID => $answer->getAnswerUserTypeId(), + AnswerInterface::ANSWER_USER_ID => $answer->getAnswerUserId(), + AnswerInterface::ANSWER_CREATED_BY => $answer->getAnswerCreatedBy(), + AnswerInterface::ANSWER_VISIBILITY_ID => $answer->getAnswerVisibilityId(), + AnswerInterface::ANSWER_LIKES => $answer->getAnswerLikes(), + AnswerInterface::ANSWER_DISLIKES => $answer->getAnswerDislikes(), + AnswerInterface::ANSWER_CREATED_AT => $answer->getAnswerCreatedAt() + ]; + return $answerData; + } +} diff --git a/Model/Resolver/DataProvider/Question.php b/Model/Resolver/DataProvider/Question.php new file mode 100755 index 0000000..82d42ac --- /dev/null +++ b/Model/Resolver/DataProvider/Question.php @@ -0,0 +1,82 @@ +questionRepository = $questionRepository; + } + + /** + * @param int $questionId + * @return array + * @throws NoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function getData(int $questionId): array + { + $question = $this->questionRepository->getById($questionId); + + if (false === $question->getQuestionStatusId()) { + throw new NoSuchEntityException(); + } + + $questionData = [ + QuestionInterface::QUESTION_ID => $question->getId(), + QuestionInterface::QUESTION_DETAIL => $question->getQuestionDetail(), + QuestionInterface::QUESTION_AUTHOR_NAME => $question->getQuestionAuthorName(), + QuestionInterface::QUESTION_AUTHOR_EMAIL => $question->getQuestionAuthorEmail(), + QuestionInterface::QUESTION_STATUS_ID => $question->getQuestionStatusId(), + QuestionInterface::QUESTION_USER_TYPE_ID => $question->getQuestionUserTypeId(), + QuestionInterface::CUSTOMER_ID => $question->getCustomerId(), + QuestionInterface::QUESTION_VISIBILITY_ID => $question->getQuestionVisibilityId(), + QuestionInterface::QUESTION_STORE_ID => $question->getQuestionStoreId(), + QuestionInterface::QUESTION_LIKES => $question->getQuestionLikes(), + QuestionInterface::QUESTION_DISLIKES => $question->getQuestionDislikes(), + QuestionInterface::TOTAL_ANSWERS => $question->getTotalAnswers(), + QuestionInterface::PENDING_ANSWERS => $question->getPendingAnswers(), + QuestionInterface::PRODUCT_ID => $question->getProductId(), + QuestionInterface::QUESTION_CREATED_BY => $question->getQuestionCreatedBy(), + QuestionInterface::QUESTION_CREATED_AT => $question->getQuestionCreatedAt() + ]; + return $questionData; + } +} diff --git a/Model/Resolver/Question.php b/Model/Resolver/Question.php new file mode 100644 index 0000000..ad5ce72 --- /dev/null +++ b/Model/Resolver/Question.php @@ -0,0 +1,93 @@ +questionDataProvider = $questionDataProvider; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + $questionId = $this->getQuestionId($args); + $questionData = $this->getQuestionData($questionId); + + return $questionData; + } + + /** + * @param array $args + * @return int + * @throws GraphQlInputException + */ + private function getQuestionId(array $args): int + { + if (!isset($args['id'])) { + throw new GraphQlInputException(__('"Question id should be specified')); + } + + return (int)$args['id']; + } + + /** + * @param int $questionId + * @return array + * @throws GraphQlNoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + private function getQuestionData(int $questionId): array + { + try { + $questionData = $this->questionDataProvider->getData($questionId); + } catch (NoSuchEntityException $e) { + throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + } + return $questionData; + } +} diff --git a/Model/Resolver/Questions.php b/Model/Resolver/Questions.php new file mode 100755 index 0000000..fe6f46a --- /dev/null +++ b/Model/Resolver/Questions.php @@ -0,0 +1,79 @@ +searchCriteriaBuilder = $searchCriteriaBuilder; + $this->questionRepository = $questionRepository; + } + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + $searchCriteria = $this->searchCriteriaBuilder->build('di_build_question_field_filter', $args); + $searchCriteria->setCurrentPage($args['currentPage']); + $searchCriteria->setPageSize($args['pageSize']); + + $searchResult = $this->questionRepository->getList($searchCriteria); + return [ + 'total_count' => $searchResult->getTotalCount(), + 'items' => $searchResult->getItems() + ]; + } +} diff --git a/Model/Resolver/SubmitAnswer.php b/Model/Resolver/SubmitAnswer.php new file mode 100644 index 0000000..11760e3 --- /dev/null +++ b/Model/Resolver/SubmitAnswer.php @@ -0,0 +1,159 @@ +creatAnswer = $creatAnswer; + $this->userType = $userType; + $this->answerDataProvider = $answerDataProvider; + $this->questionRepository = $questionRepository; + } + + /** + * @param Field $field + * @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context + * @param ResolveInfo $info + * @param array|null $value + * @param array|null $args + * @return \Ecomteck\ProductQuestions\Api\Data\AnswerInterface|\Magento\Framework\GraphQl\Query\Resolver\Value|mixed + * @throws GraphQlInputException + * @throws GraphQlNoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + $userCode = $this->userType->getGuestCode(); + + $data = $this->validateQuestionInput($args); + $data['question_id'] = $this->validateQuestion($args['input']['question_id']); + $data['answer_status_id'] = Status::STATUS_PENDING; + $data['answer_visibility_id'] = Visibility::VISIBILITY_NOT_VISIBLE; + $data['answer_created_by'] = $userCode; + $data['answer_user_type_id'] = $userCode; + + $answer = $this->creatAnswer->execute($data); + try { + $answerData = $this->answerDataProvider->getData($answer->getId()); + } catch (NoSuchEntityException $e) { + throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + } + return $answerData; + } + + /** + * @param int $questionId + * @return int + * @throws GraphQlNoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + private function validateQuestion(int $questionId): int + { + try { + $question = $this->questionRepository->getById($questionId); + if (!$question->getId()) { + throw new GraphQlNoSuchEntityException( + __("The question doesn't exist. Verify the question and try again.") + ); + } + } catch (NoSuchEntityException $e) { + throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + } + return $question->getId(); + } + + /** + * @param array $args + * @return array + * @throws GraphQlInputException + */ + private function validateQuestionInput(array $args): array + { + if (empty($args['input']['answer_detail'])) { + throw new GraphQlInputException(__('Please enter the answer.')); + } + if (empty($args['input']['answer_author_name'])) { + throw new GraphQlInputException(__('Please provide your name.')); + } + if (empty($args['input']['answer_author_email'])) { + throw new GraphQlInputException(__('Please provide your email.')); + } + + return [ + 'answer_detail' => $args['input']['answer_detail'], + 'answer_author_name' => $args['input']['answer_author_name'], + 'answer_author_email' => $args['input']['answer_author_email'] + ]; + } +} diff --git a/Model/Resolver/SubmitQuestion.php b/Model/Resolver/SubmitQuestion.php new file mode 100644 index 0000000..ccd1ecd --- /dev/null +++ b/Model/Resolver/SubmitQuestion.php @@ -0,0 +1,157 @@ +productRepository = $productRepository; + $this->creatQuestion = $creatQuestion; + $this->userType = $userType; + $this->questionDataProvider = $questionDataProvider; + } + + /** + * @param Field $field + * @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context + * @param ResolveInfo $info + * @param array|null $value + * @param array|null $args + * @return \Ecomteck\ProductQuestions\Api\Data\QuestionInterface|\Magento\Framework\GraphQl\Query\Resolver\Value|mixed + * @throws GraphQlInputException + * @throws GraphQlNoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + $data = $this->validateQuestionInput($args); + $data['product_id'] = $this->validateProduct($args['input']['product_id']); + $data['question_visibility_id'] = Visibility::VISIBILITY_NOT_VISIBLE; + $data['question_status_id'] = Status::STATUS_PENDING; + $userCode = $this->userType->getGuestCode(); + $data['question_created_by'] = $userCode; + $data['question_user_type_id'] = $userCode; + + $question = $this->creatQuestion->execute($data); + try { + $questionData = $this->questionDataProvider->getData($question->getId()); + } catch (NoSuchEntityException $e) { + throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + } + return $questionData; + } + + /** + * @param int $productId + * @return int + * @throws GraphQlNoSuchEntityException + */ + private function validateProduct(int $productId): int + { + try { + $product = $this->productRepository->getById($productId); + if (!$product->isVisibleInCatalog()) { + throw new GraphQlNoSuchEntityException( + __("The product that was requested doesn't exist. Verify the product and try again.") + ); + } + } catch (NoSuchEntityException $e) { + throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + } + return $product->getId(); + } + + /** + * @param array $args + * @return array + * @throws GraphQlInputException + */ + private function validateQuestionInput(array $args): array + { + if (empty($args['input']['question_detail'])) { + throw new GraphQlInputException(__('Please enter the question.')); + } + if (empty($args['input']['question_author_name'])) { + throw new GraphQlInputException(__('Please provide your name.')); + } + if (empty($args['input']['question_author_email'])) { + throw new GraphQlInputException(__('Please provide your email.')); + } + + return [ + 'question_detail' => $args['input']['question_detail'], + 'question_author_name' => $args['input']['question_author_name'], + 'question_author_email' => $args['input']['question_author_email'] + ]; + } +} diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..d061120 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "ecomteck/module-product-questions-graph-ql", + "description": "N/A", + "type": "magento2-module", + "require": { + "php": "~7.1.3||~7.2.0", + "magento/framework": "102.0.*", + "ecomteck/module-product-questions": "1.0.*" + }, + "suggest": { + "magento/module-graph-ql": "100.3.*" + }, + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Ecomteck\\ProductQuestionsGraphQl\\": "" + } + }, + "version": "1.0.0" +} diff --git a/etc/di.xml b/etc/di.xml new file mode 100644 index 0000000..c6898a3 --- /dev/null +++ b/etc/di.xml @@ -0,0 +1,33 @@ + + + + + + + + Ecomteck\ProductQuestionsGraphQl\Model\Questions\FilterArgument + Ecomteck\ProductQuestionsGraphQl\Model\Answers\FilterArgument + + + + \ No newline at end of file diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 0000000..e46e7e2 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/etc/schema.graphqls b/etc/schema.graphqls new file mode 100644 index 0000000..e3a9fdc --- /dev/null +++ b/etc/schema.graphqls @@ -0,0 +1,114 @@ +# Copyright © Ecomteck (ecomteck@gmail.com). All rights reserved. +# Please visit Ecomteck.com for license details (https://www.ecomteck.com/LICENSE.txt). + +type Query { + productQuestion( + id: Int @doc(description: "Id of the question") + ): QuestionInterFace @resolver(class: "\\Ecomteck\\ProductQuestionsGraphQl\\Model\\Resolver\\Question") @doc(description: "The product question query returns information about a question") + productQuestions( + filter: QuestionFilterInput @doc(description: "Identifies which question attributes to search for and return."), + pageSize: Int = 5 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."), + currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1."), + ):Questions + @resolver(class: "Ecomteck\\ProductQuestionsGraphQl\\Model\\Resolver\\Questions") @doc(description: "The questions query searches for questions that match the criteria specified in the search and filter attributes") + + productQuestionAnswer( + id: Int @doc(description: "Id of the answer") + ): AnswerInterFace @resolver(class: "\\Ecomteck\\ProductQuestionsGraphQl\\Model\\Resolver\\Answer") @doc(description: "The query returns information about a answer") + productQuestionAnswers( + filter: AnswerFilterInput @doc(description: "Identifies which answer attributes to search for and return."), + pageSize: Int = 5 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."), + currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1."), + ):Answers + @resolver(class: "Ecomteck\\ProductQuestionsGraphQl\\Model\\Resolver\\Answers") @doc(description: "The questions query searches for questions that match the criteria specified in the search and filter attributes") +} + +type QuestionInterFace @doc(description: "product question defines all question information") { + question_id: Int @doc(description: "Id of the question") + question_detail: String @doc(description: "Detail of the question") + question_author_name: String @doc(description: "product question author name") + question_author_email: String @doc(description: "product question author email") + question_status_id: Int @doc(description: "question status id") + question_user_type_id: Int @doc(description: "question user type id") + customer_id: Int @doc(description: "customer id") + question_visibility_id: Int @doc(description: "question visibility id") + question_store_id: Int @doc(description: "store id") + question_likes: Int @doc(description: "question likes") + question_dislikes: Int @doc(description: "question dislikes") + total_answers: Int @doc(description: "question total answers") + pending_answers: Int @doc(description: "question pending answers") + product_id: Int @doc(description: "product id") + question_created_by: Int @doc(description: "question created by") + question_created_at: String @doc(description: "question created at") +} + +type AnswerInterFace @doc(description: "the product question defines all answer information") { + answer_id: Int @doc(description: "Id of the answer") + answer_detail: String @doc(description: "Detail of the answer") + answer_author_name: String @doc(description: "answer question author name") + answer_author_email: String @doc(description: "answer question author email") + question_id: Int @doc(description: "question id which answer posts in") + answer_status_id: Int @doc(description: "answer status id") + answer_user_type_id: Int @doc(description: "answer user type id") + answer_user_id: Int @doc(description: "answer user id") + answer_visibility_id: Int @doc(description: "answer visibility id") + answer_likes: Int @doc(description: "answer likes") + answer_dislikes: Int @doc(description: "answer dislikes") + answer_created_by: Int @doc(description: "answer created by") + answer_created_at: String @doc(description: "answer created at") +} + +type Questions @doc(description: "The Questions object is the top-level object returned in a question search") { + total_count: Int @doc(description: "The number of questions returned") + items: [QuestionInterFace] @doc(description: "An array of questions that match the specified search criteria") +} + +type Answers @doc(description: "The Answers object is the top-level object returned in a answer search") { + total_count: Int @doc(description: "The number of answers returned") + items: [AnswerInterFace] @doc(description: "An array of answers that match the specified search criteria") +} + +input QuestionFilterInput @doc(description: "QuestionFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { + question_author_name: FilterTypeInput @doc(description: "The author name who posts the product questions") + question_author_email: FilterTypeInput @doc(description: "author email") + question_status_id: FilterTypeInput @doc(description: "question status id") + customer_id: FilterTypeInput @doc(description: "customer id") + question_visibility_id: FilterTypeInput @doc(description: "question visibility id") + question_store_id: FilterTypeInput @doc(description: "store id") + product_id: FilterTypeInput @doc(description: "product id") + or: QuestionFilterInput @doc(description: "The keyword required to perform a logical OR comparison") +} + +input AnswerFilterInput @doc(description: "AnswerFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { + answer_author_name: FilterTypeInput @doc(description: "The author name who posts the answer for question") + answer_author_email: FilterTypeInput @doc(description: "author email") + answer_status_id: FilterTypeInput @doc(description: "answer status id") + question_id: FilterTypeInput @doc(description: "question id") + answer_visibility_id: FilterTypeInput @doc(description: "answer visibility id") + answer_store_id: FilterTypeInput @doc(description: "store id") + answer_user_id: FilterTypeInput @doc(description: "answer user id") + or: AnswerFilterInput @doc(description: "The keyword required to perform a logical OR comparison") +} + +type Mutation { + submitProductQuestion( + input: SubmitProductQuestionInput + ): QuestionInterFace @resolver(class: "\\Ecomteck\\ProductQuestionsGraphQl\\Model\\Resolver\\SubmitQuestion") @doc(description:"submit a question for the product and return to question interface") + submitProductQuestionAnswer( + input: SubmitProductQuestionAnswerInput + ): AnswerInterFace @resolver(class: "\\Ecomteck\\ProductQuestionsGraphQl\\Model\\Resolver\\SubmitAnswer") @doc(description:"submit a question for the product and return to question interface") +} + +input SubmitProductQuestionInput { + product_id: Int! @doc(description: "the product id which question submited") + question_detail: String! @doc(description: "the detail of question") + question_author_name: String! @doc(description: "question author name") + question_author_email: String! @doc(description: "question author email") +} + +input SubmitProductQuestionAnswerInput { + question_id: Int! @doc(description: "the question id which answer submited") + answer_detail: String! @doc(description: "the detail of answer") + answer_author_name: String! @doc(description: "answer author name") + answer_author_email: String! @doc(description: "answer author email") +} diff --git a/registration.php b/registration.php new file mode 100755 index 0000000..3b52902 --- /dev/null +++ b/registration.php @@ -0,0 +1,30 @@ + Date: Wed, 21 Aug 2019 09:46:24 +0700 Subject: [PATCH 2/2] update submit Question and Answer --- Model/Resolver/SubmitAnswer.php | 12 ++++++------ Model/Resolver/SubmitQuestion.php | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Model/Resolver/SubmitAnswer.php b/Model/Resolver/SubmitAnswer.php index 11760e3..b4a71a2 100644 --- a/Model/Resolver/SubmitAnswer.php +++ b/Model/Resolver/SubmitAnswer.php @@ -14,7 +14,7 @@ * version in the future. * * @category Ecomteck - * @package Ecomteck_ProductQuestionsGraph + * @package Ecomteck_ProductQuestionsGraphQl * @copyright Copyright (c) 2019 Ecomteck (https://ecomteck.com/) * @license https://ecomteck.com/LICENSE.txt */ @@ -43,7 +43,7 @@ class SubmitAnswer implements ResolverInterface /** * @var CreateAnswer */ - private $creatAnswer; + private $createAnswer; /** * User Type Model @@ -64,18 +64,18 @@ class SubmitAnswer implements ResolverInterface /** * SubmitQuestion constructor. - * @param CreateAnswer $creatAnswer + * @param CreateAnswer $createAnswer * @param UserType $userType * @param AnswerDataProvider $answerDataProvider * @param QuestionRepositoryInterface $questionRepository */ public function __construct( - CreateAnswer $creatAnswer, + CreateAnswer $createAnswer, UserType $userType, AnswerDataProvider $answerDataProvider, QuestionRepositoryInterface $questionRepository ) { - $this->creatAnswer = $creatAnswer; + $this->createAnswer = $createAnswer; $this->userType = $userType; $this->answerDataProvider = $answerDataProvider; $this->questionRepository = $questionRepository; @@ -103,7 +103,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $data['answer_created_by'] = $userCode; $data['answer_user_type_id'] = $userCode; - $answer = $this->creatAnswer->execute($data); + $answer = $this->createAnswer->execute($data); try { $answerData = $this->answerDataProvider->getData($answer->getId()); } catch (NoSuchEntityException $e) { diff --git a/Model/Resolver/SubmitQuestion.php b/Model/Resolver/SubmitQuestion.php index ccd1ecd..50eb6dd 100644 --- a/Model/Resolver/SubmitQuestion.php +++ b/Model/Resolver/SubmitQuestion.php @@ -14,7 +14,7 @@ * version in the future. * * @category Ecomteck - * @package Ecomteck_ProductQuestionsGraph + * @package Ecomteck_ProductQuestionsGraphQl * @copyright Copyright (c) 2019 Ecomteck (https://ecomteck.com/) * @license https://ecomteck.com/LICENSE.txt */ @@ -48,7 +48,7 @@ class SubmitQuestion implements ResolverInterface /** * @var CreateQuestion */ - private $creatQuestion; + private $createQuestion; /** * User Type Model @@ -65,18 +65,18 @@ class SubmitQuestion implements ResolverInterface /** * SubmitQuestion constructor. * @param ProductRepositoryInterface $productRepository - * @param CreateQuestion $creatQuestion + * @param CreateQuestion $createQuestion * @param UserType $userType * @param QuestionDataProvider $questionDataProvider */ public function __construct( ProductRepositoryInterface $productRepository, - CreateQuestion $creatQuestion, + CreateQuestion $createQuestion, UserType $userType, QuestionDataProvider $questionDataProvider ) { $this->productRepository = $productRepository; - $this->creatQuestion = $creatQuestion; + $this->createQuestion = $createQuestion; $this->userType = $userType; $this->questionDataProvider = $questionDataProvider; } @@ -102,7 +102,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $data['question_created_by'] = $userCode; $data['question_user_type_id'] = $userCode; - $question = $this->creatQuestion->execute($data); + $question = $this->createQuestion->execute($data); try { $questionData = $this->questionDataProvider->getData($question->getId()); } catch (NoSuchEntityException $e) {