Documentation ¶
Index ¶
- Variables
- func TranslateValidationErrors(err error) []error
- type Answers
- type InvalidAnswerError
- type Survey
- func (s *Survey) AddGroup(g *question.Group) error
- func (s *Survey) AddGroupBytes(g []byte) error
- func (s *Survey) AddGroupJson(g string) error
- func (s *Survey) AddGroupMap(g map[string]any) error
- func (s *Survey) AddOrUpdateQuestion(q *question.Question) error
- func (s *Survey) AddOrUpdateQuestionBytes(qb []byte) error
- func (s *Survey) AddOrUpdateQuestionJson(qs string) error
- func (s *Survey) AddOrUpdateQuestionMap(qm map[string]any) error
- func (s *Survey) AddQuestion(q *question.Question) error
- func (s *Survey) AddQuestionBytes(qb []byte) error
- func (s *Survey) AddQuestionJson(qs string) error
- func (s *Survey) AddQuestionMap(qm map[string]any) error
- func (s *Survey) AddQuestionToGroup(questionNameId, groupNameId string, position int) error
- func (s *Survey) GetQuestionsAssignments() map[string]string
- func (s *Survey) RemoveGroup(groupNameId string) error
- func (s *Survey) RemoveQuestion(questionNameId string) error
- func (s *Survey) RemoveQuestionFromGroup(questionNameId, groupNameId string) error
- func (s *Survey) ReviewAnswers(ans Answers) (*SurveyResume, error)
- func (s *Survey) ToJson() (string, error)
- func (s *Survey) ToMap() (map[string]any, error)
- func (s *Survey) UpdateGroupBytes(ug []byte) error
- func (s *Survey) UpdateGroupJson(ug string) error
- func (s *Survey) UpdateGroupMap(ug map[string]any) error
- func (s *Survey) UpdateGroupQuestions(groupNameId string, questionsIds []string) error
- func (s *Survey) UpdateGroupsOrder(order []string) error
- func (s *Survey) UpdateQuestion(uq *question.Question) error
- func (s *Survey) UpdateQuestionBytes(uq []byte) error
- func (s *Survey) UpdateQuestionJson(uq string) error
- func (s *Survey) UpdateQuestionMap(uq map[string]any) error
- func (s *Survey) ValidateSurvey() error
- type SurveyResume
- type TotalsResume
Constants ¶
This section is empty.
Variables ¶
var SurveyValidator = newSurveyValidator(validatorTranslator)
Functions ¶
Types ¶
type Answers ¶
Answers is a map with the answers provided by the user. The key is the question NameId (Question.NameId).
type InvalidAnswerError ¶
type Survey ¶
type Survey struct { // Title is the title of the survey. // Validations: // - required // - min length: 1 Title string `json:"title,omitempty" bson:"title,omitempty" validate:"required,min=1"` // Version is the version of the survey. // Validations: // - required // - min length: 1 Version string `json:"version,omitempty" bson:"version,omitempty" validate:"required,min=1"` // Description is the description of the survey. // Validations: // - optional // - min length: 1 Description *string `json:"description,omitempty" bson:"description,omitempty" validate:"omitempty"` // Questions is a map with all the questions in the survey. // The key is the question NameId (Question.NameId). // Validations: // - required // - min length: 1 // - each question must be valid Questions map[string]*question.Question `json:"questions,omitempty" bson:"questions,omitempty" validate:"required,dive"` // Groups is a map with all the groups in the survey. // The key is the group NameId (Group.NameId). // Validations: // - required // - min length: 1 // - each group must be valid Groups map[string]*question.Group `json:"groups,omitempty" bson:"groups,omitempty" validate:"required,dive"` // GroupsOrder is a list of group name ids that defines the order of the groups in the survey. // Validations: // - required // - min length: 1 GroupsOrder []string `json:"groupsOrder,omitempty" bson:"groupsOrder,omitempty" validate:"required"` }
Survey is a struct representation of a survey.
func NewSurvey ¶
NewSurvey creates a new Survey instance with the given title, version, and description. Args:
- nameId: the name id of the survey (required)
- title: the title of the survey (required)
- version: the version of the survey (required)
- description: the description of the survey (optional)
Returns:
- *Survey: the new survey instance
- error: if an error occurred
func ParseFromBytes ¶
ParseFromBytes converts the given json byte slice into a Survey instance.
func ParseFromJsonStr ¶
ParseFromJsonStr converts the given json string into a Survey instance.
func (*Survey) AddGroup ¶
AddGroup adds a group to the survey. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) AddGroupBytes ¶
AddGroupBytes adds a group to the survey given its representation as a byte array It also validates the group and checks if the group is consistent with the survey.
func (*Survey) AddGroupJson ¶
AddGroupJson adds a group to the survey given its representation as a JSON string It also validates the group and checks if the group is consistent with the survey.
func (*Survey) AddGroupMap ¶
AddGroupMap adds a group to the survey given its representation as a map[string]any It also validates the group and checks if the group is consistent with the survey.
func (*Survey) AddOrUpdateQuestion ¶
AddOrUpdateQuestion adds a question to the survey if it does not exist, or updates it if it does. It also validates the question and checks if the question is consistent with the survey.
func (*Survey) AddOrUpdateQuestionBytes ¶
AddOrUpdateQuestionBytes adds a question to the survey if it does not exist, or updates it if it does. It also validates the question and checks if the question is consistent with the survey.
func (*Survey) AddOrUpdateQuestionJson ¶
AddOrUpdateQuestionJson adds a question to the survey if it does not exist, or updates it if it does. It also validates the question and checks if the question is consistent with the survey.
func (*Survey) AddOrUpdateQuestionMap ¶
AddOrUpdateQuestionMap adds a question to the survey if it does not exist, or updates it if it does. It also validates the question and checks if the question is consistent with the survey.
func (*Survey) AddQuestion ¶
AddQuestion adds a question to the survey. It also validates the question and checks if the question is consistent with the survey.
func (*Survey) AddQuestionBytes ¶
AddQuestionBytes adds a question to the survey given its representation as a byte array It also validates the question and checks if the question is consistent with the survey.
func (*Survey) AddQuestionJson ¶
AddQuestionJson adds a question to the survey given its representation as a JSON string It also validates the question and checks if the question is consistent with the survey.
func (*Survey) AddQuestionMap ¶
AddQuestionMap adds a question to the survey given its representation as a map[string]any It also validates the question and checks if the question is consistent with the survey.
func (*Survey) AddQuestionToGroup ¶
AddQuestionToGroup adds a question to a group in the survey. Args: * questionNameId: the nameId of the question to add. * groupNameId: the nameId of the group to add the question to. * position: the position of the question in the group. If position is -1, the question will be added at the end of the group. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) GetQuestionsAssignments ¶
GetQuestionsAssignments returns a map with the question nameId as key and the group nameId as value. If a question is not assigned to any group, value will be empty.
func (*Survey) RemoveGroup ¶
RemoveGroup removes a group from the survey given its nameId. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) RemoveQuestion ¶
RemoveQuestion removes a question from the survey given its nameId. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) RemoveQuestionFromGroup ¶
RemoveQuestionFromGroup removes a question from a group in the survey. Args: * questionNameId: the nameId of the question to remove. * groupNameId: the nameId of the group to remove the question from. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) ReviewAnswers ¶
func (s *Survey) ReviewAnswers(ans Answers) (*SurveyResume, error)
ReviewAnswers verifies if the answers provided are valid for this survey. Args: * ans: the answers to check. Returns: * map[string]bool:
- key: the name id of the missing question
- value: if the question is required or not
- error: if an error occurred
func (*Survey) UpdateGroupBytes ¶
UpdateGroupBytes updates a group in the survey given its representation as a byte array It also validates the group and checks if the group is consistent with the survey.
func (*Survey) UpdateGroupJson ¶
UpdateGroupJson updates an existing group in the survey with the data provided as a JSON string. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) UpdateGroupMap ¶
UpdateGroupMap updates an existing group in the survey with the data provided as a map. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) UpdateGroupQuestions ¶
UpdateGroupQuestions updates the questions of a group in the survey. Args: * groupNameId: the nameId of the group to update. * questionsIds: the list of questions ids to update the group with. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) UpdateGroupsOrder ¶
UpdateGroupsOrder updates the groups order in the survey. It also validates the group and checks if the group is consistent with the survey.
func (*Survey) UpdateQuestion ¶
UpdateQuestion updates an existing question in the survey. It also validates the question and checks if the question is consistent with the survey.
func (*Survey) UpdateQuestionBytes ¶
UpdateQuestionBytes updates a question in the survey given its representation as a byte array It also validates the question and checks if the question is consistent with the survey.
func (*Survey) UpdateQuestionJson ¶
UpdateQuestionJson updates an existing question in the survey with the data provided as a JSON string. It also validates the question and checks if the question is consistent with the survey.
func (*Survey) UpdateQuestionMap ¶
UpdateQuestionMap updates an existing question in the survey with the data provided as a map. It also validates the question and checks if the question is consistent with the survey.
func (*Survey) ValidateSurvey ¶
ValidateSurvey validates the survey.
type SurveyResume ¶
type SurveyResume struct { TotalsResume `json:",inline" bson:",inline"` //----- Others Totals -----// // ExternalSurveyIds map of external survey ids. Key: GroupNameId, Value: ExternalSurveyId ExternalSurveyIds map[string]string `json:"externalSurveyIds,omitempty" bson:"externalSurveyIds,omitempty"` //----- Groups -----// // GroupsResume map of groups resume. Key: GroupNameId, Value: GroupResume GroupsResume map[string]*TotalsResume `json:"groupsResume,omitempty" bson:"groupsResume,omitempty"` //----- Errors -----// // InvalidAnswers list of invalid answers InvalidAnswers []InvalidAnswerError `json:"invalidAnswers,omitempty" bson:"invalidAnswers,omitempty"` }
SurveyResume contains the resume of a survey based on the answers provided. All values are calculated based on the answers provided and over the visible components of the survey.
type TotalsResume ¶
type TotalsResume struct { //----- Questions Totals -----// // TotalQuestions number of questions in the group TotalQuestions int `json:"totalQuestions,omitempty" bson:"totalQuestions,omitempty"` // TotalRequiredQuestions number of required questions in the group TotalRequiredQuestions int `json:"totalRequiredQuestions,omitempty" bson:"totalRequiredQuestions,omitempty"` //----- Answers Totals -----// // TotalQuestionsAnswered number of answered questions in the group TotalQuestionsAnswered int `json:"totalQuestionsAnswered,omitempty" bson:"totalQuestionsAnswered,omitempty"` // TotalRequiredQuestionsAnswered number of required questions answered in the group TotalRequiredQuestionsAnswered int `json:"totalRequiredQuestionsAnswered,omitempty" bson:"totalRequiredQuestionsAnswered,omitempty"` // UnansweredQuestions map of unanswered questions, key is the nameId of the question, value is true if the question is required UnansweredQuestions map[string]bool `json:"unansweredQuestions,omitempty" bson:"unansweredQuestions,omitempty"` }