models

package
v0.0.0-...-691f0da Latest Latest
Warning

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

Go to latest
Published: May 14, 2023 License: GPL-3.0 Imports: 11 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 {
	DBEntity
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
}

Customer is a type for customers

type DBEntity

type DBEntity struct {
	ID        int       `model-copy:"ignore" json:"id" gorm:"primaryKey"`
	CreatedAt time.Time `model-copy:"ignore" json:"-"`
	UpdatedAt time.Time `model-copy:"ignore" json:"-"`
}

func (DBEntity) GetID

func (e DBEntity) GetID() int

func (*DBEntity) SetCreated

func (e *DBEntity) SetCreated()

func (*DBEntity) SetUpdated

func (e *DBEntity) SetUpdated()

type DBModel

type DBModel struct {
	DB *gorm.DB
}

DBModel is the type for database connection values

func (*DBModel) Authenticate

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

func (*DBModel) DeleteUser

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

DeleteUser removes user from DB

func (*DBModel) GetAllOrders

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

func (*DBModel) GetAllSubscriptions

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

func (*DBModel) GetAllUsers

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

GetAllUsers fetches list of users from the DB ordered by LastName and FirstName

func (*DBModel) GetCustomer

func (m *DBModel) GetCustomer(id int) (Customer, error)

GetCustomer fetches Customer from DB by id

func (*DBModel) GetOrder

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

GetOrder fetches Order entity from DB by id

func (*DBModel) GetTransaction

func (m *DBModel) GetTransaction(id int) (Transaction, error)

GetTransaction fetches Transaction from DB by id

func (*DBModel) GetTransactionByPI

func (m *DBModel) GetTransactionByPI(pi string) (Transaction, error)

GetTransactionByPI fetches Transaction from DB by Payment Intent ID

func (*DBModel) GetUserByEmail

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

GetUserByEmail gets a user by email address

func (*DBModel) GetUserByID

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

GetUserByID fetches one user from DB by id

func (*DBModel) GetUserForToken

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

func (*DBModel) GetWidget

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

GetWidget fetches Widget entity from DB by id

func (*DBModel) InsertCustomer

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

InsertCustomer inserts new order and returns it's id

func (*DBModel) InsertOrder

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

InsertOrder inserts new order and returns it's id

func (*DBModel) InsertToken

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

func (*DBModel) InsertTransaction

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

InsertTransaction inserts new transaction and returns it's id

func (*DBModel) InsertUser

func (m *DBModel) InsertUser(u User) (int, error)

InsertUser adds a new user to DB

func (*DBModel) UpdateOrderStatus

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

func (*DBModel) UpdatePasswordForUser

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

func (*DBModel) UpdateUser

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

UpdateUser updates user's record in DB

type IDBEntity

type IDBEntity interface {
	GetID() int
	SetCreated()
	SetUpdated()
}

type Models

type Models struct {
	DB DBModel
}

Models is the wrapper for all models

func NewModels

func NewModels(db *gorm.DB) Models

NewModels returns a model type with database connection pool

type Order

type Order struct {
	DBEntity
	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"`
	Widget        Widget      `json:"widget"`
	Transaction   Transaction `json:"transaction"`
	Customer      Customer    `json:"customer"`
}

Order is the type for all orders

type SToken

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

SToken is a type for authentication tokens

func GenerateToken

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

GenerateToken generates token for user identified by userID that lasts for ttl and returns it or possibly an error

type Status

type Status struct {
	DBEntity
	Name int `json:"name"`
}

Status is a type for order statuses

type Token

type Token struct {
	DBEntity
	UserID    int
	Name      string
	Email     string
	Expiry    time.Time
	TokenHash []byte
}

Token is a type for saving tokens (SToken) to DB

type Transaction

type Transaction struct {
	DBEntity
	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"`
}

Transactionis a type for transactions

type TransactionStatus

type TransactionStatus struct {
	DBEntity
	Name int `json:"name"`
}

TransactionStatus is a type for transaction statuses

type User

type User struct {
	DBEntity
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Password  string `model-copy:"ignore" json:"password"`
}

User is a type for users

type VTTransactionData

type VTTransactionData struct {
	PaymentAmount   int    `json:"amount"`
	PaymentCurrency string `json:"currency"`
	FirstName       string `json:"first_name"`
	LastName        string `json:"last_name"`
	Email           string `json:"email"`
	PaymentIntent   string `json:"payment_intent"`
	PaymentMethod   string `json:"payment_method"`
	BankReturnCode  string `json:"bank_return_code"`
	ExpiryMonth     int    `json:"expiry_month"`
	ExpiryYear      int    `json:"expiry_year"`
	LastFour        string `json:"last_four"`
}

type Widget

type Widget struct {
	DBEntity
	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"`
}

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