# ForeSee QnA Firestore
The new QnA FireStore scheme will only depend on 1 collection, along with the the existing QNA-QAwerQnerCollection collection.
# Table of Contents
[TOC]
## General Document Structure
Below is the general structure of a document in the collection. Note that there are 2 extra flags/booleans, which indicates the state of the question, i.e. whether it should get shown to the members/eye pros, etc.
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: ""
answerTitle: [""]
answerContent: [""]
createAnswerTime: [""]
createProblemTime: ""
tags: []
isQuesAuth: boolean
isAnsAuth: boolean
}
## Actors
* Members (Questioners)
* Eye Professionals (Answerers)
* Admin (Authorizing questions and answers)
## Use Cases
### Members -> View Answered Questions
**Brief description**: Members view authorized/answered questions.
**Precondition**: Logged in FamilyHomeScreen.js
**Flow**:
1. Members Click on the Q&A button.
2. App navigates to QnASearchScreen.js
* Call to async fetchQuestions(), fetch all documents in collection.
* Filter these documents, fetching only with authorized and answered set to true
* Sample Response
~~~
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: ""
answerTitle: [""]
answerContent: [""]
createAnswerTime: [""]
tags: []
auth: true
answered: true
}
2. A list of answered questions asked by other members are shown
### Members -> Ask Questions
**Brief Description**: Members ask questions to eye professionals.
**Precondition**: Logged in QnASearchScreen.js
**Flow**:
1. Member clicks on Ask a Question Button.
2. App navigates to AskQuestionScreen.js.
3. Member fills in question details, including title, description and tags, and submits the question.
* Call to async addQuestion(), creates a new document in the collection.
* Sample Document after call
~~~
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: ""
answerTitle: [""]
answerContent: [""]
createAnswerTime: [""]
createProblemTime: ""
tags: []
isQuesAuth: false
isAnsAuth: false
}
Note that the auth and answered flags are initialized to false, when a new question is added.
### Eye Professional -> View Authorized question
**Brief description**: Eye Professionals view authorized, unanswered questions
**Precondition**: Logged in ProHome.js
**Flow**:
1. Eye Professional click on QnA Button
2. App navigates to ProQnASearchScreen.js
* Call to fetchQuestions(), fetch all documents in collection.
* Filter these documents, fetching only with authorized set to true and answered set to false
* Sample Response
~~~
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: ""
answerTitle: [""]
answerContent: [""]
createAnswerTime: [""]
createProblemTime: ""
tags: []
isQuesAuth: true
isAnsAuth: false
}
3. A list of unanswered questions are shown.
### Eye Professional -> Answer Questions
**Brief description**: Eye Professionals answer authorized, unanswered questions
**Precondition**: Logged in ProQnASearchScreen.js
**Flow**:
1. Eye Professional clicks on a question
2. Question title and content gets shown
3. Eye Professional enters answer title and content and submits answers.
* Call to async addAnswer(), modifies the existing document
* Answer title and content, createAnswerTime gets appended to their respective fields in document.
* Sample Document after call
~~~
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: APPEND [""]
answerContent: APPEND [""]
createAnswerTime: APPEND [""]
createProblemTime: ""
createProblemTime: ""
tags: []
isQuesAuth: true
isAnsAuth: false
}
### Admin -> View unauthroized questions
**Brief description**: Admin views all unauthroized questions asked by members
**Precondition**: Logged in HomeScreen.js
**Flow**:
1. Click on Authorize Questions button
2. App navigates to AuthQuestScreen.js
* Call to async fetchQuestions(), fetching all documents.
* Filter these documents, fetching only those with authorized set to false.
* Sample Response
~~~
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: [""]
answerContent: [""]
createAnswerTime: [""]
createProblemTime: ""
createProblemTime: ""
tags: []
isQuesAuth: false
isAnsAuth: false
}
3. The list of unauthorized questions gets shown.
### Admin -> Authorize questions
**Brief description**: Admin authroizes questions asked by members
**Precondition**: Logged in AuthQuestScreen.js
**Flow**:
1. Click on a question
2. Shows the question title and question content
3. Click authorize question
* Call to async authQuestion(), modifiying existing document
* Sample Document After call
~~~
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: [""]
answerContent: [""]
createAnswerTime: [""]
createProblemTime: ""
createProblemTime: ""
tags: []
isQuesAuth: set to TRUE
isAnsAuth: false
}
### Admin -> Unauthorize questions
**Brief description**: Admin unauthroizes/deletes questions asked by members
**Precondition**: Logged in AuthQuestScreen.js
**Flow**:
1. Click on a question
2. App navigates to AuthQuestionDetail.js
3. Shows the question title and question content
4. Click unauthorize question
* Call to async unauthQuestion(), deleting existing document
### Admin -> View answers to unanswered questions
**Brief description**: Admin views all answers to unanswered question.
**Precondition**: Logged in HomeScreen.js.
**Flow**:
1. Click on Authorize Answers button
2. App navigates to AuthQuestScreen.js
* Call to async fetchQuestions(), fetching all documents.
* Filter these documents, fetching only those with authorized set to true, but answered to false.
* Sample Response
~~~
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: [""]
answerContent: [""]
createAnswerTime: [""]
createProblemTime: ""
tags: []
isQuesAuth: true
isAnsAuth: false
}
3. The list of unanswered questions gets shown.
### Admin -> Verify answers
**Brief description**: Admin verifies an answer for a particular question
**Precondition**: Logged in AuthQuestScreen.js
**Flow**:
1. Click on an answer
2. App navigates to AuthAnswerDetail.js
3. Shows the question title and question content
4. Click verify answer
* Call to async verifyAnswer(), modifiying existing document
* Sample Document After call
~~~
{
questionId:generated randomly by firebase
questionTitle:""
questionContent:""
answerTitle: [""] with length of 1
answerContent: [""] with length of 1
createAnswerTime: [""] with length of 1
createProblemTime: ""
tags: []
isQuesAuth: true
isAnsAuth: set to TRUE
}
Note that after verifiying an answer, answerTitle, answerContent and createAnswerTime should have length of 1, as there should only be 1 answer to a question, implying that if there are multiple answers to a question, the answer which is authorized will prevail and get shown to members.
## Functions To be Implemented
* fetchQuestions()
* Fetches all documents/questions in collection.
* addQuestion()
* Adds a new document, with answer and auth flags, both set to false.
* addAnswer()
* Appends answer, including answerTitle, answerContent, and createAnswerTime to existing document.
* AuthQuestion()
* Sets the auth question of the document/question to true.
* unauthQuestion(question)
* Deletes the document/question in the collection.
* verifyAnswer()
* Remove all answers to a question except for the verified one, and sets the answered flag to true.