database

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: Apache-2.0 Imports: 12 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

type APIKey struct {
	ID          string    `json:"id"`
	Prefix      string    `json:"prefix"`
	UserID      string    `json:"userId"`
	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

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"`
	RetrospectiveCount   int `json:"retrospectiveCount"`
	OrganizationCount    int `json:"organizationCount"`
	DepartmentCount      int `json:"departmentCount"`
	TeamCount            int `json:"teamCount"`
	APIKeyCount          int `json:"apikeyCount"`
	ActiveRetroCount     int `json:"activeRetroCount"`
	ActiveRetroUserCount int `json:"activeRetroUserCount"`
}

ApplicationStats includes user, retrospective counts

type Color

type Color struct {
	Color  string `json:"color"`
	Legend string `json:"legend"`
}

Color is a color legend

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) AbandonRetrospective

func (d *Database) AbandonRetrospective(RetrospectiveID string, UserID string) ([]*RetrospectiveUser, error)

AbandonRetrospective removes a user from the current retrospective by ID and sets abandoned true

func (*Database) AddUserToRetrospective

func (d *Database) AddUserToRetrospective(RetrospectiveID string, UserID string) ([]*RetrospectiveUser, error)

AddUserToRetrospective adds a user by ID to the retrospective by ID

func (*Database) AlertDelete

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

AlertDelete deletes an alert

func (*Database) AlertsCreate

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

AlertsCreate creates

func (*Database) AlertsList

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

AlertsList gets alerts from db for admin listing

func (*Database) AlertsUpdate

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

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

AuthUser attempts to authenticate the user

func (*Database) CleanGuests

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

CleanGuests deletes guest users older than X days

func (*Database) CleanRetrospectives

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

CleanRetrospectives deletes retrospectives older than X days

func (*Database) ConfirmAdmin

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

ConfirmAdmin confirms whether the user is infact a ADMIN

func (*Database) ConfirmOwner

func (d *Database) ConfirmOwner(RetrospectiveID string, userID string) error

ConfirmOwner confirms the user is infact owner of the retrospective

func (*Database) CreateRetrospective

func (d *Database) CreateRetrospective(OwnerID string, RetrospectiveName string) (*Retrospective, error)

CreateRetrospective adds a new retrospective to the db

func (*Database) CreateRetrospectiveAction

func (d *Database) CreateRetrospectiveAction(RetrospectiveID string, UserID string, Content string) ([]*RetrospectiveAction, error)

CreateRetroAction adds a new action to the retrospective

func (*Database) CreateRetrospectiveItemImprove

func (d *Database) CreateRetrospectiveItemImprove(RetrospectiveID string, UserID string, Content string) ([]*RetrospectiveItem, error)

CreateRetrospectiveItemImprove adds a improve item to the retrospective

func (*Database) CreateRetrospectiveItemQuestion

func (d *Database) CreateRetrospectiveItemQuestion(RetrospectiveID string, UserID string, Content string) ([]*RetrospectiveItem, error)

CreateRetrospectiveItemQuestion adds a question item to the retrospective

func (*Database) CreateRetrospectiveItemWorked

func (d *Database) CreateRetrospectiveItemWorked(RetrospectiveID string, UserID string, Content string) ([]*RetrospectiveItem, error)

CreateRetrospectiveItemWorked adds a worked item to the retrospective

func (*Database) CreateUserGuest

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

CreateUserGuest adds a new user guest to the db

func (*Database) CreateUserRegistered

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

CreateUserRegistered adds a new user registered to the db

func (*Database) DeleteRetrospective

func (d *Database) DeleteRetrospective(RetrospectiveID string, userID string) error

DeleteRetrospective removes all retrospective associations and the retrospective itself from DB by RetrospectiveID

func (*Database) DeleteRetrospectiveAction

func (d *Database) DeleteRetrospectiveAction(RetrospectiveID string, userID string, ActionID string) ([]*RetrospectiveAction, error)

DeleteRetrospectiveAction removes a goal from the current board by ID

func (*Database) DeleteRetrospectiveItem

func (d *Database) DeleteRetrospectiveItem(RetrospectiveID string, userID string, ItemID string) (WorkedItems []*RetrospectiveItem, ImproveItems []*RetrospectiveItem, QuestionItems []*RetrospectiveItem, DeleteError error)

DeleteRetrospectiveItem removes a item from the current board by ID

func (*Database) DeleteUser

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

DeleteUser attempts to delete a user

func (*Database) DeleteUserAPIKey

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

DeleteUserAPIKey removes a users api key

func (*Database) DemoteUser

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

DemoteUser demotes a user to REGISTERED type

func (*Database) DepartmentAddUser

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

DepartmentAddUser adds a user to an organization department

func (*Database) DepartmentCreate

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

DepartmentCreate creates an organization department

func (*Database) DepartmentGet

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

DepartmentGet gets a department

func (*Database) DepartmentRemoveUser

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

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

func (*Database) DepartmentTeamCreate

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

DepartmentTeamCreate creates a department team

func (*Database) DepartmentTeamList

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

DepartmentTeamList gets a list of department teams

func (*Database) DepartmentTeamUserRole

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

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

DepartmentUserList gets a list of department users

func (*Database) DepartmentUserRole

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

DepartmentUserRole gets a users role in department (and organization)

func (*Database) FilterItemsByUser

func (d *Database) FilterItemsByUser(UserID string, Items []*RetrospectiveItem) []*RetrospectiveItem

FilterItemsByUser filters the list of items by userId

func (*Database) GenerateAPIKey

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

GenerateAPIKey generates a new API key for a User

func (*Database) GetAPIKeys

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

GetAPIKeys gets a list of api keys

func (*Database) GetActiveAlerts

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

GetActiveAlerts gets alerts from db for UI display

func (*Database) GetActiveCountries

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), and retrospectives

func (*Database) GetRegisteredUsers

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

GetRegisteredUsers retrieves the registered users from db

func (*Database) GetRetrospective

func (d *Database) GetRetrospective(RetrospectiveID string) (*Retrospective, error)

GetRetrospective gets a retrospective by ID

func (*Database) GetRetrospectiveActions

func (d *Database) GetRetrospectiveActions(RetrospectiveID string) []*RetrospectiveAction

GetRetrospectiveActions retrieves retrospective actions from the DB

func (*Database) GetRetrospectiveItems

func (d *Database) GetRetrospectiveItems(RetrospectiveID string) (Worked []*RetrospectiveItem, Improve []*RetrospectiveItem, Question []*RetrospectiveItem)

GetRetrospectiveItems retrieves retrospective items from the DB

func (*Database) GetRetrospectiveUser

func (d *Database) GetRetrospectiveUser(RetrospectiveID string, UserID string) (*RetrospectiveUser, error)

GetRetrospectiveUser gets a user from db by ID and checks retrospective active status

func (*Database) GetRetrospectiveUsers

func (d *Database) GetRetrospectiveUsers(RetrospectiveID string) []*RetrospectiveUser

GetRetrospectiveUsers retrieves the users for a given retrospective from db

func (*Database) GetRetrospectivesByUser

func (d *Database) GetRetrospectivesByUser(UserID string) ([]*Retrospective, error)

GetRetrospectivesByUser gets a list of retrospectives by UserID

func (*Database) GetUser

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

GetUser gets a user from db by ID

func (*Database) GetUserAPIKeys

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

GetUserAPIKeys gets a list of api keys for a user

func (*Database) GetUserByEmail

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

GetUserByEmail gets a user by email

func (*Database) HashAPIKey

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

HashAPIKey hashes the API key using SHA256 (not reversible)

func (*Database) NestRetrospectiveItem

func (d *Database) NestRetrospectiveItem(RetrospectiveID string, userID string, ItemID string, ParentID string) (WorkedItems []*RetrospectiveItem, ImproveItems []*RetrospectiveItem, QuestionItems []*RetrospectiveItem, DeleteError error)

NestRetrospectiveItem nests a item under another

func (*Database) OrganizationAddUser

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

OrganizationAddUser adds a user to an organization

func (*Database) OrganizationCreate

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

OrganizationCreate creates an organization

func (*Database) OrganizationDepartmentList

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

OrganizationDepartmentList gets a list of organization departments

func (*Database) OrganizationGet

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

OrganizationGet gets an organization

func (*Database) OrganizationList

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

OrganizationList gets a list of organizations

func (*Database) OrganizationListByUser

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

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

OrganizationRemoveUser removes a user from a organization

func (*Database) OrganizationTeamCreate

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

OrganizationTeamCreate creates an organization team

func (*Database) OrganizationTeamList

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

OrganizationTeamList gets a list of organization teams

func (*Database) OrganizationTeamUserRole

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

OrganizationTeamUserRole gets a users role in organization team

func (*Database) OrganizationUserList

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

OrganizationUserList gets a list of organization users

func (*Database) OrganizationUserRole

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

OrganizationUserRole gets a users role in organization

func (*Database) PromoteUser

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

PromoteUser promotes a user to ADMIN type

func (*Database) RetreatUser

func (d *Database) RetreatUser(RetrospectiveID string, UserID string) []*RetrospectiveUser

RetreatUser removes a user from the current retrospective by ID

func (*Database) RetrospectiveAdvancePhase

func (d *Database) RetrospectiveAdvancePhase(RetrospectiveID string, userID string, Phase int) (*Retrospective, error)

RetrospectiveAdvancePhase sets the phase for the retrospective

func (*Database) SetRetrospectiveOwner

func (d *Database) SetRetrospectiveOwner(RetrospectiveID string, userID string, OwnerID string) (*Retrospective, error)

SetRetrospectiveOwner sets the ownerId for the retrospective

func (*Database) TeamAddRetrospective

func (d *Database) TeamAddRetrospective(TeamID string, RetrospectiveID string) error

TeamAddRetrospective adds a retrospective to a team

func (*Database) TeamAddUser

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

TeamAddUser adds a user to a team

func (*Database) TeamCreate

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

TTeamCreate creates a team with current user as an ADMIN

func (*Database) TeamDelete

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

TeamDelete deletes a team

func (*Database) TeamGet

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

TeamGet gets an team

func (*Database) TeamList

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

TeamList gets a list of teams

func (*Database) TeamListByUser

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

TeamListByUser gets a list of teams the user is on

func (*Database) TeamRemoveRetrospective

func (d *Database) TeamRemoveRetrospective(TeamID string, RetrospectiveID string) error

TeamRemoveRetrospective removes a retrospective from a team

func (*Database) TeamRemoveUser

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

TeamRemoveUser removes a user from a team

func (*Database) TeamRetrospectiveList

func (d *Database) TeamRetrospectiveList(TeamID string, Limit int, Offset int) []*Retrospective

TeamRetrospectiveList gets a list of team retrospectives

func (*Database) TeamUserList

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

TeamUserList gets a list of team users

func (*Database) TeamUserRole

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

TeamUserRole gets a users role in team

func (*Database) UnNestRetrospectiveItem

func (d *Database) UnNestRetrospectiveItem(RetrospectiveID string, userID string, ItemID string) (WorkedItems []*RetrospectiveItem, ImproveItems []*RetrospectiveItem, QuestionItems []*RetrospectiveItem, DeleteError error)

NestRetrospectiveItem unnests a item from under another

func (*Database) UpdateUserAPIKey

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

UpdateUserAPIKey updates a users api key (active column only)

func (*Database) UpdateUserProfile

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

UpdateUserProfile attempts to update the users profile

func (*Database) UpdatedRetrospectiveAction

func (d *Database) UpdatedRetrospectiveAction(RetrospectiveID string, userID string, ActionID string, Completed bool) (Actions []*RetrospectiveAction, DeleteError error)

UpdatedRetrospectiveAction updates an actions status

func (*Database) UserResetPassword

func (d *Database) UserResetPassword(ResetID string, UserPassword string) (userName string, userEmail string, resetErr error)

UserResetPassword attempts to reset a users password

func (*Database) UserResetRequest

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

UserResetRequest inserts a new user reset request

func (*Database) UserUpdatePassword

func (d *Database) UserUpdatePassword(UserID string, UserPassword string) (userName string, userEmail string, resetErr error)

UserUpdatePassword attempts to update a users password

func (*Database) ValidateAPIKey

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

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

VerifyUserAccount attempts to verify a users account email

func (*Database) VoteRetrospectiveItem

func (d *Database) VoteRetrospectiveItem(RetrospectiveID string, userID string, ItemID string) (WorkedItems []*RetrospectiveItem, ImproveItems []*RetrospectiveItem, QuestionItems []*RetrospectiveItem, DeleteError error)

VoteRetrospectiveItem votes for a retrospective item

type Department

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

type DepartmentUser

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

type Organization

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

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

type Retrospective

type Retrospective struct {
	RetrospectiveID   string                 `json:"id" db:"id"`
	OwnerID           string                 `json:"ownerId" db:"ownder_id"`
	RetrospectiveName string                 `json:"name" db:"name"`
	Users             []*RetrospectiveUser   `json:"users"`
	WorkedItems       []*RetrospectiveItem   `json:"workedItems"`
	ImproveItems      []*RetrospectiveItem   `json:"improveItems"`
	QuestionItems     []*RetrospectiveItem   `json:"questionItems"`
	ActionItems       []*RetrospectiveAction `json:"actionItems"`
	Phase             int                    `json:"phase" db:"phase"`
}

Retrospective A story mapping board

type RetrospectiveAction

type RetrospectiveAction struct {
	ID              string `json:"id" db:"id"`
	RetrospectiveID string `json:"retrospectiveId" db:"retrospective_id"`
	Content         string `json:"content" db:"content"`
	Completed       bool   `json:"completed" db:"completed"`
}

RetrospectiveAction is an action the team can take based on retro feedback

type RetrospectiveItem

type RetrospectiveItem struct {
	ID              string   `json:"id" db:"id"`
	RetrospectiveID string   `json:"retrospectiveId" db:"retrospective_id"`
	UserID          string   `json:"userId" db:"user_id"`
	ParentID        string   `json:"parentId" db:"parent_id"`
	Content         string   `json:"content" db:"content"`
	Type            string   `json:"type" db:"type"`
	Votes           []string `json:"votes" db:"votes"`
}

RetrospectiveItem can be a pro (went well/worked), con (needs improvement), or a question

type RetrospectiveUser

type RetrospectiveUser struct {
	UserID   string `json:"id"`
	UserName string `json:"name"`
	Active   bool   `json:"active"`
}

RetrospectiveUser aka user

type Team

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

type TeamUser

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

type User

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

User aka user

Jump to

Keyboard shortcuts

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