survey

package
v0.0.0-...-7f26107 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TIME_LAYOUT = "2006-01-02 15:04:05 MST"
)

Variables

This section is empty.

Functions

func SubmissionCount

func SubmissionCount(surveyID int) int

func SurveyCount

func SurveyCount() int

SurveyCount will return the total number of surveys in the database that aren't marked as deleted.

Types

type Answer

type Answer struct {
	ID           int              `json:"id"`
	Answer       string           `json:"answer"`
	DataType     string           `json:"data_type"`
	DateAdded    time.Time        `json:"date_added"`
	DateModified time.Time        `json:"date_modified"`
	UserID       int              `json:"-"`
	Deleted      bool             `json:"-"`
	Revisions    []AnswerRevision `json:"revisions"`
}

Answer contains information for a possible answer for a given Question.

func (*Answer) Delete

func (a *Answer) Delete() error

Delete will mark the referenced Answer as deleted.

type AnswerRevision

type AnswerRevision struct {
	ID         int          `json:"id"`
	User       RevisionUser `json:"user"`
	NewAnswer  string       `json:"new_answer"`
	OldAnswer  string       `json:"old_answer"`
	Date       time.Time    `json:"date"`
	ChangeType string       `json:"change_type"`
}

AnswerRevision is a change record for an Answer.

type Question

type Question struct {
	ID           int                `json:"id"`
	Question     string             `json:"question"`
	DateModified time.Time          `json:"date_modified"`
	DateAdded    time.Time          `json:"date_added"`
	UserID       int                `json:"-"`
	Deleted      bool               `json:"-"`
	Revisions    []QuestionRevision `json:"revisions"`
	Answers      []Answer           `json:"answers"`
}

Question contains information for a question on a survey. It contains answers and revision history for both the question an each answer.

func (*Question) AddAnswer

func (q *Question) AddAnswer(a Answer) error

AddAnswer will commit a new Answer to a Question.

func (*Question) Delete

func (q *Question) Delete() error

Delete will mark the referenced Question as deleted.

func (*Question) GetRevisions

func (q *Question) GetRevisions() error

type QuestionRevision

type QuestionRevision struct {
	ID          int          `json:"id"`
	User        RevisionUser `json:"user"`
	NewQuestion string       `json:"new_question"`
	OldQuestion string       `json:"old_question"`
	Date        time.Time    `json:"date"`
	ChangeType  string       `json:"change_type"`
}

QuestionRevision is a change record for a Question.

type RevisionUser

type RevisionUser struct {
	ID        int    `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Username  string `json:"username"`
}

type Survey

type Survey struct {
	ID           int              `json:"id"`
	Name         string           `json:"name"`
	Description  string           `json:"description"`
	DateAdded    time.Time        `json:"date_added"`
	DateModified time.Time        `json:"date_modified"`
	UserID       int              `json:"-"`
	Deleted      bool             `json:"-"`
	Revisions    []SurveyRevision `json:"revisions"`
	Questions    []Question       `json:"questions"`
	Completion   SurveyStatus     `json:"-"`
}

func GetSurveys

func GetSurveys(skip, take int) ([]Survey, error)

GetSurveys will return a list of surveys in the database or an error if empty.

func (*Survey) AddQuestion

func (s *Survey) AddQuestion(q Question) (Question, error)

AddQuestion will commit a new question to a referenced Survey.

func (*Survey) Delete

func (s *Survey) Delete() error

Delete will remove (mark as deleted) a Survey from the list of returned results

func (*Survey) Get

func (s *Survey) Get() error

Get will update the values on the bound Survey or return an error.

func (*Survey) GetQuestions

func (s *Survey) GetQuestions() error

public getter for questions

func (*Survey) Save

func (s *Survey) Save() error

Add will commit the current Survey to the database.

type SurveyRevision

type SurveyRevision struct {
	ID         int          `json:"id"`
	NewName    *string      `json:"new_name"`
	OldName    *string      `json:"old_name"`
	Date       time.Time    `json:"date"`
	ChangeType string       `json:"change_type"`
	User       RevisionUser `json:"user"`
}

type SurveyStatus

type SurveyStatus struct {
	Completed     bool `json:"completed"`
	QuestionCount int  `json:"question_count"`
}

type SurveySubmission

type SurveySubmission struct {
	ID        int                      `json:"id"`
	User      SurveyUser               `json:"user"`
	Questions []SurveySubmissionAnswer `json:"questions"`
	Survey    Survey                   `json:"survey"`
}

func GetAllSubmissions

func GetAllSubmissions(skip, take, surveyID int) ([]SurveySubmission, error)

func (*SurveySubmission) Get

func (s *SurveySubmission) Get() error

func (*SurveySubmission) Submit

func (s *SurveySubmission) Submit() error

type SurveySubmissionAnswer

type SurveySubmissionAnswer struct {
	ID           int       `json:"id"`
	Answer       string    `json:"answer"`
	Question     string    `json:"question"`
	DateAnswered time.Time `json:"date_answered"`
}

type SurveyUser

type SurveyUser struct {
	ID        int       `json:"id"`
	FirstName string    `json:"fname"`
	LastName  string    `json:"lname"`
	Email     string    `json:"email"`
	DateAdded time.Time `json:"date_added"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL