Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Candidates ¶
Candidates can add and delete candidates.
type CandidatesSvc ¶
type CandidatesSvc struct {
// contains filtered or unexported fields
}
CandidatesSvc provides API for candidates.
func NewCandidates ¶
func NewCandidates(r Registry) *CandidatesSvc
NewCandidates creates new instance with given registry.
func (*CandidatesSvc) Add ¶
func (c *CandidatesSvc) Add(name string) error
Add stores single candidate. If already exists - this is not an error.
func (*CandidatesSvc) Del ¶
func (c *CandidatesSvc) Del(name string) error
Del - removes candidate with given name.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is responsible for requests parsing and responses serialization.
func NewController ¶
func NewController(v Votes, c Candidates) *Controller
NewController is a constructor for Controller instance.
func (*Controller) GetStats ¶
func (c *Controller) GetStats(w http.ResponseWriter, req *http.Request)
GetStats returns statistics with current voting data.
func (*Controller) GetStatsWS ¶
func (c *Controller) GetStatsWS(w http.ResponseWriter, req *http.Request)
GetStatsWS returns statistics with current voting data via WebSocket.
func (*Controller) HandleCandidates ¶
func (c *Controller) HandleCandidates(w http.ResponseWriter, req *http.Request)
HandleCandidates is responsible for add/delete operations on candidates.
func (*Controller) HandleVote ¶
func (c *Controller) HandleVote(w http.ResponseWriter, req *http.Request)
HandleVote accepts requests with SMS data and passes this data to service responsible for processing.
type Messenger ¶
type Messenger interface {
RequestSMS(sender, msisdn, text string)
}
Messenger is used to send text messages.
type ScoreKeeper ¶
type ScoreKeeper interface { AddPoint(participant string) error AddCountry(name string) error GetAllCandidates() ([]string, error) GetAllCountries() ([]string, error) Get(key string) (int, error) }
ScoreKeeper persists score and stats, returns results.
type Voting ¶
type Voting struct {
// contains filtered or unexported fields
}
Voting is a service that holds all business logic required to run voting.
func New ¶
func New(m Messenger, en Enquirer, sk ScoreKeeper, ev string) *Voting
New constructs Voting service instance initialized with all dependencies.
func (*Voting) GetStats ¶
GetStats returns voting statistics for each participant and distribution by countries.
func (*Voting) RegisterVote ¶
RegisterVote increments votes counter for participant and also keeps track of number of votes for each country.