Documentation ¶
Index ¶
- Constants
- Variables
- func Count(context interface{}, db *db.DB, formID string) (int, error)
- func Create(context interface{}, db *db.DB, formID string, submission *Submission) error
- func Delete(context interface{}, db *db.DB, id string) error
- func EnsureIndexes(context interface{}, db *db.DB) error
- type Answer
- type AnswerInput
- type SearchOpts
- type SearchResultCounts
- type SearchResults
- type Submission
- func AddFlag(context interface{}, db *db.DB, id, flag string) (*Submission, error)
- func RemoveFlag(context interface{}, db *db.DB, id, flag string) (*Submission, error)
- func Retrieve(context interface{}, db *db.DB, id string) (*Submission, error)
- func RetrieveMany(context interface{}, db *db.DB, ids []string) ([]Submission, error)
- func UpdateAnswer(context interface{}, db *db.DB, id string, answer AnswerInput) (*Submission, error)
- func UpdateStatus(context interface{}, db *db.DB, id, status string) (*Submission, error)
Constants ¶
const Collection = "form_submissions"
Collection is the mongo collection where Submission documents are saved.
Variables ¶
var ErrInvalidID = errors.New("ID is not in it's proper form")
ErrInvalidID occurs when an ID is not in a valid form.
Functions ¶
func Count ¶
Count returns the count of current submissions for a given form id in the Form Submissions MongoDB database collection.
func Create ¶
func Create(context interface{}, db *db.DB, formID string, submission *Submission) error
Create adds a new Submission based on a given Form into the MongoDB database collection.
func EnsureIndexes ¶
EnsureIndexes perform index create commands against Mongo for the indexes needed for the ask package to run.
Types ¶
type Answer ¶
type Answer struct { WidgetID string `json:"widget_id" bson:"widget_id" validate:"required,len=24"` Identity bool `json:"identity" bson:"identity"` Answer interface{} `json:"answer" bson:"answer"` EditedAnswer interface{} `json:"edited" bson:"edited"` Question string `json:"question" bson:"question"` Props interface{} `json:"props" bson:"props"` }
Answer describes an answer submitted for a specific Form widget with the specific question asked included as well.
type AnswerInput ¶
type AnswerInput struct { WidgetID string `json:"widget_id" validate:"required"` Answer interface{} `json:"answer" validate:"exists"` }
AnswerInput describes the input accepted for a new submission answer.
func (*AnswerInput) Validate ¶
func (f *AnswerInput) Validate() error
Validate checks the AnswerInput value for consistency.
type SearchOpts ¶
SearchOpts is the options used to perform a search accross a given forms submissions.
type SearchResultCounts ¶
type SearchResultCounts struct { SearchByFlag map[string]int `json:"search_by_flag"` TotalSearch int `json:"total_search"` TotalSubmissions int `json:"total_submissions"` }
SearchResultCounts is a structured type containing the counts of results.
type SearchResults ¶
type SearchResults struct { Counts SearchResultCounts `json:"counts"` Submissions []Submission `json:"submissions"` CSVURL string `json:"csv_url"` }
SearchResults is a structured type returning the results expected from searching for submissions based on a form id.
func Search ¶
func Search(context interface{}, db *db.DB, formID string, limit, skip int, opts SearchOpts) (*SearchResults, error)
Search searches through form submissions for a given form using the provided search options.
type Submission ¶
type Submission struct { ID bson.ObjectId `json:"id" bson:"_id"` FormID bson.ObjectId `json:"form_id" bson:"form_id"` Number int `json:"number" bson:"number"` Status string `json:"status" bson:"status"` Answers []Answer `json:"replies" bson:"replies"` Flags []string `json:"flags" bson:"flags"` // simple, flexible string flagging Header interface{} `json:"header" bson:"header"` FinishedScreen interface{} `json:"finishedScreen" bson:"finishedScreen"` CreatedBy interface{} `json:"created_by" bson:"created_by"` // Todo, decide how to represent ownership here UpdatedBy interface{} `json:"updated_by" bson:"updated_by"` // Todo, decide how to represent ownership here DateCreated time.Time `json:"date_created,omitempty" bson:"date_created,omitempty"` DateUpdated time.Time `json:"date_updated,omitempty" bson:"date_updated,omitempty"` }
Submission contains all the answers submitted for a specific Form as well as any other details about the Form that were present at the time of the Form submission.
func AddFlag ¶
func AddFlag(context interface{}, db *db.DB, id, flag string) (*Submission, error)
AddFlag adds, and de-duplicates a flag to a given Submission in the MongoDB database collection.
func RemoveFlag ¶
func RemoveFlag(context interface{}, db *db.DB, id, flag string) (*Submission, error)
RemoveFlag removes a flag from a given Submission in the MongoDB database collection.
func Retrieve ¶
func Retrieve(context interface{}, db *db.DB, id string) (*Submission, error)
Retrieve retrieves a Submission from the MongoDB database collection.
func RetrieveMany ¶
func RetrieveMany(context interface{}, db *db.DB, ids []string) ([]Submission, error)
RetrieveMany retrieves a list of Submission's from the MongoDB database collection.
func UpdateAnswer ¶
func UpdateAnswer(context interface{}, db *db.DB, id string, answer AnswerInput) (*Submission, error)
UpdateAnswer updates the edited answer if it could find it inside the MongoDB database collection atomically.
func UpdateStatus ¶
func UpdateStatus(context interface{}, db *db.DB, id, status string) (*Submission, error)
UpdateStatus updates a form submissions status inside the MongoDB database collection.
func (*Submission) Validate ¶
func (s *Submission) Validate() error
Validate checks the Submission value for consistency.