entity

package
v0.0.0-...-d11cb64 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup()

Cleanup cleans up any db resources

func InitDB

func InitDB() error

InitDB initializes the database

Types

type Entity

type Entity interface {
	Insert() error
	Save() error
}

Entity represents the generic type of db entity

type NextTurnAction

type NextTurnAction int

NextTurnAction represents the next action the acting user needs to take

const (
	Submit NextTurnAction = iota
	Voting
)

A list of actions the user takes in their actions

func (NextTurnAction) String

func (i NextTurnAction) String() string

type Proposal

type Proposal struct {
	gorm.Model

	Number      int
	Text        string
	SubmittedBy string // username of submitter

	RelatedToRule    int
	VotesInFavor     int
	VotesAgainst     int
	VotingInProgress bool
	VotingStarted    *time.Time
	VotingEnded      *time.Time
}

Proposal is the entity for proposed rule-changes

func (Proposal) IsVotingEnded

func (p Proposal) IsVotingEnded() bool

IsVotingEnded determines if voting has ended on this proposal

func (Proposal) IsVotingStarted

func (p Proposal) IsVotingStarted() bool

IsVotingStarted determines if voting has started on this proposal

func (*Proposal) StartVoting

func (p *Proposal) StartVoting()

StartVoting starts voting on this proposal

type Rule

type Rule struct {
	gorm.Model
	RuleNumber int
	RuleText   string
	Initial    bool
	Active     bool
}

Rule represents a single rule

func FindAllActiveRules

func FindAllActiveRules() []Rule

FindAllActiveRules returns the list of active rules

func (Rule) Insert

func (r Rule) Insert() error

Insert inserts the record into the db This does not check to see if the records already exists; it assumes it does not.

func (Rule) Save

func (r Rule) Save() error

Save will insert or update the record, based on whether it has a primary key or not

type User

type User struct {
	gorm.Model
	FullName    string
	DisplayName string
	Username    string
	Password    []byte
	LastLogin   time.Time
	Points      int
	IsTurn      bool
	EndOfTurn   time.Time
	Action      NextTurnAction
}

User contains data for a user of the game

func AddNewUser

func AddNewUser(fullname, displayname, username, password string) (*User, error)

AddNewUser creates a new user and inserts it into the DB

func Authenticate

func Authenticate(username, password string) (*User, error)

Authenticate authenticates the user

func FindUserByDisplayName

func FindUserByDisplayName(name string) (*User, bool)

FindUserByDisplayName returns a user based on the display name. It will return true if the user was found; false otherwise.

func FindUserByUsername

func FindUserByUsername(username string) (*User, bool)

FindUserByUsername finds the user based on the username. It will return true if the user was found; false otherwise.

func SetFirstTurn

func SetFirstTurn() (*User, error)

SetFirstTurn sets the turn to the first user by display name

func SetNextTurn

func SetNextTurn() (*User, error)

SetNextTurn sets the turn indicator to true for the next user and false for all others

func (*User) HashAndSalt

func (u *User) HashAndSalt(value string) error

HashAndSalt converts password to hashed value

func (*User) Insert

func (u *User) Insert() error

Insert inserts the record into the db This does not check to see if the records already exists; it assumes it does not.

func (*User) Save

func (u *User) Save() error

Save will insert or update the record, based on whether it has a primary key or not

func (*User) StartTurn

func (u *User) StartTurn()

StartTurn will set the turn to active for this user and set the EndOfTurn appropriately, ending at 11:59 PM EST four days in the future. Note this doesn't update any other user, so caller is responsible for making sure no other user is set to active

func (User) VerifyPassword

func (u User) VerifyPassword(password string) error

VerifyPassword will validate the given password

Jump to

Keyboard shortcuts

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