Documentation ¶
Index ¶
- Variables
- func GetDatabase() *sql.DB
- func SetupPostgres(pc config.PostgreSQLConnection)
- func UUID() (string, error)
- func WipeDatabase()
- type BigintSlice
- type Mailman
- type PgQuery
- type PollyContext
- func (context *PollyContext) Authentication(request *restful.Request) (interface{}, error)
- func (context *PollyContext) Begin() (*PollyContextTx, error)
- func (context *PollyContext) Exec(query string, args ...interface{}) (sql.Result, error)
- func (context *PollyContext) GetMailman(mailbox string) (Mailman, error)
- func (context *PollyContext) GetProposalByID(id int64) (Proposal, error)
- func (context *PollyContext) GetUserByAccessToken(token string) (interface{}, error)
- func (context *PollyContext) GetUserByID(id int64) (User, error)
- func (context *PollyContext) GetUserByNameAndPassword(name, password string) (User, error)
- func (context *PollyContext) GrantMaxValue() uint
- func (context *PollyContext) LoadAllProposals() ([]Proposal, error)
- func (context *PollyContext) LoadAllUserVotes(userID int64) ([]Vote, error)
- func (context *PollyContext) LoadAllUsers() ([]User, error)
- func (context *PollyContext) LoadProposalByID(id int64) (Proposal, error)
- func (context *PollyContext) LoadUserByID(id int64) (User, error)
- func (context *PollyContext) LogSummary()
- func (context *PollyContext) NewAPIContext() smolder.APIContext
- func (context *PollyContext) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (context *PollyContext) QueryRow(query string, args ...interface{}) *sql.Row
- func (context *PollyContext) RemainingSmallGrantThisMonth(month uint) uint
- func (context *PollyContext) SmallGrantMaxValue(month uint) uint
- type PollyContextTx
- func (hTx *PollyContextTx) Commit() error
- func (hTx *PollyContextTx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (hTx *PollyContextTx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (hTx *PollyContextTx) QueryRow(query string, args ...interface{}) *sql.Row
- func (hTx *PollyContextTx) Rollback() error
- type Proposal
- func (proposal *Proposal) Accepted(context *PollyContext) bool
- func (proposal *Proposal) Ended(context *PollyContext) bool
- func (proposal *Proposal) Ends(context *PollyContext) time.Time
- func (proposal *Proposal) IsTopTwo(context *PollyContext) bool
- func (proposal *Proposal) Save(context *PollyContext) error
- func (proposal *Proposal) Started(context *PollyContext) bool
- func (proposal *Proposal) Update(context *PollyContext) error
- func (proposal *Proposal) Vote(context *PollyContext, user User, up bool) (Vote, error)
- type StringSlice
- type User
- type Vote
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidID is the error returned when encountering an invalid database ID ErrInvalidID = errors.New("Invalid id") )
Functions ¶
func GetDatabase ¶
GetDatabase connects to the database on first run and returns the existing connection on further calls
func SetupPostgres ¶
func SetupPostgres(pc config.PostgreSQLConnection)
SetupPostgres sets the db configuration
Types ¶
type BigintSlice ¶
type BigintSlice []int64
BigintSlice is a custom int64 slice for postgres encoding
func (*BigintSlice) Scan ¶
func (s *BigintSlice) Scan(value interface{}) error
Scan converts a postgres value into an int64 slice
type Mailman ¶
Mailman represents the db schema of mailman info
func (*Mailman) Update ¶
func (mm *Mailman) Update(context *PollyContext) error
Update mailman info in the database
type PollyContext ¶
type PollyContext struct { Config config.Data Queries []PgQuery // contains filtered or unexported fields }
PollyContext is polly's central context
func (*PollyContext) Authentication ¶
func (context *PollyContext) Authentication(request *restful.Request) (interface{}, error)
Authentication parses the request for an access-/authtoken and returns the matching user
func (*PollyContext) Begin ¶
func (context *PollyContext) Begin() (*PollyContextTx, error)
Begin returns a new polly transactional context
func (*PollyContext) Exec ¶
func (context *PollyContext) Exec(query string, args ...interface{}) (sql.Result, error)
Exec runs a postgres Exec
func (*PollyContext) GetMailman ¶
func (context *PollyContext) GetMailman(mailbox string) (Mailman, error)
GetMailman returns the mailman info for a mailbox
func (*PollyContext) GetProposalByID ¶
func (context *PollyContext) GetProposalByID(id int64) (Proposal, error)
GetProposalByID returns a proposal by ID from the cache
func (*PollyContext) GetUserByAccessToken ¶
func (context *PollyContext) GetUserByAccessToken(token string) (interface{}, error)
GetUserByAccessToken loads a user by accesstoken from the database
func (*PollyContext) GetUserByID ¶
func (context *PollyContext) GetUserByID(id int64) (User, error)
GetUserByID returns a user by ID from the cache
func (*PollyContext) GetUserByNameAndPassword ¶
func (context *PollyContext) GetUserByNameAndPassword(name, password string) (User, error)
GetUserByNameAndPassword loads a user by name & password from the database
func (*PollyContext) GrantMaxValue ¶
func (context *PollyContext) GrantMaxValue() uint
GrantMaxValue returns the max allowed grant value
func (*PollyContext) LoadAllProposals ¶
func (context *PollyContext) LoadAllProposals() ([]Proposal, error)
LoadAllProposals loads all proposals from the database
func (*PollyContext) LoadAllUserVotes ¶
func (context *PollyContext) LoadAllUserVotes(userID int64) ([]Vote, error)
LoadAllUserVotes loads all votes for a user from the database
func (*PollyContext) LoadAllUsers ¶
func (context *PollyContext) LoadAllUsers() ([]User, error)
LoadAllUsers loads all users from the database
func (*PollyContext) LoadProposalByID ¶
func (context *PollyContext) LoadProposalByID(id int64) (Proposal, error)
LoadProposalByID loads a proposal by ID from the database
func (*PollyContext) LoadUserByID ¶
func (context *PollyContext) LoadUserByID(id int64) (User, error)
LoadUserByID loads a user by ID from the database
func (*PollyContext) LogSummary ¶
func (context *PollyContext) LogSummary()
LogSummary logs out the current context stats
func (*PollyContext) NewAPIContext ¶
func (context *PollyContext) NewAPIContext() smolder.APIContext
NewAPIContext returns a new polly context
func (*PollyContext) Query ¶
func (context *PollyContext) Query(query string, args ...interface{}) (*sql.Rows, error)
Query runs a postgres Query
func (*PollyContext) QueryRow ¶
func (context *PollyContext) QueryRow(query string, args ...interface{}) *sql.Row
QueryRow runs a postgres QueryRow
func (*PollyContext) RemainingSmallGrantThisMonth ¶
func (context *PollyContext) RemainingSmallGrantThisMonth(month uint) uint
RemainingSmallGrantThisMonth returns the total available budget for small grants this month
func (*PollyContext) SmallGrantMaxValue ¶
func (context *PollyContext) SmallGrantMaxValue(month uint) uint
SmallGrantMaxValue returns the max available value for a micro budget
type PollyContextTx ¶
type PollyContextTx struct {
// contains filtered or unexported fields
}
PollyContextTx is a transactional polly context
func (*PollyContextTx) Commit ¶
func (hTx *PollyContextTx) Commit() error
Commit runs a postgres Commit in the transactional context
func (*PollyContextTx) Exec ¶
func (hTx *PollyContextTx) Exec(query string, args ...interface{}) (sql.Result, error)
Exec runs a postgres Exec in the transactional context
func (*PollyContextTx) Query ¶
func (hTx *PollyContextTx) Query(query string, args ...interface{}) (*sql.Rows, error)
Query runs a postgres Query in the transactional context
func (*PollyContextTx) QueryRow ¶
func (hTx *PollyContextTx) QueryRow(query string, args ...interface{}) *sql.Row
QueryRow runs a postgres QueryRow in the transactional context
func (*PollyContextTx) Rollback ¶
func (hTx *PollyContextTx) Rollback() error
Rollback runs a postgres Rollback in the transactional context
type Proposal ¶
type Proposal struct { ID int64 UserID int64 Title string Description string Activities string Contact string Recipient string Recipient2 string Value uint64 RealValue uint64 Starts time.Time FinishedDate time.Time Votes uint64 Vetos uint64 Moderated bool StartTrigger bool }
Proposal represents the db schema of a proposal
func (*Proposal) Accepted ¶
func (proposal *Proposal) Accepted(context *PollyContext) bool
Accepted returns true if a proposal has finished and was accepted by poll
func (*Proposal) Ended ¶
func (proposal *Proposal) Ended(context *PollyContext) bool
Ended returns true if a proposal ended
func (*Proposal) Ends ¶
func (proposal *Proposal) Ends(context *PollyContext) time.Time
Ends returns when this proposal ends
func (*Proposal) IsTopTwo ¶
func (proposal *Proposal) IsTopTwo(context *PollyContext) bool
func (*Proposal) Save ¶
func (proposal *Proposal) Save(context *PollyContext) error
Save a proposal to the database
func (*Proposal) Started ¶
func (proposal *Proposal) Started(context *PollyContext) bool
Started returns true if a proposal has started
func (*Proposal) Update ¶
func (proposal *Proposal) Update(context *PollyContext) error
Update a proposal in the database
type StringSlice ¶
type StringSlice []string
StringSlice is a custom string slice for postgres encoding
func (*StringSlice) Scan ¶
func (s *StringSlice) Scan(value interface{}) error
Scan converts a postgres value into a string slice
type User ¶
type User struct { ID int64 Username string About string Email string Activated bool AuthToken StringSlice }
User represents the db schema of a user
func (*User) Update ¶
func (user *User) Update(context *PollyContext) error
Update a user in the database
func (*User) UpdatePassword ¶
func (user *User) UpdatePassword(context *PollyContext, password string) error
UpdatePassword sets a new user password in the database