models

package
v0.0.0-...-5d6c776 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeAuthentication = "authentication"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Customer

type Customer struct {
	ID        int       `json:"id"`
	FirstName string    `json:"first_name"`
	LastName  string    `json:"last_name"`
	Email     string    `json:"email"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

Customer is the type for customers

type DBModel

type DBModel struct {
	DB *sql.DB
}

DBModel is the type for database connection values

func (*DBModel) AddUser

func (m *DBModel) AddUser(u User, hash string) error

AddUser inserts a user into the database

func (*DBModel) Authenticate

func (m *DBModel) Authenticate(email, password string) (int, error)

Authenticate attempts to log a user in by comparing supplied password with password hash

func (*DBModel) DeleteUser

func (m *DBModel) DeleteUser(id int) error

DeleteUser deletes a user by id

func (*DBModel) EditUser

func (m *DBModel) EditUser(u User) error

EditUser edits an existing user

func (*DBModel) GetAllOrders

func (m *DBModel) GetAllOrders() ([]*Order, error)

GetAllOrders returns a slice of all orders

func (*DBModel) GetAllOrdersPaginated

func (m *DBModel) GetAllOrdersPaginated(pageSize, page int) ([]*Order, int, int, error)

GetAllOrdersPaginated returns a slice of a subset of orders

func (*DBModel) GetAllSubscriptions

func (m *DBModel) GetAllSubscriptions() ([]*Order, error)

GetAllSubscriptions returns a slice of all subscriptions

func (*DBModel) GetAllSubscriptionsPaginated

func (m *DBModel) GetAllSubscriptionsPaginated(pageSize, page int) ([]*Order, int, int, error)

GetAllSubscriptionsPaginated returns a slice of a subset of subscriptions

func (*DBModel) GetAllUsers

func (m *DBModel) GetAllUsers() ([]*User, error)

GetAllUsers returns a slice of all users

func (*DBModel) GetOneUser

func (m *DBModel) GetOneUser(id int) (User, error)

GetOneUser returns one user by id

func (*DBModel) GetOrderByID

func (m *DBModel) GetOrderByID(id int) (Order, error)

GetOrderByID gets one order by id and returns the Order

func (*DBModel) GetUserByEmail

func (m *DBModel) GetUserByEmail(email string) (User, error)

GetUserByEmail gets a user by email address

func (*DBModel) GetUserForToken

func (m *DBModel) GetUserForToken(token string) (*User, error)

func (*DBModel) GetWidget

func (m *DBModel) GetWidget(id int) (Widget, error)

GetWidget gets one widget by id

func (*DBModel) InsertCustomer

func (m *DBModel) InsertCustomer(c Customer) (int, error)

InsertOrder inserts a new order, and returns its id

func (*DBModel) InsertOrder

func (m *DBModel) InsertOrder(order Order) (int, error)

InsertOrder inserts a new order, and returns its id

func (*DBModel) InsertToken

func (m *DBModel) InsertToken(t *Token, u User) error

func (*DBModel) InsertTransaction

func (m *DBModel) InsertTransaction(txn Transaction) (int, error)

InsertTransaction inserts a new txn, and returns its id

func (*DBModel) UpdateOrderStatus

func (m *DBModel) UpdateOrderStatus(id, statusID int) error

UpdateOrderStatus updates the status of order to supplied statusID by id

func (*DBModel) UpdatePasswordForUser

func (m *DBModel) UpdatePasswordForUser(u User, hash string) error

UpdatePasswordForUser updates the password hash for a given user, by user id

type Models

type Models struct {
	DB DBModel
}

Models is the wrapper for all models

func NewModels

func NewModels(db *sql.DB) Models

NewModels returns a model type with database connection pool

type Order

type Order struct {
	ID            int         `json:"id"`
	WidgetID      int         `json:"widget_id"`
	TransactionID int         `json:"transaction_id"`
	CustomerID    int         `json:"customer_id"`
	StatusID      int         `json:"status_id"`
	Quantity      int         `json:"quantity"`
	Amount        int         `json:"amount"`
	CreatedAt     time.Time   `json:"-"`
	UpdatedAt     time.Time   `json:"-"`
	Widget        Widget      `json:"widget"`
	Transaction   Transaction `json:"transaction"`
	Customer      Customer    `json:"customer"`
}

Order is the type for all orders

type Status

type Status struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

Status is the type for order statuses

type Token

type Token struct {
	PlainText string    `json:"token"`
	UserID    int64     `json:"-"`
	Hash      []byte    `json:"-"`
	Expiry    time.Time `json:"expiry"`
	Scope     string    `json:"-"`
}

Token is the type for authentication tokens

func GenerateToken

func GenerateToken(userID int, ttl time.Duration, scope string) (*Token, error)

GenerateToken generates a token that lasts for ttl, and returns it

type Transaction

type Transaction struct {
	ID                  int       `json:"id"`
	Amount              int       `json:"amount"`
	Currency            string    `json:"currency"`
	LastFour            string    `json:"last_four"`
	ExpiryMonth         int       `json:"expiry_month"`
	ExpiryYear          int       `json:"expiry_year"`
	PaymentIntent       string    `json:"payment_intent"`
	PaymentMethod       string    `json:"payment_method"`
	BankReturnCode      string    `json:"bank_return_code"`
	TransactionStatusID int       `json:"transaction_status_id"`
	CreatedAt           time.Time `json:"-"`
	UpdatedAt           time.Time `json:"-"`
}

Transaction is the type for transactions

type TransactionStatus

type TransactionStatus struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

TransactionStatus is the type for transaction statuses

type User

type User struct {
	ID        int       `json:"id"`
	FirstName string    `json:"first_name"`
	LastName  string    `json:"last_name"`
	Email     string    `json:"email"`
	Password  string    `json:"password"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

User is the type for users

type Widget

type Widget struct {
	ID             int       `json:"id"`
	Name           string    `json:"name"`
	Description    string    `json:"description"`
	InventoryLevel int       `json:"inventory_level"`
	Price          int       `json:"price"`
	Image          string    `json:"image"`
	IsRecurring    bool      `json:"is_recurring"`
	PlanID         string    `json:"plan_id"`
	CreatedAt      time.Time `json:"-"`
	UpdatedAt      time.Time `json:"-"`
}

Widget is the type for all widgets

Jump to

Keyboard shortcuts

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