postgres

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthService

type AuthService struct {
	// contains filtered or unexported fields
}

AuthService is a service for managing authentication.

func NewAuthService

func NewAuthService(db *DB) *AuthService

NewAuthService creates a new AuthService.

func (*AuthService) Auhenticate

func (a *AuthService) Auhenticate(ctx context.Context, opts *entity.AuthUserOptions) (*entity.Auth, error)

Auhenticate not implemented.

func (*AuthService) CreateAuth

func (s *AuthService) CreateAuth(ctx context.Context, auth *entity.Auth) error

CreateAuth creates a new auth. If is attached to a user, links the auth to the user, otherwise creates a new user. On success, the auth.ID is set.

func (*AuthService) DeleteAuth

func (s *AuthService) DeleteAuth(ctx context.Context, id int64) error

DeleteAuth deletes an auth. Do not delete underlying user.

func (*AuthService) FindAuthByID

func (s *AuthService) FindAuthByID(ctx context.Context, id int64) (*entity.Auth, error)

FindAuthByID returns a single auth by its id. Returns ENOTFOUND if the auth does not exist.

func (*AuthService) FindAuths

func (s *AuthService) FindAuths(ctx context.Context, filter service.AuthFilter) (entity.Auths, int, error)

FindAuths returns a list of auths. Predicate can be used to filter the results. Also returns the total count of auths.

type ContractService

type ContractService struct {
	// contains filtered or unexported fields
}

ContractService is the postgres implementation of the contract service.

func NewContractService

func NewContractService(db *DB) *ContractService

NewContractService creates a new contract service.

func (*ContractService) CreateContract

func (cs *ContractService) CreateContract(ctx context.Context, contract *entity.Contract) error

CreateContract creates a new contract. Return EINVALID if the contract is invalid. Return EEXISTS if the contract already exists. Return EFORBIDDEN if the user is not allowed to create a contract. Return EUNAUTHORIZED if the contract owner is not the authenticated user or user is not authenticated.

func (*ContractService) DeleteContract

func (cs *ContractService) DeleteContract(ctx context.Context, id int64) error

DeleteContract deletes the contract with the given id. Return EUNAUTHORIZED if the contract is not the same as the authenticated user. Return ENOTFOUND if the contract does not exist. This service also deletes the revisions of the contract.

func (*ContractService) FindContractByID

func (cs *ContractService) FindContractByID(ctx context.Context, id int64) (*entity.Contract, error)

FindContractByID returns the contract with the given id. Return ENOTFOUND if the contract does not exist.

func (*ContractService) FindContracts

func (cs *ContractService) FindContracts(ctx context.Context, filter service.ContractFilter) (entity.Contracts, int, error)

FindContracts returns a list of contracts filtered by the given options. Also returns the total count of contracts.

func (*ContractService) FindRevisionByContractAndRev

func (cs *ContractService) FindRevisionByContractAndRev(ctx context.Context, contractID int64, rev entity.RevisionNumber) (*entity.Revision, error)

FindRevisionByContractAndRev returns the revision searched by the given contract and revision number. if rev passed is eq 0, it returns the latest revision. Return ENOTFOUND if the revision does not exist.

func (*ContractService) MakeRevision

func (cs *ContractService) MakeRevision(ctx context.Context, revision *entity.Revision) error

MakeRevision creates a new revision of the contract. Return ENOTFOUND if the contract does not exist. Return EINVALID if the revision is invalid. It shouldn't return ECONFLICT because there's a UNIQUE constraint on the revision number and the Contract ID.

func (*ContractService) UpdateContract

func (cs *ContractService) UpdateContract(ctx context.Context, id int64, upd service.ContractUpdate) (*entity.Contract, error)

UpdateContract updates the given contract. Return ENOTFOUND if the contract does not exist. Return EUNAUTHORIZED if the contract is not owned by the authenticated user.

type DB

type DB struct {
	DSN string

	Now func() time.Time
	// contains filtered or unexported fields
}

DB represents the database connection.

func NewDB

func NewDB(dsn string) *DB

NewDB returns a new instance of DB with the given DSN.

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTx starts a transaction and returns a wrapper Tx type. This type provides a reference to the database and a fixed timestamp at the start of the transaction. The timestamp allows us to mock time during tests as well.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) MustOpen

func (db *DB) MustOpen()

MustOpen opens the database and panics on error.

func (*DB) Open

func (db *DB) Open() error

Open database connection

type StateService added in v0.0.7

type StateService struct {

	// CacheStateSearchService is the cache for searching states.
	// It is used to avoid querying the database when the state is already in the cache.
	// Can be nil if the cache is not enabled.
	CacheStateSearchService service.StateSearchService

	// LockService is the service for locking the state during I/O operations.
	CreateLockService func(ctx context.Context, revisionID int64) (service.LockService, error)
	// contains filtered or unexported fields
}

StateService is the implementation of service.StateService for PostgreSQL.

func NewStateService added in v0.0.7

func NewStateService(db *DB) *StateService

NewStateService creates a new StateService.

func (*StateService) CreateState added in v0.0.7

func (s *StateService) CreateState(ctx context.Context, state *entity.State) error

CreateState creates a new state.

func (*StateService) FindStateByRevisionID added in v0.0.7

func (s *StateService) FindStateByRevisionID(ctx context.Context, revisionID int64) (*entity.State, error)

FindStateByRevisionID finds the state by revision ID and the authenticated user retrieved from the context. If cache is enabled, it tries to find the state in the cache first.

func (*StateService) UpdateState added in v0.0.7

func (s *StateService) UpdateState(ctx context.Context, revisionID int64, value entity.StateValue) (*entity.State, error)

UpdateState updates the state.

type Tx

type Tx struct {
	*sqlx.Tx
	// contains filtered or unexported fields
}

Tx wraps the SQL Tx object to provide a timestamp at the start of the transaction.

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

UserService represents a service for managing users.

func NewUserService

func NewUserService(db *DB) *UserService

NewUserService creates a new user service.

func (*UserService) CreateUser

func (s *UserService) CreateUser(ctx context.Context, user *entity.User) error

CreateUser creates a new user.

func (*UserService) DeleteUser

func (s *UserService) DeleteUser(ctx context.Context, id int64) error

DeleteUser deletes the user with the given id. Return EUNAUTHORIZED if the user is not the same as the authenticated user. Return ENOTFOUND if the user does not exist.

func (*UserService) FindUserByEmail

func (s *UserService) FindUserByEmail(ctx context.Context, email string) (*entity.User, error)

FindUserByEmail returns the user with the given email. Return ENOTFOUND if the user does not exist.

func (*UserService) FindUserByID

func (s *UserService) FindUserByID(ctx context.Context, id int64) (*entity.User, error)

FindUserByID returns the user with the given id. Return ENOTFOUND if the user does not exist.

func (*UserService) FindUsers

func (s *UserService) FindUsers(ctx context.Context, filter service.UserFilter) (entity.Users, int, error)

FindUsers retrieves a list of users by filter. Also returns total count of matching users which may differ from returned results if filter.Limit is specified.

func (*UserService) UpdateUser

func (u *UserService) UpdateUser(ctx context.Context, id int64, upd service.UserUpdate) (*entity.User, error)

UpdateUser updates the given user. Return EUNAUTHORIZED if the user is not the same as the authenticated user. Return ENOTFOUND if the user does not exist.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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