db

package
v0.0.0-...-db946dc Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotFound     = errors.New("not found")
	InvalidScore = errors.New("invalid score")
)

Functions

func SumScores

func SumScores(scores []Votes) map[string]int

Types

type Battle

type Battle struct {
	Name      string    `yaml:"name"`
	Entries   Entries   `yaml:"entries"`
	ClosedAt  time.Time `yaml:"closed_at"`
	CreatedAt time.Time `yaml:"crated_at"`
	Hidden    bool      `yaml:"hidden"`
}

func (*Battle) GetEntryByFilename

func (d *Battle) GetEntryByFilename(filename string) (Entry, bool)

func (*Battle) GetEntryByID

func (d *Battle) GetEntryByID(id string) (Entry, bool)

func (Battle) IsVotingOpen

func (d Battle) IsVotingOpen() bool

type DB

type DB struct {
	BoltDB *bolt.DB
}

func (*DB) CloseBattle

func (db *DB) CloseBattle(battleName string) error

func (*DB) GetAllBattles

func (db *DB) GetAllBattles() ([]Battle, error)

func (*DB) GetAllVotes

func (db *DB) GetAllVotes(battleName string) ([]Votes, error)

func (*DB) GetBattle

func (db *DB) GetBattle(battleName string) (*Battle, error)

func (*DB) GetVotes

func (db *DB) GetVotes(battleName string, voterID string) (*Votes, error)

func (*DB) HideBattle

func (db *DB) HideBattle(battleName string) error

func (*DB) OpenBattle

func (db *DB) OpenBattle(battleName string) error

func (*DB) RemoveVotes

func (db *DB) RemoveVotes(battleName string, voterID string) error

func (*DB) UnhideBattle

func (db *DB) UnhideBattle(battleName string) error

func (*DB) UpdateBattle

func (db *DB) UpdateBattle(fsBattle scanner.Battle) error

func (*DB) UpdateVote

func (db *DB) UpdateVote(battleName string, entryID string, voterID string, score int) error

type Entries

type Entries []Entry

func (Entries) Contains

func (e Entries) Contains(entry Entry) bool

func (Entries) Places

func (e Entries) Places(scoreMap ScoreMap) Places

func (Entries) Shuffle

func (e Entries) Shuffle()

func (Entries) SortByID

func (e Entries) SortByID()

func (Entries) SortByName

func (e Entries) SortByName()

func (Entries) SortByScore

func (e Entries) SortByScore(scoreMap ScoreMap)

type Entry

type Entry struct {
	ID        string    `yaml:"id"`
	Title     string    `yaml:"title"`
	Author    string    `yaml:"author"`
	Filename  string    `yaml:"filename"`
	CreatedAt time.Time `yaml:"created_at"`
}

type Places

type Places []Entries

func (Places) All

func (p Places) All() Entries

func (Places) Diff

func (p Places) Diff(entries Entries) Entries

type ScoreMap

type ScoreMap map[string]int

ScoreMap is [entryID]score

type Votes

type Votes struct {
	BattleName string    `yaml:"battle"`
	VoterID    string    `yaml:"voter_id"`
	CreatedAt  time.Time `yaml:"created_at"`
	UpdatedAt  time.Time `yaml:"updated_at"`
	Scores     ScoreMap  `yaml:"score"`
}

func (*Votes) UpdateScore

func (v *Votes) UpdateScore(entryID string, score int)

SetScore updates the scores map in a way where one score value is uniqe among the values.

Jump to

Keyboard shortcuts

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