db

package
v0.0.0-...-0ba1a38 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOperationNotImplemented = errors.New("radiotation: operation not implemented")
	ErrUserNotFound            = errors.New("radiotation: user not found")
	ErrRoomNotFound            = errors.New("radiotation: room not found")
	ErrQueueNotFound           = errors.New("radiotation: queue not found")
	ErrNoTracksInQueue         = errors.New("radiotation: no tracks in queue")
)

Functions

func RandomID

func RandomID(src rand.Source) string

func RandomTrackID

func RandomTrackID(src rand.Source) string

func SaveRotator

func SaveRotator(r Rotator) []byte

Types

type DB

type DB interface {
	RoomDB
	UserDB
	QueueDB
	HistoryDB
}

type HistoryDB

type HistoryDB interface {
	History(RoomID) ([]*TrackEntry, error)
	AddToHistory(RoomID, *TrackEntry) (int, error)
	MarkVetoed(RoomID, UserID) error
}

type QueueDB

type QueueDB interface {
	Tracks(QueueID, *QueueOptions) ([]*QueueTrack, error)
	AddTrack(QueueID, *radio.Track, string) error
	RemoveTrack(QueueID, string) error
}

type QueueID

type QueueID struct {
	RoomID RoomID
	UserID UserID
}

type QueueOptions

type QueueOptions struct {
	Type QueueType
}

type QueueTrack

type QueueTrack struct {
	ID     string `json:"id"`
	Played bool   `json:"played"`

	Track *radio.Track `json:"track"`
}

type QueueType

type QueueType int
const (
	AllTracks QueueType = iota
	PlayedOnly
	UnplayedOnly
)

type Room

type Room struct {
	ID          RoomID      `json:"id"`
	DisplayName string      `json:"displayName"`
	RotatorType RotatorType `json:"-"`
}

type RoomDB

type RoomDB interface {
	Room(RoomID) (*Room, error)
	NextTrack(RoomID) (*User, *radio.Track, error)

	SearchRooms(string) ([]*Room, error)

	AddRoom(*Room) (RoomID, error)
	AddUserToRoom(RoomID, UserID) error
}

type RoomID

type RoomID string

RoomID is an opaque string identifying a room.

type Rotator

type Rotator interface {
	// NextIndex returns the next index in the rotation.
	NextIndex() int
	// Add adds a new index into the rotation. Depending on the implementation,
	// this may or may not be at the end. It's invalid to call NextIndex() before
	// Add() has been called at least once.
	Add()
}

A Rotator says what the next index should be from a list of size n. They can assume that n will never decrease, but it can increase between any two invocations of start.

func LoadRotator

func LoadRotator(b []byte) Rotator

func NewRotator

func NewRotator(r RotatorType) Rotator

type RotatorType

type RotatorType int

RotatorType is an enum for the type of rotation for the room.

const (
	RoundRobin RotatorType = iota
	Shuffle
	Random
)

func (RotatorType) String

func (r RotatorType) String() string

type TrackEntry

type TrackEntry struct {
	UserID UserID
	Track  *radio.Track

	// VetoedBy is only set if Vetoed is true.
	Vetoed   bool
	VetoedBy UserID
}

type User

type User struct {
	ID    UserID `json:"id"`
	First string `json:"first"`
	Last  string `json:"last"`
}

type UserDB

type UserDB interface {
	User(UserID) (*User, error)
	Users(RoomID) ([]*User, error)

	AddUser(user *User) error
}

type UserID

type UserID string

Jump to

Keyboard shortcuts

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