database

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(hashedPwd string, plainPwd []byte) bool

ComparePasswords takes a password hash and compares it to entered password bytes returning true if matches false if not

func GetBoolEnv

func GetBoolEnv(key string, fallback bool) bool

GetBoolEnv gets an environment variable and converts it to a bool and if it finds none uses fallback

func GetEnv

func GetEnv(key string, fallback string) string

GetEnv gets environment variable matching key string and if it finds none uses fallback string returning either the matching or fallback string

func GetIntEnv

func GetIntEnv(key string, fallback int) int

GetIntEnv gets an environment variable and converts it to an int and if it finds none uses fallback

func HashAndSalt

func HashAndSalt(pwd []byte) (string, error)

HashAndSalt takes a password byte and salt + hashes it returning a hash string to store in db

Types

type APIKey added in v1.2.0

type APIKey struct {
	ID          string    `json:"id"`
	Prefix      string    `json:"prefix"`
	WarriorID   string    `json:"warriorId"`
	Name        string    `json:"name"`
	Key         string    `json:"apiKey"`
	Active      bool      `json:"active"`
	CreatedDate time.Time `json:"createdDate"`
	UpdatedDate time.Time `json:"updatedDate"`
}

APIKey structure

type ApplicationStats

type ApplicationStats struct {
	RegisteredCount   int `json:"registeredWarriorCount"`
	UnregisteredCount int `json:"unregisteredWarriorCount"`
	BattleCount       int `json:"battleCount"`
	PlanCount         int `json:"planCount"`
}

ApplicationStats includes warrior, battle, and plan counts

type Battle

type Battle struct {
	BattleID           string           `json:"id"`
	BattleName         string           `json:"name"`
	Warriors           []*BattleWarrior `json:"warriors"`
	Plans              []*Plan          `json:"plans"`
	VotingLocked       bool             `json:"votingLocked"`
	ActivePlanID       string           `json:"activePlanId"`
	PointValuesAllowed []string         `json:"pointValuesAllowed"`
	AutoFinishVoting   bool             `json:"autoFinishVoting"`
	Leaders            []string         `json:"leaders"`
}

Battle aka arena

type BattleWarrior

type BattleWarrior struct {
	WarriorID     string `json:"id"`
	WarriorName   string `json:"name"`
	WarriorRank   string `json:"rank"`
	WarriorAvatar string `json:"avatar"`
	Active        bool   `json:"active"`
	Abandoned     bool   `json:"abandoned"`
}

BattleWarrior aka user

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config holds all the configuration for the db

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database contains all the methods to interact with DB

func New

func New(AdminEmail string, schemaSQL string) *Database

New runs db migrations, sets up a db connection pool and sets previously active warriors to false during startup

func (*Database) AbandonBattle

func (d *Database) AbandonBattle(BattleID string, WarriorID string) ([]*BattleWarrior, error)

AbandonBattle removes a warrior from the current battle by ID and sets abandoned true

func (*Database) ActivatePlanVoting

func (d *Database) ActivatePlanVoting(BattleID string, warriorID string, PlanID string) ([]*Plan, error)

ActivatePlanVoting sets the plan by ID to active, wipes any previous votes/points, and disables votingLock

func (*Database) AddWarriorToBattle

func (d *Database) AddWarriorToBattle(BattleID string, WarriorID string) ([]*BattleWarrior, error)

AddWarriorToBattle adds a warrior by ID to the battle by ID

func (*Database) AuthWarrior

func (d *Database) AuthWarrior(WarriorEmail string, WarriorPassword string) (*Warrior, error)

AuthWarrior attempts to authenticate the warrior

func (*Database) BurnPlan

func (d *Database) BurnPlan(BattleID string, warriorID string, PlanID string) ([]*Plan, error)

BurnPlan removes a plan from the current battle by ID

func (*Database) CleanBattles added in v1.4.0

func (d *Database) CleanBattles(DaysOld int) error

CleanBattles deletes battles older than X days

func (*Database) CleanGuests added in v1.4.0

func (d *Database) CleanGuests(DaysOld int) error

CleanGuests deletes guest warriors older than X days

func (*Database) ConfirmAdmin

func (d *Database) ConfirmAdmin(AdminID string) error

ConfirmAdmin confirms whether the warrior is infact a GENERAL (ADMIN)

func (*Database) ConfirmLeader

func (d *Database) ConfirmLeader(BattleID string, warriorID string) error

ConfirmLeader confirms the warrior is infact leader of the battle

func (*Database) CreateBattle

func (d *Database) CreateBattle(LeaderID string, BattleName string, PointValuesAllowed []string, Plans []*Plan, AutoFinishVoting bool) (*Battle, error)

CreateBattle adds a new battle to the db

func (*Database) CreatePlan

func (d *Database) CreatePlan(BattleID string, warriorID string, PlanName string, PlanType string, ReferenceID string, Link string, Description string, AcceptanceCriteria string) ([]*Plan, error)

CreatePlan adds a new plan to a battle

func (*Database) CreateWarriorCorporal

func (d *Database) CreateWarriorCorporal(WarriorName string, WarriorEmail string, WarriorPassword string, ActiveWarriorID string) (NewWarrior *Warrior, VerifyID string, RegisterErr error)

CreateWarriorCorporal adds a new warrior corporal (registered) to the db

func (*Database) CreateWarriorPrivate

func (d *Database) CreateWarriorPrivate(WarriorName string) (*Warrior, error)

CreateWarriorPrivate adds a new warrior private (guest) to the db

func (*Database) DeleteBattle

func (d *Database) DeleteBattle(BattleID string, warriorID string) error

DeleteBattle removes all battle associations and the battle itself from DB by BattleID

func (*Database) DeleteWarrior added in v1.5.0

func (d *Database) DeleteWarrior(WarriorID string) error

UpdateWarriorProfile attempts to delete a warrior

func (*Database) DeleteWarriorAPIKey added in v1.2.0

func (d *Database) DeleteWarriorAPIKey(WarriorID string, KeyID string) ([]*APIKey, error)

DeleteWarriorAPIKey removes a warriors api key

func (*Database) DemoteBattleLeader added in v1.6.0

func (d *Database) DemoteBattleLeader(BattleID string, warriorID string, LeaderID string) ([]string, error)

DemoteBattleLeader removes a warrior from battle leaders

func (*Database) DemoteWarrior added in v1.1.0

func (d *Database) DemoteWarrior(WarriorID string) error

DemoteWarrior demotes a warrior to CORPORAL (Registered) rank

func (*Database) EndPlanVoting

func (d *Database) EndPlanVoting(BattleID string, warriorID string, PlanID string, AutoFinishVoting bool) ([]*Plan, error)

EndPlanVoting sets plan to active: false

func (*Database) FinalizePlan

func (d *Database) FinalizePlan(BattleID string, warriorID string, PlanID string, PlanPoints string) ([]*Plan, error)

FinalizePlan sets plan to active: false

func (*Database) GenerateAPIKey added in v1.2.0

func (d *Database) GenerateAPIKey(WarriorID string, KeyName string) (*APIKey, error)

GenerateAPIKey generates a new API key for a Warrior

func (*Database) GetAppStats

func (d *Database) GetAppStats() (*ApplicationStats, error)

GetAppStats gets counts of warriors (registered and unregistered), battles, and plans

func (*Database) GetBattle

func (d *Database) GetBattle(BattleID string, WarriorID string) (*Battle, error)

GetBattle gets a battle by ID

func (*Database) GetBattleActiveWarriors

func (d *Database) GetBattleActiveWarriors(BattleID string) []*BattleWarrior

GetBattleActiveWarriors retrieves the active warriors for a given battle from db

func (*Database) GetBattleWarrior

func (d *Database) GetBattleWarrior(BattleID string, WarriorID string) (*BattleWarrior, error)

GetBattleWarrior gets a warrior from db by ID and checks battle active status

func (*Database) GetBattleWarriors

func (d *Database) GetBattleWarriors(BattleID string) []*BattleWarrior

GetBattleWarriors retrieves the warriors for a given battle from db

func (*Database) GetBattlesByWarrior

func (d *Database) GetBattlesByWarrior(WarriorID string) ([]*Battle, error)

GetBattlesByWarrior gets a list of battles by WarriorID

func (*Database) GetPlans

func (d *Database) GetPlans(BattleID string, WarriorID string) []*Plan

GetPlans retrieves plans for given battle from db

func (*Database) GetRegisteredWarriors

func (d *Database) GetRegisteredWarriors(Limit int, Offset int) []*Warrior

GetRegisteredWarriors retrieves the registered warriors from db

func (*Database) GetWarrior

func (d *Database) GetWarrior(WarriorID string) (*Warrior, error)

GetWarrior gets a warrior from db by ID

func (*Database) GetWarriorAPIKeys added in v1.2.0

func (d *Database) GetWarriorAPIKeys(WarriorID string) ([]*APIKey, error)

GetWarriorAPIKeys gets a list of api keys for a warrior

func (*Database) GetWarriorByEmail

func (d *Database) GetWarriorByEmail(WarriorEmail string) (*Warrior, error)

func (*Database) HashAPIKey added in v1.2.0

func (d *Database) HashAPIKey(apikey string) string

HashAPIKey hashes the API key using SHA256 (not reversible)

func (*Database) PromoteWarrior

func (d *Database) PromoteWarrior(WarriorID string) error

PromoteWarrior promotes a warrior to GENERAL (ADMIN) rank

func (*Database) RetractVote

func (d *Database) RetractVote(BattleID string, WarriorID string, PlanID string) []*Plan

RetractVote removes a warriors vote for the plan

func (*Database) RetreatWarrior

func (d *Database) RetreatWarrior(BattleID string, WarriorID string) []*BattleWarrior

RetreatWarrior removes a warrior from the current battle by ID

func (*Database) ReviseBattle

func (d *Database) ReviseBattle(BattleID string, warriorID string, BattleName string, PointValuesAllowed []string, AutoFinishVoting bool) error

ReviseBattle updates the battle by ID

func (*Database) RevisePlan

func (d *Database) RevisePlan(BattleID string, warriorID string, PlanID string, PlanName string, PlanType string, ReferenceID string, Link string, Description string, AcceptanceCriteria string) ([]*Plan, error)

RevisePlan updates the plan by ID

func (*Database) SetBattleLeader

func (d *Database) SetBattleLeader(BattleID string, warriorID string, LeaderID string) ([]string, error)

SetBattleLeader sets the leaderId for the battle

func (*Database) SetVote

func (d *Database) SetVote(BattleID string, WarriorID string, PlanID string, VoteValue string) (BattlePlans []*Plan, AllWarriorsVoted bool)

SetVote sets a warriors vote for the plan

func (*Database) SkipPlan

func (d *Database) SkipPlan(BattleID string, warriorID string, PlanID string) ([]*Plan, error)

SkipPlan sets plan to active: false and unsets battle's activePlanId

func (*Database) UpdateWarriorAPIKey added in v1.2.0

func (d *Database) UpdateWarriorAPIKey(WarriorID string, KeyID string, Active bool) ([]*APIKey, error)

UpdateWarriorAPIKey updates a warriors api key (active column only)

func (*Database) UpdateWarriorProfile

func (d *Database) UpdateWarriorProfile(WarriorID string, WarriorName string, WarriorAvatar string, NotificationsEnabled bool) error

UpdateWarriorProfile attempts to update the warriors profile

func (*Database) ValidateAPIKey added in v1.2.0

func (d *Database) ValidateAPIKey(APK string) (WarriorID string, ValidatationErr error)

ValidateAPIKey checks to see if the API key exists in the database and if so returns WarriorID

func (*Database) VerifyWarriorAccount

func (d *Database) VerifyWarriorAccount(VerifyID string) error

VerifyWarriorAccount attempts to verify a warriors account email

func (*Database) WarriorResetPassword

func (d *Database) WarriorResetPassword(ResetID string, WarriorPassword string) (warriorName string, warriorEmail string, resetErr error)

WarriorResetPassword attempts to reset a warriors password

func (*Database) WarriorResetRequest

func (d *Database) WarriorResetRequest(WarriorEmail string) (resetID string, warriorName string, resetErr error)

WarriorResetRequest inserts a new warrior reset request

func (*Database) WarriorUpdatePassword

func (d *Database) WarriorUpdatePassword(WarriorID string, WarriorPassword string) (warriorName string, warriorEmail string, resetErr error)

WarriorUpdatePassword attempts to update a warriors password

type Plan

type Plan struct {
	PlanID             string    `json:"id"`
	PlanName           string    `json:"name"`
	Type               string    `json:"type"`
	ReferenceID        string    `json:"referenceId"`
	Link               string    `json:"link"`
	Description        string    `json:"description"`
	AcceptanceCriteria string    `json:"acceptanceCriteria"`
	Votes              []*Vote   `json:"votes"`
	Points             string    `json:"points"`
	PlanActive         bool      `json:"active"`
	PlanSkipped        bool      `json:"skipped"`
	VoteStartTime      time.Time `json:"voteStartTime"`
	VoteEndTime        time.Time `json:"voteEndTime"`
}

Plan aka Story structure

type Vote

type Vote struct {
	WarriorID string `json:"warriorId"`
	VoteValue string `json:"vote"`
}

Vote structure

type Warrior

type Warrior struct {
	WarriorID            string `json:"id"`
	WarriorName          string `json:"name"`
	WarriorEmail         string `json:"email"`
	WarriorRank          string `json:"rank"`
	WarriorAvatar        string `json:"avatar"`
	Verified             bool   `json:"verified"`
	NotificationsEnabled bool   `json:"notificationsEnabled"`
}

Warrior aka user

Jump to

Keyboard shortcuts

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