postgres

package
v0.0.0-...-baa204d Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

README

postgres/

An implementation of the services in models/ that uses postgres as its backing store.

Documentation

Overview

Package postgres provides a PostgreSQL specific implementation of the services we provide.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

GenerateRandomString returns a securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func Open

func Open(connStr string) (*sql.DB, error)

Open starts the connection to the database.

Types

type AnnouncementService

type AnnouncementService struct {
	DB *sql.DB
}

AnnouncementService is a PostgreSQL implementation of models.announcement

func (*AnnouncementService) Create

func (s *AnnouncementService) Create(message string) (err error)

Create creates an announcement and stores it in the DB

func (*AnnouncementService) DeleteByID

func (s *AnnouncementService) DeleteByID(id int) (err error)

RemoveByID removes the announcement by id Note: removing by latest can cause racing call problems Should always remove by ID

func (*AnnouncementService) GetAllAnnouncements

func (s *AnnouncementService) GetAllAnnouncements() (a []*models.Announcement, err error)

func (*AnnouncementService) GetByID

func (s *AnnouncementService) GetByID(id int) (a *models.Announcement, err error)

GetByID returns an announcement with the given ID.

func (*AnnouncementService) GetCurrent

func (s *AnnouncementService) GetCurrent() (a *models.Announcement, err error)

GetCurrent returns the most recent announcement (by timestamp)

type ApplicationService

type ApplicationService struct {
	DB *sql.DB
}

UserService is a PostgreSQL implementation of models.UserService

func (*ApplicationService) AddPointsToUser

func (s *ApplicationService) AddPointsToUser(uid int, points int) error

add points to user

func (*ApplicationService) CheckIn

func (s *ApplicationService) CheckIn(app *models.Application) (err error)

CheckIn attempts to check-in a user by switching boolean value of check-in from false to true.

func (*ApplicationService) CreateOrUpdate

func (s *ApplicationService) CreateOrUpdate(newApp *models.Application) (err error)

CreateOrUpdate tries to make a new Application, if one already exists then it updates the existing one.

func (*ApplicationService) GetApplicationCount

func (s *ApplicationService) GetApplicationCount() int

returns number of applications in the database

func (*ApplicationService) GetByUserID

func (s *ApplicationService) GetByUserID(uid int) (*models.Application, error)

GetByUserID returns a single Application with the given user id.

type RSVPService

type RSVPService struct {
	DB *sql.DB
}

RSVPService is a PostgreSQL implementation of models.RSVPService

func (*RSVPService) CreateOrUpdate

func (s *RSVPService) CreateOrUpdate(r *models.RSVP) (err error)

CreateOrUpdate tries to make a new RSVP, unless one already exists then it updates the existing one.

func (*RSVPService) GetByUserID

func (s *RSVPService) GetByUserID(uid int) (*models.RSVP, error)

GetByUserID returns a single RSVP with the given user id.

type RaffleService

type RaffleService struct {
	DB *sql.DB
}

RaffleService is a PostgreSQL implementation of models.raffle

func (*RaffleService) ClaimRaffle

func (s *RaffleService) ClaimRaffle(userId int, raffleId string) error

claim a raffle by inserting to raffle_hacker relation

func (*RaffleService) Create

func (s *RaffleService) Create(ra *models.Raffle) error

Create creates a raffle and stores it in the DB

func (*RaffleService) GetById

func (s *RaffleService) GetById(id string) (*models.Raffle, error)

Get raffle by id

type UserService

type UserService struct {
	DB *sql.DB
}

UserService is a PostgreSQL implementation of models.UserService

func (*UserService) GetByCode

func (s *UserService) GetByCode(code string) (u *models.User, err error)

GetByCode returns a single user with the given email confirmation code

func (*UserService) GetByEmail

func (s *UserService) GetByEmail(email string) (u *models.User, err error)

GetByEmail returns a single user with the given email.

func (*UserService) GetByID

func (s *UserService) GetByID(id int) (u *models.User, err error)

GetByID returns a single user with the given id.

func (*UserService) GetPasswordReset

func (s *UserService) GetPasswordReset(email string) (string, error)

Creates the user's token for a password reset

func (*UserService) GetUserCount

func (s *UserService) GetUserCount() int

Get number of users in the database

func (*UserService) Login

func (s *UserService) Login(u *models.User) error

Login checks to see if a passed user's password matches the one recorded in the database. It expects to receive a user object with at least an email and a password. When Login fails it will return an error, otherwise it will return nil.

func (*UserService) ResetPassword

func (s *UserService) ResetPassword(token string, password string) error

ResetPassword resets the user's password

func (*UserService) Signup

func (s *UserService) Signup(u *models.User) (id int, code string, err error)

func (*UserService) TokenChangePassword

func (s *UserService) TokenChangePassword(id int, uid int, password string) error

TokenChangePassword changes password then deletes the token used

func (*UserService) Update

func (s *UserService) Update(u *models.User) error

Update changes the values of a user in the database. It will update all fields in the user model given to it, including nil or zero fields. Don't give it a user with only the changes you want to make.

Jump to

Keyboard shortcuts

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