database

package
v1.16.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: Apache-2.0 Imports: 14 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 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"`
	UserID      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 Alert added in v1.10.0

type Alert struct {
	AlertID        string `json:"id" db:"id"`
	Name           string `json:"name" db:"name"`
	Type           string `json:"type" db:"type"`
	Content        string `json:"content" db:"content"`
	Active         bool   `json:"active" db:"active"`
	AllowDismiss   bool   `json:"allowDismiss" db:"allow_dismiss"`
	RegisteredOnly bool   `json:"registeredOnly" db:"registered_only"`
	CreatedDate    string `json:"createdDate" db:"created_date"`
	UpdatedDate    string `json:"updatedDate" db:"updated_date"`
}

type ApplicationStats

type ApplicationStats struct {
	RegisteredCount       int `json:"registeredUserCount"`
	UnregisteredCount     int `json:"unregisteredUserCount"`
	BattleCount           int `json:"battleCount"`
	PlanCount             int `json:"planCount"`
	OrganizationCount     int `json:"organizationCount"`
	DepartmentCount       int `json:"departmentCount"`
	TeamCount             int `json:"teamCount"`
	APIKeyCount           int `json:"apikeyCount"`
	ActiveBattleCount     int `json:"activeBattleCount"`
	ActiveBattleUserCount int `json:"activeBattleUserCount"`
}

ApplicationStats includes user, organization, team, battle, and plan counts

type Battle

type Battle struct {
	BattleID             string        `json:"id"`
	BattleName           string        `json:"name"`
	Users                []*BattleUser `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"`
	PointAverageRounding string        `json:"pointAverageRounding"`
}

Battle aka arena

type BattleUser added in v1.8.0

type BattleUser struct {
	UserID     string `json:"id"`
	UserName   string `json:"name"`
	UserType   string `json:"rank"`
	UserAvatar string `json:"avatar"`
	Active     bool   `json:"active"`
	Abandoned  bool   `json:"abandoned"`
	Spectator  bool   `json:"spectator"`
}

BattleUser 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 users to false during startup

func (*Database) AbandonBattle

func (d *Database) AbandonBattle(BattleID string, UserID string) ([]*BattleUser, error)

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

func (*Database) ActivatePlanVoting

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

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

func (*Database) AddBattleLeadersByEmail added in v1.16.0

func (d *Database) AddBattleLeadersByEmail(BattleID string, UserID string, LeaderEmails []string) ([]string, error)

AddBattleLeadersByEmail adds additional battle leaders using provided emails for matches

func (*Database) AddUserToBattle added in v1.8.0

func (d *Database) AddUserToBattle(BattleID string, UserID string) ([]*BattleUser, error)

AddUserToBattle adds a user by ID to the battle by ID

func (*Database) AlertDelete added in v1.10.0

func (d *Database) AlertDelete(AlertID string) error

AlertDelete deletes an alert

func (*Database) AlertsCreate added in v1.10.0

func (d *Database) AlertsCreate(Name string, Type string, Content string, Active bool, AllowDismiss bool, RegisteredOnly bool) error

AlertsCreate creates

func (*Database) AlertsList added in v1.10.0

func (d *Database) AlertsList(Limit int, Offset int) []interface{}

AlertsList gets alerts from db for admin listing

func (*Database) AlertsUpdate added in v1.10.0

func (d *Database) AlertsUpdate(ID string, Name string, Type string, Content string, Active bool, AllowDismiss bool, RegisteredOnly bool) error

AlertsUpdate updates an alert

func (*Database) AuthUser added in v1.8.0

func (d *Database) AuthUser(UserEmail string, UserPassword string) (*User, error)

AuthUser attempts to authenticate the user

func (*Database) BurnPlan

func (d *Database) BurnPlan(BattleID string, UserID 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 users older than X days

func (*Database) ConfirmAdmin

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

ConfirmAdmin confirms whether the users is infact an admin

func (*Database) ConfirmLeader

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

ConfirmLeader confirms the user is infact leader of the battle

func (*Database) CreateBattle

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

CreateBattle adds a new battle to the db

func (*Database) CreatePlan

func (d *Database) CreatePlan(BattleID string, UserID 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) CreateUserGuest added in v1.8.0

func (d *Database) CreateUserGuest(UserName string) (*User, error)

CreateUserGuest adds a new guest user to the db

func (*Database) CreateUserRegistered added in v1.8.0

func (d *Database) CreateUserRegistered(UserName string, UserEmail string, UserPassword string, ActiveUserID string) (NewUser *User, VerifyID string, RegisterErr error)

CreateUserRegistered adds a new registered user to the db

func (*Database) DeleteBattle

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

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

func (*Database) DeleteUser added in v1.8.0

func (d *Database) DeleteUser(UserID string) error

UpdateUserProfile attempts to delete a user

func (*Database) DeleteUserAPIKey added in v1.8.0

func (d *Database) DeleteUserAPIKey(UserID string, KeyID string) ([]*APIKey, error)

DeleteUserAPIKey removes a users api key

func (*Database) DemoteBattleLeader added in v1.6.0

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

DemoteBattleLeader removes a user from battle leaders

func (*Database) DemoteUser added in v1.8.0

func (d *Database) DemoteUser(UserID string) error

DemoteUser demotes a user to registered type

func (*Database) DepartmentAddUser added in v1.8.0

func (d *Database) DepartmentAddUser(DepartmentID string, UserID string, Role string) (string, error)

DepartmentAddUser adds a user to an organization department

func (*Database) DepartmentCreate added in v1.8.0

func (d *Database) DepartmentCreate(OrgID string, OrgName string) (string, error)

DepartmentCreate creates an organization department

func (*Database) DepartmentGet added in v1.8.0

func (d *Database) DepartmentGet(DepartmentID string) (*Department, error)

DepartmentGet gets a department

func (*Database) DepartmentRemoveUser added in v1.8.0

func (d *Database) DepartmentRemoveUser(DepartmentID string, UserID string) error

DepartmentRemoveUser removes a user from a department (and department teams)

func (*Database) DepartmentTeamCreate added in v1.8.0

func (d *Database) DepartmentTeamCreate(DepartmentID string, TeamName string) (string, error)

DepartmentTeamCreate creates a department team

func (*Database) DepartmentTeamList added in v1.8.0

func (d *Database) DepartmentTeamList(DepartmentID string, Limit int, Offset int) []*Team

DepartmentTeamList gets a list of department teams

func (*Database) DepartmentTeamUserRole added in v1.8.0

func (d *Database) DepartmentTeamUserRole(UserID string, OrgID string, DepartmentID string, TeamID string) (string, string, string, error)

DepartmentTeamUserRole gets a users role in organization department team

func (*Database) DepartmentUserList added in v1.8.0

func (d *Database) DepartmentUserList(DepartmentID string, Limit int, Offset int) []*DepartmentUser

DepartmentUserList gets a list of department users

func (*Database) DepartmentUserRole added in v1.8.0

func (d *Database) DepartmentUserRole(UserID string, OrgID string, DepartmentID string) (string, string, error)

DepartmentUserRole gets a users role in department (and organization)

func (*Database) EndPlanVoting

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

EndPlanVoting sets plan to active: false

func (*Database) FinalizePlan

func (d *Database) FinalizePlan(BattleID string, UserID 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(UserID string, KeyName string) (*APIKey, error)

GenerateAPIKey generates a new API key for a User

func (*Database) GetAPIKeys added in v1.9.0

func (d *Database) GetAPIKeys(Limit int, Offset int) []*APIKey

GetAPIKeys gets a list of api keys

func (*Database) GetActiveAlerts added in v1.10.0

func (d *Database) GetActiveAlerts() []interface{}

GetActiveAlerts gets alerts from db for UI display

func (*Database) GetActiveCountries added in v1.10.0

func (d *Database) GetActiveCountries() ([]string, error)

GetActiveCountries gets a list of user countries

func (*Database) GetAppStats

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

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

func (*Database) GetBattle

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

GetBattle gets a battle by ID

func (*Database) GetBattleActiveUsers added in v1.8.0

func (d *Database) GetBattleActiveUsers(BattleID string) []*BattleUser

GetBattleActiveUsers retrieves the active users for a given battle from db

func (*Database) GetBattleUser added in v1.8.0

func (d *Database) GetBattleUser(BattleID string, UserID string) (*BattleUser, error)

GetBattleUser gets a user from db by ID and checks battle active status

func (*Database) GetBattleUsers added in v1.8.0

func (d *Database) GetBattleUsers(BattleID string) []*BattleUser

GetBattleUsers retrieves the users for a given battle from db

func (*Database) GetBattlesByUser added in v1.8.0

func (d *Database) GetBattlesByUser(UserID string) ([]*Battle, error)

GetBattlesByUser gets a list of battles by UserID

func (*Database) GetPlans

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

GetPlans retrieves plans for given battle from db

func (*Database) GetRegisteredUsers added in v1.8.0

func (d *Database) GetRegisteredUsers(Limit int, Offset int) []*User

GetRegisteredUsers retrieves the registered users from db

func (*Database) GetUser added in v1.8.0

func (d *Database) GetUser(UserID string) (*User, error)

GetUser gets a user from db by ID

func (*Database) GetUserAPIKeys added in v1.8.0

func (d *Database) GetUserAPIKeys(UserID string) ([]*APIKey, error)

GetUserAPIKeys gets a list of api keys for a user

func (*Database) GetUserByEmail added in v1.8.0

func (d *Database) GetUserByEmail(UserEmail string) (*User, error)

GetUserByEmail gets the user by email

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) LowercaseUserEmails added in v1.13.0

func (d *Database) LowercaseUserEmails() ([]*User, error)

LowercaseUserEmails goes through and lowercases any user email that has any uppercase letters returning the list of updated users

func (*Database) MergeDuplicateAccounts added in v1.13.0

func (d *Database) MergeDuplicateAccounts() ([]*User, error)

MergeDuplicateAccounts goes through and merges any user accounts with duplicate emails that has any uppercase letters returning the list of merged users

func (*Database) OrganizationAddUser added in v1.8.0

func (d *Database) OrganizationAddUser(OrgID string, UserID string, Role string) (string, error)

OrganizationAddUser adds a user to an organization

func (*Database) OrganizationCreate added in v1.8.0

func (d *Database) OrganizationCreate(UserID string, OrgName string) (string, error)

OrganizationCreate creates an organization

func (*Database) OrganizationDepartmentList added in v1.8.0

func (d *Database) OrganizationDepartmentList(OrgID string, Limit int, Offset int) []*Department

OrganizationDepartmentList gets a list of organization departments

func (*Database) OrganizationGet added in v1.8.0

func (d *Database) OrganizationGet(OrgID string) (*Organization, error)

OrganizationGet gets an organization

func (*Database) OrganizationList added in v1.8.0

func (d *Database) OrganizationList(Limit int, Offset int) []*Organization

OrganizationList gets a list of organizations

func (*Database) OrganizationListByUser added in v1.8.0

func (d *Database) OrganizationListByUser(UserID string, Limit int, Offset int) []*Organization

OrganizationList gets a list of organizations the user is apart of

func (*Database) OrganizationRemoveUser added in v1.8.0

func (d *Database) OrganizationRemoveUser(OrganizationID string, UserID string) error

OrganizationRemoveUser removes a user from a organization

func (*Database) OrganizationTeamCreate added in v1.8.0

func (d *Database) OrganizationTeamCreate(OrgID string, TeamName string) (string, error)

OrganizationTeamCreate creates an organization team

func (*Database) OrganizationTeamList added in v1.8.0

func (d *Database) OrganizationTeamList(OrgID string, Limit int, Offset int) []*Team

OrganizationTeamList gets a list of organization teams

func (*Database) OrganizationTeamUserRole added in v1.8.0

func (d *Database) OrganizationTeamUserRole(UserID string, OrgID string, TeamID string) (string, string, error)

OrganizationTeamUserRole gets a users role in organization team

func (*Database) OrganizationUserList added in v1.8.0

func (d *Database) OrganizationUserList(OrgID string, Limit int, Offset int) []*OrganizationUser

OrganizationUserList gets a list of organization users

func (*Database) OrganizationUserRole added in v1.8.0

func (d *Database) OrganizationUserRole(UserID string, OrgID string) (string, error)

OrganizationUserRole gets a users role in organization

func (*Database) PromoteUser added in v1.8.0

func (d *Database) PromoteUser(UserID string) error

PromoteUser promotes a user to admin type

func (*Database) RetractVote

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

RetractVote removes a users vote for the plan

func (*Database) RetreatUser added in v1.8.0

func (d *Database) RetreatUser(BattleID string, UserID string) []*BattleUser

RetreatUser removes a user from the current battle by ID

func (*Database) ReviseBattle

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

ReviseBattle updates the battle by ID

func (*Database) RevisePlan

func (d *Database) RevisePlan(BattleID string, UserID 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, UserID string, LeaderID string) ([]string, error)

SetBattleLeader sets the leaderId for the battle

func (*Database) SetVote

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

SetVote sets a users vote for the plan

func (*Database) SkipPlan

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

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

func (*Database) TeamAddBattle added in v1.8.0

func (d *Database) TeamAddBattle(TeamID string, BattleID string) error

TeamAddBattle adds a battle to a team

func (*Database) TeamAddUser added in v1.8.0

func (d *Database) TeamAddUser(TeamID string, UserID string, Role string) (string, error)

TeamAddUser adds a user to a team

func (*Database) TeamBattleList added in v1.8.0

func (d *Database) TeamBattleList(TeamID string, Limit int, Offset int) []*Battle

TeamBattleList gets a list of team battles

func (*Database) TeamCreate added in v1.8.0

func (d *Database) TeamCreate(UserID string, TeamName string) (string, error)

TTeamCreate creates a team with current user as an ADMIN

func (*Database) TeamDelete added in v1.8.0

func (d *Database) TeamDelete(TeamID string) error

TeamDelete deletes a team

func (*Database) TeamGet added in v1.8.0

func (d *Database) TeamGet(TeamID string) (*Team, error)

TeamGet gets an team

func (*Database) TeamList added in v1.8.0

func (d *Database) TeamList(Limit int, Offset int) []*Team

TeamList gets a list of teams

func (*Database) TeamListByUser added in v1.8.0

func (d *Database) TeamListByUser(UserID string, Limit int, Offset int) []*Team

TeamListByUser gets a list of teams the user is on

func (*Database) TeamRemoveBattle added in v1.8.0

func (d *Database) TeamRemoveBattle(TeamID string, BattleID string) error

TeamRemoveBattle removes a battle from a team

func (*Database) TeamRemoveUser added in v1.8.0

func (d *Database) TeamRemoveUser(TeamID string, UserID string) error

TeamRemoveUser removes a user from a team

func (*Database) TeamUserList added in v1.8.0

func (d *Database) TeamUserList(TeamID string, Limit int, Offset int) []*OrganizationUser

TeamUserList gets a list of team users

func (*Database) TeamUserRole added in v1.8.0

func (d *Database) TeamUserRole(UserID string, TeamID string) (string, error)

TeamUserRole gets a users role in team

func (*Database) ToggleSpectator added in v1.14.1

func (d *Database) ToggleSpectator(BattleID string, UserID string, Spectator bool) ([]*BattleUser, error)

func (*Database) UpdateUserAPIKey added in v1.8.0

func (d *Database) UpdateUserAPIKey(UserID string, KeyID string, Active bool) ([]*APIKey, error)

UpdateUserAPIKey updates a user api key (active column only)

func (*Database) UpdateUserProfile added in v1.8.0

func (d *Database) UpdateUserProfile(UserID string, UserName string, UserAvatar string, NotificationsEnabled bool, Country string, Locale string, Company string, JobTitle string) error

UpdateUserProfile attempts to update the users profile

func (*Database) UserResetPassword added in v1.8.0

func (d *Database) UserResetPassword(ResetID string, UserPassword string) (UserName string, UserEmail string, resetErr error)

UserResetPassword attempts to reset a users password

func (*Database) UserResetRequest added in v1.8.0

func (d *Database) UserResetRequest(UserEmail string) (resetID string, UserName string, resetErr error)

UserResetRequest inserts a new user reset request

func (*Database) UserUpdatePassword added in v1.8.0

func (d *Database) UserUpdatePassword(UserID string, UserPassword string) (Name string, Email string, resetErr error)

UserUpdatePassword attempts to update a users password

func (*Database) ValidateAPIKey added in v1.2.0

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

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

func (*Database) VerifyUserAccount added in v1.8.0

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

VerifyUserAccount attempts to verify a users account email

type Department added in v1.8.0

type Department struct {
	DepartmentID string `json:"id"`
	Name         string `json:"name"`
	CreatedDate  string `json:"createdDate"`
	UpdatedDate  string `json:"updatedDate"`
}

type DepartmentUser added in v1.8.0

type DepartmentUser struct {
	UserID string `json:"id"`
	Name   string `json:"name"`
	Email  string `json:"email"`
	Role   string `json:"role"`
}

type Organization added in v1.8.0

type Organization struct {
	OrganizationID string `json:"id"`
	Name           string `json:"name"`
	CreatedDate    string `json:"createdDate"`
	UpdatedDate    string `json:"updatedDate"`
}

Organization can be a company

type OrganizationUser added in v1.8.0

type OrganizationUser struct {
	UserID string `json:"id"`
	Name   string `json:"name"`
	Email  string `json:"email"`
	Role   string `json:"role"`
}

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 Team added in v1.8.0

type Team struct {
	TeamID      string `json:"id"`
	Name        string `json:"name"`
	CreatedDate string `json:"createdDate"`
	UpdatedDate string `json:"updatedDate"`
}

type TeamUser added in v1.8.0

type TeamUser struct {
	UserID string `json:"id"`
	Name   string `json:"name"`
	Email  string `json:"email"`
	Role   string `json:"role"`
}

type User added in v1.8.0

type User struct {
	UserID               string `json:"id"`
	UserName             string `json:"name"`
	UserEmail            string `json:"email"`
	UserType             string `json:"rank"`
	UserAvatar           string `json:"avatar"`
	Verified             bool   `json:"verified"`
	NotificationsEnabled bool   `json:"notificationsEnabled"`
	Country              string `json:"country"`
	Locale               string `json:"locale"`
	Company              string `json:"company"`
	JobTitle             string `json:"jobTitle"`
}

User aka user

type Vote

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

Vote structure

Jump to

Keyboard shortcuts

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