model

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownEventType error = errors.New("unknown event type")

Map to convert a connectrpc room status to a model.RoomStatus

Functions

This section is empty.

Types

type BaseEvent

type BaseEvent struct {
	ID          ulid.ULID
	Timestamp   time.Time
	Type        EventType
	RoomID      string
	Description string
}

BaseEvent struct with embedded fields

func (*BaseEvent) GetDescription

func (e *BaseEvent) GetDescription() string

func (*BaseEvent) GetID

func (e *BaseEvent) GetID() string

func (*BaseEvent) GetRoomID

func (e *BaseEvent) GetRoomID() string

func (*BaseEvent) GetTimestamp

func (e *BaseEvent) GetTimestamp() time.Time

func (*BaseEvent) GetType

func (e *BaseEvent) GetType() EventType

type Event

type Event interface {
	GetID() string
	GetTimestamp() time.Time
	GetType() EventType
	GetDescription() string
	GetRoomID() string
}

Event interface definition

func ConvertProtoEvent added in v0.6.5

func ConvertProtoEvent(protoEvent *roomsv1.Event) (Event, error)

ConvertProtoEvent converts the room event type from the ConnectRPC format back to the internal event format.

Returns ErrEventTypeInvalid if the event is malformed.

Returns ErrUlidInvalid if the event id can't be parsed as an ULID.

func NewEvent

func NewEvent(baseEvent BaseEvent) (Event, error)

NewEvent creates a specific Event based on the BaseEvent Type

func NewGenericEvent

func NewGenericEvent(eventType EventType, roomId string, description string) Event

Factory function for creating a new GenericEvent

func NewGenericEventWithTimestamp added in v0.7.2

func NewGenericEventWithTimestamp(timestamp time.Time, eventType EventType, roomId string, description string) Event

Factory function for creating a new GenericEvent. This function is useful for synchronizing the event with other functions.

func NewRoomEditedEvent added in v0.10.0

func NewRoomEditedEvent(roomId string, roomName string, maxPlayers uint32, questionCount uint32, playingDuration time.Duration) Event

Factory function to create a new RoomEditedEvent

func NewRoomStartingEvent added in v0.7.0

func NewRoomStartingEvent(roomId string, description string, questionSetId string) Event

func NewUserEvent

func NewUserEvent(eventType EventType, roomId string, userId string, description string) Event

Factory function for creating a new UserEvent

type EventType

type EventType int
const (
	RoomStarting EventType = iota
	RoomPlaying
	RoomEnding
	RoomEdited
	UserHostChanged
	UserJoined
	UserLeft
	UserBanned
	UserUnbanned
	UserLostConnection

	ErrorStarting
	ErrorEnding
)

func (EventType) String added in v0.7.8

func (e EventType) String() string

type GenericEvent

type GenericEvent struct {
	BaseEvent
}

roomEvent struct embedding baseEvent

type Room

type Room struct {
	ID                     string        `validate:"bingame_room_id"`
	Name                   string        `validate:"max=50" redis:"name"`
	HostID                 string        `validate:"required,uuid5" redis:"hostid"`
	MaxPlayers             uint32        `validate:"required,min=1,max=40" redis:"maxplayers"`
	QuestionCount          uint32        `validate:"required,min=1,max=1000" redis:"questioncount"`
	Status                 RoomStatus    `redis:"status"`
	LastTimeStarted        *time.Time    `redis:"laststarted"` // is nil if the room never started
	QuestionSetID          string        `validate:"omitempty,uuid4" redis:"questionset"`
	FinishedAnsweringCount uint32        `redis:"finishedanswering" validate:"ltefield=MaxPlayers"`
	PlayingDuration        time.Duration `redis:"playingdurationseconds" validate:"min=30s"`
}

func New

func New(hostId string, roomName string, maxPlayers uint32, playingDuration *time.Duration) (*Room, error)

func (*Room) Validate added in v0.7.2

func (r *Room) Validate() error

type RoomEditedEvent added in v0.10.0

type RoomEditedEvent struct {
	BaseEvent
	RoomName        string
	MaxPlayers      uint32
	PlayingDuration time.Duration
}

func (*RoomEditedEvent) GetMaxPlayers added in v0.10.0

func (e *RoomEditedEvent) GetMaxPlayers() uint32

func (*RoomEditedEvent) GetPlayingDuration added in v0.10.0

func (e *RoomEditedEvent) GetPlayingDuration() time.Duration

func (*RoomEditedEvent) GetRoomName added in v0.10.0

func (e *RoomEditedEvent) GetRoomName() string

type RoomStartingEvent added in v0.7.0

type RoomStartingEvent struct {
	BaseEvent
	QuestionSetId string
	StartsIn      time.Duration
}

func (*RoomStartingEvent) GetQuestionSetId added in v0.7.0

func (e *RoomStartingEvent) GetQuestionSetId() string

func (*RoomStartingEvent) GetStartsIn added in v0.7.0

func (e *RoomStartingEvent) GetStartsIn() time.Duration

type RoomStatus

type RoomStatus int
const (
	Waiting RoomStatus = iota
	Starting
	Playing
	Ending
)

statuses of the room

func ConvertProtoStatus added in v0.6.5

func ConvertProtoStatus(protoStatus roomsv1.RoomStatus) (RoomStatus, error)

ConvertProtoStatus converts the room status type from the ConnectRPC format back to the internal model format.

Returns ErrRoomStatusInvalid if the status is not recognized.

type UserEvent

type UserEvent struct {
	BaseEvent
	UserId string
}

userEvent struct embedding baseEvent and adding UserId

func (*UserEvent) GetUserId

func (e *UserEvent) GetUserId() string

Jump to

Keyboard shortcuts

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