polls

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArePollDataEquals

func ArePollDataEquals(first, second *PollData) bool

ArePollDataEquals check whether the first and second pointers to a PollData object represents the same poll or not.

Types

type AnswerID

type AnswerID uint64

AnswerID represents a unique answer id

func ParseAnswerID

func ParseAnswerID(value string) (AnswerID, error)

ParseAnswerID returns the AnswerID represented inside the provided value, or an error if no id could be parsed properly

func (AnswerID) MarshalJSON

func (id AnswerID) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshaler

func (AnswerID) String

func (id AnswerID) String() string

String implements fmt.Stringer

func (*AnswerID) UnmarshalJSON

func (id *AnswerID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements Unmarshaler

type PollAnswer

type PollAnswer struct {
	ID   AnswerID `json:"id" yaml:"id"`     // Unique id inside the post, serialized as a string for Javascript compatibility
	Text string   `json:"text" yaml:"text"` // Text of the answer
}

PollAnswer contains the data of a single poll answer inserted by the creator

func NewPollAnswer

func NewPollAnswer(id AnswerID, text string) PollAnswer

NewPollAnswer returns a new PollAnswer object

func (PollAnswer) Equals

func (pa PollAnswer) Equals(other PollAnswer) bool

Equals allows to check whether the contents of p are the same of other

func (PollAnswer) String

func (pa PollAnswer) String() string

String implements fmt.Stringer

func (PollAnswer) Validate

func (pa PollAnswer) Validate() error

Validate implements validator

type PollAnswers

type PollAnswers []PollAnswer

PollAnswers represents a slice of poll answers

func NewPollAnswers

func NewPollAnswers(answers ...PollAnswer) PollAnswers

NewPollAnswers builds a new PollAnswers object starting from the given answers

func (PollAnswers) AppendIfMissing

func (answers PollAnswers) AppendIfMissing(newAnswer PollAnswer) PollAnswers

AppendIfMissing appends the given answer to the answers slice if it does not exist inside it yet. It returns a new slice of PollAnswers containing such PollAnswer.

func (PollAnswers) Equals

func (answers PollAnswers) Equals(other PollAnswers) bool

Equals returns true iff the answers slice contains the same data in the same order of the other slice

func (PollAnswers) ExtractAnswersIDs

func (answers PollAnswers) ExtractAnswersIDs() (answersIDs []AnswerID)

ExtractAnswersIDs appends every answer ID to a slice of IDs. It returns a slice of answers IDs.

func (PollAnswers) String

func (answers PollAnswers) String() string

Strings implements fmt.Stringer

func (PollAnswers) Validate

func (answers PollAnswers) Validate() error

Validate implements validator

type PollData

type PollData struct {
	Question              string      `json:"question" yaml:"question"`                               // Describes what poll is about
	ProvidedAnswers       PollAnswers `json:"provided_answers" yaml:"provided_answers"`               // Lists of answers provided by the creator
	EndDate               time.Time   `json:"end_date" yaml:"end_date"`                               // RFC3339 date at which the poll will no longer accept new answers
	AllowsMultipleAnswers bool        `json:"allows_multiple_answers" yaml:"allows_multiple_answers"` // Tells if the poll is a single or multiple answers one
	AllowsAnswerEdits     bool        `json:"allows_answer_edits" yaml:"allows_answer_edits"`         // Tells if the poll allows answer edits
}

PollData contains the information of a poll that is associated to a post

func NewPollData

func NewPollData(question string, endDate time.Time, providedAnswers PollAnswers,
	allowMultipleAnswers, allowsAnswerEdits bool) PollData

NewPollData returns a new PollData object pointer containing the given data

func (PollData) Equals

func (pd PollData) Equals(other PollData) bool

Equals returns true if this poll data object has the same contents of the other given. It assumes neither pd or other are null. To check the equality between possibly null values use ArePollDataEquals instead.

func (PollData) String

func (pd PollData) String() string

String implements fmt.Stringer

func (PollData) Validate

func (pd PollData) Validate() error

Validate implements the validator interface

type UserAnswer

type UserAnswer struct {
	Answers []AnswerID     `json:"answers" yaml:"answers"`
	User    sdk.AccAddress `json:"user" yaml:"user"`
}

UserAnswer contains the data of a user's answer submission

func NewUserAnswer

func NewUserAnswer(answers []AnswerID, user sdk.AccAddress) UserAnswer

NewUserAnswer returns a new AnswerDetails object containing the given data

func (UserAnswer) Equals

func (userAnswers UserAnswer) Equals(other UserAnswer) bool

Equals returns true iff the userPollAnswers contains the same data of the other userPollAnswers

func (UserAnswer) String

func (userAnswers UserAnswer) String() string

Strings implements fmt.Stringer

func (UserAnswer) Validate

func (userAnswers UserAnswer) Validate() error

Validate implements validator

type UserAnswers

type UserAnswers []UserAnswer

func NewUserAnswers

func NewUserAnswers(answers ...UserAnswer) UserAnswers

NewUserAnswers allows to create a new UserAnswers object from the given answers

func (UserAnswers) AppendIfMissingOrIfUsersEquals

func (ua UserAnswers) AppendIfMissingOrIfUsersEquals(answer UserAnswer) (UserAnswers, bool)

AppendIfMissingOrIfUserEquals appends the given answer to the user's answers slice if it does not exist inside it yet or if the user of the answer details is the same. It returns a new slice of containing such answer and a boolean indicating if the slice has been modified or not.

Jump to

Keyboard shortcuts

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