database

package
v0.0.0-...-06a0142 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var Migrations = migrate.NewMigrations()

Functions

func CountUsers

func CountUsers(x ...bun.IDB) (int, error)

func CountVotesForElection

func CountVotesForElection(electionID int, x ...bun.IDB) (int, error)

func DeleteAllCandidatesForUser

func DeleteAllCandidatesForUser(userID string, x ...bun.IDB) error

func DeleteAllVotesForElection

func DeleteAllVotesForElection(electionID int, x ...bun.IDB) error

func DeleteAllVotesForUser

func DeleteAllVotesForUser(userID string, x ...bun.IDB) error

func DeleteBallotForElection

func DeleteBallotForElection(electionID int, x ...bun.IDB) error

func DeleteCandidatesForElection

func DeleteCandidatesForElection(electionID int, x ...bun.IDB) error

func DeleteElectionByID

func DeleteElectionByID(electionID int, x ...bun.IDB) error

func DeleteUser

func DeleteUser(id string, x ...bun.IDB) error

func Get

func Get() *bun.DB

func GetTx

func GetTx() (bun.Tx, error)

func HasUserVotedInElection

func HasUserVotedInElection(userID string, electionID int, x ...bun.IDB) (bool, error)

func Migrate

func Migrate(db *bun.DB) error

Types

type BallotEntry

type BallotEntry struct {
	bun.BaseModel `bun:"ballot_entry" json:"-"`

	ID         int    `bun:",pk,autoincrement" json:"id"`
	ElectionID int    `json:"electionID"`
	Name       string `json:"name"`
	IsRON      bool   `json:"isRON"`
}

func CreateBallot

func CreateBallot(electionID int, names []string, x ...bun.IDB) ([]*BallotEntry, error)

func GetAllBallotEntriesForElection

func GetAllBallotEntriesForElection(electionID int, x ...bun.IDB) ([]*BallotEntry, error)

func (*BallotEntry) Delete

func (b *BallotEntry) Delete(x ...bun.IDB) error

func (*BallotEntry) Insert

func (b *BallotEntry) Insert(x ...bun.IDB) error

type Candidate

type Candidate struct {
	bun.BaseModel `json:"-"`

	UserID     string `json:"userID"`
	ElectionID int    `json:"electionID"`
}

func (*Candidate) Delete

func (c *Candidate) Delete(x ...bun.IDB) error

func (*Candidate) Insert

func (c *Candidate) Insert(x ...bun.IDB) error

type DB

type DB struct {
	DB bun.IDB
}

type Election

type Election struct {
	bun.BaseModel `json:"-"`

	ID          int    `bun:",pk,autoincrement" json:"id"`
	RoleName    string `json:"roleName"`
	Description string `json:"description"`

	IsActive bool `json:"isActive"`
}

func GetActiveElection

func GetActiveElection(x ...bun.IDB) (*Election, error)

func GetAllElections

func GetAllElections(x ...bun.IDB) ([]*Election, error)

func GetElection

func GetElection(id int, x ...bun.IDB) (*Election, error)

func (*Election) Delete

func (e *Election) Delete(x ...bun.IDB) error

func (*Election) Insert

func (e *Election) Insert(x ...bun.IDB) error

func (*Election) Update

func (e *Election) Update(x ...bun.IDB) error

func (*Election) WithCandidates

func (e *Election) WithCandidates(x ...bun.IDB) (*ElectionWithCandidates, error)

type ElectionCandidate

type ElectionCandidate struct {
	Name string `json:"name"`
	ID   string `json:"-"`
	IsMe bool   `json:"isMe"`
}

type ElectionWithCandidates

type ElectionWithCandidates struct {
	Election
	Candidates []*ElectionCandidate `json:"candidates"`
}

type User

type User struct {
	bun.BaseModel `json:"-"`

	StudentID    string `bun:"id,pk" json:"studentID"`
	Name         string `json:"name"`
	PasswordHash []byte `json:"-"`
	IsRestricted bool   `json:"isRestricted"`
	IsAdmin      bool   `json:"isAdmin"`
}

func GetAllUsers

func GetAllUsers(x ...bun.IDB) ([]*User, error)

func GetUser

func GetUser(id string, x ...bun.IDB) (*User, error)

func GetUsersStandingForElection

func GetUsersStandingForElection(electionID int, x ...bun.IDB) ([]*User, error)

func (*User) Insert

func (u *User) Insert(x ...bun.IDB) error

func (*User) Update

func (u *User) Update(x ...bun.IDB) error

type Vote

type Vote struct {
	bun.BaseModel `json:"-"`

	ID         int    `bun:",pk,autoincrement" json:"id"`
	ElectionID int    `json:"electionID"`
	UserID     string `json:"userID"`
	Choices    []int  `json:"choices"`
}

func GetAllVotesForElection

func GetAllVotesForElection(electionID int, x ...bun.IDB) ([]*Vote, error)

func (*Vote) Insert

func (v *Vote) Insert(x ...bun.IDB) error

Jump to

Keyboard shortcuts

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