voting

package
v0.0.0-...-adebd87 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeHTML

func ServeHTML(w http.ResponseWriter, req *http.Request)

ServeHTML serves single HTML file that displays WebSocket data.

Types

type Candidates

type Candidates interface {
	Add(name string) error
	Del(name string) error
}

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 Enquirer

type Enquirer interface {
	Lookup(msisdn string) (string, error)
}

Enquirer is used to resolve Country by MSISDN.

type Message

type Message struct {
	Originator string
	Body       string
}

Message is a struct that we expect on web-hook endpoint when SMS was sent to us.

type Messenger

type Messenger interface {
	RequestSMS(sender, msisdn, text string)
}

Messenger is used to send text messages.

type Registry

type Registry interface {
	AddCandidate(name string) error
	RemoveCandidate(name string) error
}

Registry stores all existing candidates. Supports add and delete operations.

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 StatItem

type StatItem struct {
	Name  string
	Value int
}

StatItem holds counter name and current read.

type Stats

type Stats struct {
	Candidates []StatItem
	Countries  []StatItem
}

Stats holds collections of StatItems.

type Votes

type Votes interface {
	GetStats() (Stats, error)
	RegisterVote(msisdn, text string) error
}

Votes is capable of processing vote SMS messages.

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

func (s *Voting) GetStats() (Stats, error)

GetStats returns voting statistics for each participant and distribution by countries.

func (*Voting) RegisterVote

func (s *Voting) RegisterVote(msisdn, cand string) error

RegisterVote increments votes counter for participant and also keeps track of number of votes for each country.

Jump to

Keyboard shortcuts

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