db

package
v0.0.0-...-3f76a01 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeActivation     = "activation"
	ScopeAuthentication = "authentication"
	ScopePasswordReset  = "password-reset"
)

Variables

View Source
var (
	DuplicatePhone = `pq: duplicate key value violates unique constraint "admin_phone_key"`
)

Functions

func IsValidTokenPlaintext

func IsValidTokenPlaintext(tokenPlaintext string) (bool, error)

func PasswordMatches

func PasswordMatches(pwd Password) (bool, error)

func ReadUUIDParam

func ReadUUIDParam(c echo.Context) (uuid.UUID, error)

Types

type Admin

type Admin struct {
	ID           uuid.UUID `json:"id"`
	CreatedAt    time.Time `json:"created_at"`
	Phone        string    `json:"phone"`
	PasswordHash []byte    `json:"password_hash"`
	Activated    bool      `json:"activated"`
	Version      uuid.UUID `json:"version"`
}

type CreateAdminParams

type CreateAdminParams struct {
	Phone        string `json:"phone"`
	PasswordHash []byte `json:"password_hash"`
	Activated    bool   `json:"activated"`
}

type CreateAdminRow

type CreateAdminRow struct {
	ID        uuid.UUID `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	Version   uuid.UUID `json:"version"`
}

type CreateHouseParams

type CreateHouseParams struct {
	Location  string `json:"location"`
	Block     string `json:"block"`
	Partition int16  `json:"partition"`
	Occupied  bool   `json:"occupied"`
}

type CreatePaymentParams

type CreatePaymentParams struct {
	TenantID  uuid.UUID `json:"tenant_id"`
	Amount    int32     `json:"amount"`
	StartDate time.Time `json:"start_date"`
	EndDate   time.Time `json:"end_date"`
	CreatedBy uuid.UUID `json:"created_by"`
}

type CreateTenantParams

type CreateTenantParams struct {
	FirstName      string    `json:"first_name"`
	LastName       string    `json:"last_name"`
	HouseID        uuid.UUID `json:"house_id"`
	Phone          string    `json:"phone"`
	PersonalIDType string    `json:"personal_id_type"`
	PersonalID     string    `json:"personal_id"`
	Active         bool      `json:"active"`
	Sos            time.Time `json:"sos"`
}

type CreateTokenParams

type CreateTokenParams struct {
	Hash   []byte    `json:"hash"`
	ID     uuid.UUID `json:"id"`
	Expiry time.Time `json:"expiry"`
	Scope  string    `json:"scope"`
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type DeleteAllTokenParams

type DeleteAllTokenParams struct {
	Scope string    `json:"scope"`
	ID    uuid.UUID `json:"id"`
}

type GetDetailedPaymentByIdRow

type GetDetailedPaymentByIdRow struct {
	ID         uuid.UUID   `json:"id"`
	TenantName interface{} `json:"tenant_name"`
	TenantID   uuid.UUID   `json:"tenant_id"`
	Amount     int32       `json:"amount"`
	StartDate  time.Time   `json:"start_date"`
	EndDate    time.Time   `json:"end_date"`
	AdminPhone string      `json:"admin_phone"`
	Location   string      `json:"location"`
	Block      string      `json:"block"`
	Partition  int16       `json:"partition"`
	CreatedAt  time.Time   `json:"created_at"`
	UpdatedAt  time.Time   `json:"updated_at"`
	Version    uuid.UUID   `json:"version"`
}

type GetHashTokenForAdminParams

type GetHashTokenForAdminParams struct {
	Hash   []byte    `json:"hash"`
	Scope  string    `json:"scope"`
	Expiry time.Time `json:"expiry"`
}

type GetHashTokenForAdminRow

type GetHashTokenForAdminRow struct {
	ID           uuid.UUID `json:"id"`
	CreatedAt    time.Time `json:"created_at"`
	Phone        string    `json:"phone"`
	PasswordHash []byte    `json:"password_hash"`
	Version      uuid.UUID `json:"version"`
	Activated    bool      `json:"activated"`
}

type GetHouseByIdWithTenantRow

type GetHouseByIdWithTenantRow struct {
	ID         uuid.UUID   `json:"id"`
	Location   string      `json:"location"`
	Block      string      `json:"block"`
	Partition  int16       `json:"partition"`
	Occupied   bool        `json:"occupied"`
	TenantName interface{} `json:"tenant_name"`
	TenantID   uuid.UUID   `json:"tenant_id"`
}

type GetHousesRow

type GetHousesRow struct {
	ID        uuid.UUID `json:"id"`
	Location  string    `json:"location"`
	Block     string    `json:"block"`
	Partition int16     `json:"partition"`
	Occupied  bool      `json:"occupied"`
}

type GetTenantByIdWithHouseRow

type GetTenantByIdWithHouseRow struct {
	ID             uuid.UUID `json:"id"`
	FirstName      string    `json:"first_name"`
	LastName       string    `json:"last_name"`
	HouseID        uuid.UUID `json:"house_id"`
	Location       string    `json:"location"`
	Block          string    `json:"block"`
	Partition      int16     `json:"partition"`
	Phone          string    `json:"phone"`
	PersonalIDType string    `json:"personal_id_type"`
	PersonalID     string    `json:"personal_id"`
	Active         bool      `json:"active"`
	Sos            time.Time `json:"sos"`
	Version        uuid.UUID `json:"version"`
}

type GetTenantsRow

type GetTenantsRow struct {
	ID             uuid.UUID `json:"id"`
	FirstName      string    `json:"first_name"`
	LastName       string    `json:"last_name"`
	HouseID        uuid.UUID `json:"house_id"`
	Phone          string    `json:"phone"`
	PersonalIDType string    `json:"personal_id_type"`
	PersonalID     string    `json:"personal_id"`
	Active         bool      `json:"active"`
	Sos            time.Time `json:"sos"`
}

type House

type House struct {
	ID        uuid.UUID `json:"id"`
	Location  string    `json:"location"`
	Block     string    `json:"block"`
	Partition int16     `json:"partition"`
	Occupied  bool      `json:"occupied"`
	Version   uuid.UUID `json:"version"`
}

type HouseBulk

type HouseBulk struct {
	Location  string
	Block     string
	Partition int
	Occupied  bool
}

type Password

type Password struct {
	Plaintext string
	Hash      []byte
}

func SetPassword

func SetPassword(plaintextpassword string) (*Password, error)

type Payment

type Payment struct {
	ID        uuid.UUID `json:"id"`
	TenantID  uuid.UUID `json:"tenant_id"`
	Amount    int32     `json:"amount"`
	StartDate time.Time `json:"start_date"`
	EndDate   time.Time `json:"end_date"`
	Version   uuid.UUID `json:"version"`
	CreatedAt time.Time `json:"created_at"`
	CreatedBy uuid.UUID `json:"created_by"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Querier

type Querier interface {
	CreateAdmin(ctx context.Context, arg CreateAdminParams) (CreateAdminRow, error)
	CreateHouse(ctx context.Context, arg CreateHouseParams) (uuid.UUID, error)
	CreatePayment(ctx context.Context, arg CreatePaymentParams) error
	CreateTenant(ctx context.Context, arg CreateTenantParams) error
	CreateToken(ctx context.Context, arg CreateTokenParams) error
	DeleteAllToken(ctx context.Context, arg DeleteAllTokenParams) error
	DeletePayment(ctx context.Context, id uuid.UUID) error
	GetAdminByPhone(ctx context.Context, phone string) (Admin, error)
	GetAllPayments(ctx context.Context) ([]Payment, error)
	GetDetailedPaymentById(ctx context.Context, id uuid.UUID) (GetDetailedPaymentByIdRow, error)
	GetHashTokenForAdmin(ctx context.Context, arg GetHashTokenForAdminParams) (GetHashTokenForAdminRow, error)
	GetHouseById(ctx context.Context, id uuid.UUID) (House, error)
	GetHouseByIdWithTenant(ctx context.Context, id uuid.UUID) (GetHouseByIdWithTenantRow, error)
	GetHouses(ctx context.Context) ([]GetHousesRow, error)
	GetPaymentById(ctx context.Context, id uuid.UUID) (Payment, error)
	GetTenantById(ctx context.Context, id uuid.UUID) (Tenant, error)
	GetTenantByIdWithHouse(ctx context.Context, id uuid.UUID) (GetTenantByIdWithHouseRow, error)
	GetTenants(ctx context.Context) ([]GetTenantsRow, error)
	UpdateAdmin(ctx context.Context, arg UpdateAdminParams) (uuid.UUID, error)
	UpdateHouseById(ctx context.Context, arg UpdateHouseByIdParams) error
	UpdatePayment(ctx context.Context, arg UpdatePaymentParams) error
	UpdateTenant(ctx context.Context, arg UpdateTenantParams) error
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateAdmin

func (q *Queries) CreateAdmin(ctx context.Context, arg CreateAdminParams) (CreateAdminRow, error)

func (*Queries) CreateHouse

func (q *Queries) CreateHouse(ctx context.Context, arg CreateHouseParams) (uuid.UUID, error)

func (*Queries) CreatePayment

func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) error

func (*Queries) CreateTenant

func (q *Queries) CreateTenant(ctx context.Context, arg CreateTenantParams) error

func (*Queries) CreateToken

func (q *Queries) CreateToken(ctx context.Context, arg CreateTokenParams) error

func (*Queries) DeleteAllToken

func (q *Queries) DeleteAllToken(ctx context.Context, arg DeleteAllTokenParams) error

func (*Queries) DeletePayment

func (q *Queries) DeletePayment(ctx context.Context, id uuid.UUID) error

func (*Queries) GetAdminByPhone

func (q *Queries) GetAdminByPhone(ctx context.Context, phone string) (Admin, error)

func (*Queries) GetAllPayments

func (q *Queries) GetAllPayments(ctx context.Context) ([]Payment, error)

func (*Queries) GetDetailedPaymentById

func (q *Queries) GetDetailedPaymentById(ctx context.Context, id uuid.UUID) (GetDetailedPaymentByIdRow, error)

func (*Queries) GetHashTokenForAdmin

func (q *Queries) GetHashTokenForAdmin(ctx context.Context, arg GetHashTokenForAdminParams) (GetHashTokenForAdminRow, error)

func (*Queries) GetHouseById

func (q *Queries) GetHouseById(ctx context.Context, id uuid.UUID) (House, error)

func (*Queries) GetHouseByIdWithTenant

func (q *Queries) GetHouseByIdWithTenant(ctx context.Context, id uuid.UUID) (GetHouseByIdWithTenantRow, error)

func (*Queries) GetHouses

func (q *Queries) GetHouses(ctx context.Context) ([]GetHousesRow, error)

func (*Queries) GetPaymentById

func (q *Queries) GetPaymentById(ctx context.Context, id uuid.UUID) (Payment, error)

func (*Queries) GetTenantById

func (q *Queries) GetTenantById(ctx context.Context, id uuid.UUID) (Tenant, error)

func (*Queries) GetTenantByIdWithHouse

func (q *Queries) GetTenantByIdWithHouse(ctx context.Context, id uuid.UUID) (GetTenantByIdWithHouseRow, error)

func (*Queries) GetTenants

func (q *Queries) GetTenants(ctx context.Context) ([]GetTenantsRow, error)

func (*Queries) UpdateAdmin

func (q *Queries) UpdateAdmin(ctx context.Context, arg UpdateAdminParams) (uuid.UUID, error)

func (*Queries) UpdateHouseById

func (q *Queries) UpdateHouseById(ctx context.Context, arg UpdateHouseByIdParams) error

func (*Queries) UpdatePayment

func (q *Queries) UpdatePayment(ctx context.Context, arg UpdatePaymentParams) error

func (*Queries) UpdateTenant

func (q *Queries) UpdateTenant(ctx context.Context, arg UpdateTenantParams) error

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type SQLStore

type SQLStore struct {
	*Queries
	// contains filtered or unexported fields
}

func (*SQLStore) BulkInsert

func (s *SQLStore) BulkInsert(ctx context.Context, houses []HouseBulk) error

func (*SQLStore) NewToken

func (s *SQLStore) NewToken(id uuid.UUID, ttl time.Duration, scope string) (*TokenLoc, error)

func (*SQLStore) TxnCreateTenant

func (store *SQLStore) TxnCreateTenant(ctx context.Context, args CreateTenantParams) error

func (*SQLStore) TxnRemoveTenantHouse

func (store *SQLStore) TxnRemoveTenantHouse(ctx context.Context, args UpdateTenantParams) error

func (*SQLStore) TxnUpdateTenantHouse

func (store *SQLStore) TxnUpdateTenantHouse(ctx context.Context, args UpdateTenantParams, prev_house_id uuid.UUID) error

type Store

type Store interface {
	Querier
	NewToken(id uuid.UUID, ttl time.Duration, scope string) (*TokenLoc, error)
	BulkInsert(ctx context.Context, houses []HouseBulk) error
	TxnCreateTenant(ctx context.Context, args CreateTenantParams) error
	TxnUpdateTenantHouse(ctx context.Context, args UpdateTenantParams, prev_house_id uuid.UUID) error
	TxnRemoveTenantHouse(ctx context.Context, args UpdateTenantParams) error
}

func NewStore

func NewStore(db *sql.DB) Store

NewStore creates a new store

type Tenant

type Tenant struct {
	ID             uuid.UUID    `json:"id"`
	FirstName      string       `json:"first_name"`
	LastName       string       `json:"last_name"`
	Phone          string       `json:"phone"`
	HouseID        uuid.UUID    `json:"house_id"`
	PersonalIDType string       `json:"personal_id_type"`
	PersonalID     string       `json:"personal_id"`
	Photo          string       `json:"photo"`
	Active         bool         `json:"active"`
	Sos            time.Time    `json:"sos"`
	Eos            sql.NullTime `json:"eos"`
	Version        uuid.UUID    `json:"version"`
}

type Token

type Token struct {
	Hash   []byte    `json:"hash"`
	ID     uuid.UUID `json:"id"`
	Expiry time.Time `json:"expiry"`
	Scope  string    `json:"scope"`
}

type TokenLoc

type TokenLoc struct {
	Plaintext string    `json:"token"`
	Hash      []byte    `json:"-"`
	AdminID   uuid.UUID `json:"-"`
	Expiry    time.Time `json:"expiry"`
	Scope     string    `json:"-"`
}

type UpdateAdminParams

type UpdateAdminParams struct {
	Phone        string    `json:"phone"`
	PasswordHash []byte    `json:"password_hash"`
	Activated    bool      `json:"activated"`
	ID           uuid.UUID `json:"id"`
	Version      uuid.UUID `json:"version"`
}

type UpdateHouseByIdParams

type UpdateHouseByIdParams struct {
	Location  string    `json:"location"`
	Block     string    `json:"block"`
	Partition int16     `json:"partition"`
	Occupied  bool      `json:"occupied"`
	ID        uuid.UUID `json:"id"`
	Version   uuid.UUID `json:"version"`
}

type UpdatePaymentParams

type UpdatePaymentParams struct {
	Amount    int32     `json:"amount"`
	StartDate time.Time `json:"start_date"`
	EndDate   time.Time `json:"end_date"`
	ID        uuid.UUID `json:"id"`
	Version   uuid.UUID `json:"version"`
}

type UpdateTenantParams

type UpdateTenantParams struct {
	FirstName      string       `json:"first_name"`
	LastName       string       `json:"last_name"`
	HouseID        uuid.UUID    `json:"house_id"`
	Phone          string       `json:"phone"`
	PersonalIDType string       `json:"personal_id_type"`
	PersonalID     string       `json:"personal_id"`
	Active         bool         `json:"active"`
	Sos            time.Time    `json:"sos"`
	Eos            sql.NullTime `json:"eos"`
	ID             uuid.UUID    `json:"id"`
	Version        uuid.UUID    `json:"version"`
}

Jump to

Keyboard shortcuts

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