models

package
v0.0.0-...-da5f288 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ItemTableName  = "items"
	ItemLatestView = "items_with_price"
)

ItemTableName is the name of the item table in the db ItemLatestView is the name of the item + price view

View Source
const (
	SessionTableName = "sessions"
	SessionView      = "current_sessions"
)

SessionTableName is the name of the session table in the db SessionView is the name of the view where only current sessions are shown

View Source
const (
	ItemPriceTableName = "item_prices"
)

ItemPriceTableName is the name of the item's price table in the db

View Source
const (
	SubscriptionTableName = "subscriptions"
)

SubscriptionTableName is the name of the subscription table in the db

View Source
const (
	UserItemTableName = "user_items"
)

UserItemTableName is the name of the user table in the db

View Source
const (
	UserTableName = "users"
)

UserTableName is the name of the user table in the db

Variables

This section is empty.

Functions

func LayerInstance

func LayerInstance() *layer

LayerInstance gets the static singleton reference using double check synchronization. It returns the reference to the layer.

Types

type Item

type Item struct {
	ID          uuid.UUID `valid:"-" json:"id"`
	Name        string    `valid:"required" json:"name"`
	Description string    `valid:"required" json:"description"`
	ImageURL    string    `valid:"required" json:"image_url" db:"image_url"`
	URL         string    `valid:"required" json:"url"`
	Currency    string    `valid:"required" json:"currency"`
}

Item represents a single row in the ItemTable

type ItemPrice

type ItemPrice struct {
	ItemID    uuid.UUID `valid:"-" json:"item_id" db:"item_id"`
	Time      time.Time `valid:"-" json:"time"`
	Price     int64     `valid:"required" json:"price"`
	Available bool      `valid:"required" json:"available"`
}

ItemPrice represents a single row in the ItemPriceTable

type ItemPriceQuery

type ItemPriceQuery struct {
	ID        uuid.UUID
	Time      time.Time
	Price     int64
	Available bool
}

ItemPriceQuery represents all of the rows the item can be queried over

type ItemPriceTable

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

ItemPriceTable represents the connection to the db instance

func (*ItemPriceTable) GetAllPrices

func (table *ItemPriceTable) GetAllPrices(itemID uuid.UUID) (itemPrices []ItemPrice, err error)

GetAllPrices gets all prices for a certain item

func (*ItemPriceTable) GetPrice

func (table *ItemPriceTable) GetPrice(itemID uuid.UUID) (itemPrice ItemPrice, err error)

GetPrice gets the most current price of an item

func (*ItemPriceTable) Insert

func (table *ItemPriceTable) Insert(itemPrice ItemPrice) (returnedItemPrice ItemPrice, err error)

Insert adds a new item into the table.

type ItemQuery

type ItemQuery struct {
	ID   uuid.UUID
	Name string
}

ItemQuery represents all of the rows the item can be queried over

type ItemTable

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

ItemTable represents the connection to the db instance

func (*ItemTable) DeleteByID

func (table *ItemTable) DeleteByID(id uuid.UUID) (err error)

DeleteByID permanently removes the item with uuid from table

func (*ItemTable) GetAll

func (table *ItemTable) GetAll() (items []Item, err error)

GetAll gets all items from the table

func (*ItemTable) GetAllWithPrice

func (table *ItemTable) GetAllWithPrice() (items []ItemWithPrice, err error)

GetAllWithPrice gets all items with price from the table

func (*ItemTable) GetByID

func (table *ItemTable) GetByID(id uuid.UUID) (item Item, err error)

GetByID finds an item by id

func (*ItemTable) GetWithPrice

func (table *ItemTable) GetWithPrice(id uuid.UUID) (item ItemWithPrice, err error)

GetWithPrice finds an item by id with price

func (*ItemTable) Insert

func (table *ItemTable) Insert(item Item) (returnedItem Item, err error)

Insert adds a new item into the table.

func (*ItemTable) Search

func (table *ItemTable) Search(searchQuery string) (items []ItemWithPrice, err error)

Search searches the item's names for an accent insensitive string

func (*ItemTable) Update

func (table *ItemTable) Update(id uuid.UUID, newItem Item) (updated Item, err error)

Update will update the item row with an incoming item

type ItemWithPrice

type ItemWithPrice struct {
	*ItemPrice
	*Item
}

ItemWithPrice represent the join between Item and ItemPrices

type Session

type Session struct {
	ID           uuid.UUID `valid:"required" json:"id"`
	UserID       uuid.UUID `valid:"required" json:"user_id" db:"user_id"`
	ExpiresAfter time.Time `valid:"required" json:"expires_after" db:"expires_after"`
	JWT          string    `valid:"required" json:"jwt"`
}

Session represents a single row in the SessionTable

type SessionQuery

type SessionQuery struct {
	ID     uuid.UUID
	UserID uuid.UUID
}

SessionQuery represents all of the rows the item can be queried over

type SessionTable

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

SessionTable represents the connection to the db instance

func (*SessionTable) DeleteByID

func (table *SessionTable) DeleteByID(id uuid.UUID) (err error)

DeleteByID permanently removes the session with uuid from table

func (*SessionTable) GetSession

func (table *SessionTable) GetSession(sessionID uuid.UUID) (session Session, err error)

GetSession finds a session by id

func (*SessionTable) GetUser

func (table *SessionTable) GetUser(userID uuid.UUID) (session Session, err error)

GetUser returns a single session for user

func (*SessionTable) Insert

func (table *SessionTable) Insert(userID uuid.UUID) (returnedSession Session, err error)

Insert adds a new session into the table and return the new session.

type Subscription

type Subscription struct {
	UserID      uuid.UUID `valid:"required" json:"user_id" db:"user_id"`
	ItemID      uuid.UUID `valid:"required" json:"item_id" db:"json_id"`
	Email       string    `valid:"required" json:"email"`
	TargetPrice int64     `valid:"required" json:"target_price" db:"target_price"`
}

Subscription represents a single row in the UserItemTable

type SubscriptionQuery

type SubscriptionQuery struct {
	UserID uuid.UUID
	ItemID uuid.UUID
}

SubscriptionQuery represents all of the rows the item can be queried over

type SubscriptionTable

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

SubscriptionTable represents the connection to the db instance

func (*SubscriptionTable) Delete

func (table *SubscriptionTable) Delete(userID, itemID uuid.UUID) (err error)

Delete permanently removes the subscription with uuid from table

func (*SubscriptionTable) GetByItem

func (table *SubscriptionTable) GetByItem(itemID uuid.UUID) (subscriptions []Subscription, err error)

GetByItem gets all users who follows an item

func (*SubscriptionTable) GetByUser

func (table *SubscriptionTable) GetByUser(userID uuid.UUID) (subscriptions []Subscription, err error)

GetByUser gets all items followed by user with userID

func (*SubscriptionTable) Insert

func (table *SubscriptionTable) Insert(subscription Subscription) (returnedSubscription Subscription, err error)

Insert adds a new item into the table.

func (*SubscriptionTable) Update

func (table *SubscriptionTable) Update(id uuid.UUID, newSubscription Subscription) (updated Subscription, err error)

Update will update the item row with an incoming item

type User

type User struct {
	ID       uuid.UUID `valid:"-" json:"id"`
	Username string    `valid:"required" json:"username"`
	Email    string    `valid:"required,email" json:"email"`
	Password string    `valid:"required" json:"password"`
	Created  time.Time `valid:"-" json:"created" db:"created"`
	LoggedIn time.Time `valid:"-" json:"logged_in" db:"logged_in"`
}

User represents a single row in the UserTable

type UserItem

type UserItem struct {
	UserID uuid.UUID `valid:"-" json:"user_id" db:"user_id"`
	ItemID uuid.UUID `valid:"-" json:"item_id" db:"item_id"`
}

UserItem represents a single row in the UserItemTable

type UserItemQuery

type UserItemQuery struct {
	UserID uuid.UUID
	ItemID uuid.UUID
}

UserItemQuery represents all of the rows the item can be queried over

type UserItemTable

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

UserItemTable represents the connection to the db instance

func (*UserItemTable) DeleteByID

func (table *UserItemTable) DeleteByID(id uuid.UUID) (err error)

DeleteByID permanently removes the item with uuid from table

func (*UserItemTable) GetByUser

func (table *UserItemTable) GetByUser(userID uuid.UUID) (items []ItemWithPrice, err error)

GetByUser gets all items followed by user with userID

func (*UserItemTable) GetByUserItem

func (table *UserItemTable) GetByUserItem(userID uuid.UUID, itemID uuid.UUID) (returnedUserItem UserItem, err error)

GetByUserItem gets an UserItem by both UserID and ItemID

func (*UserItemTable) Insert

func (table *UserItemTable) Insert(userItem UserItem) (returnedUserItem UserItem, err error)

Insert adds a new item into the table.

func (*UserItemTable) Update

func (table *UserItemTable) Update(id uuid.UUID, newUserItem UserItem) (updated UserItem, err error)

Update will update the item row with an incoming item

type UserTable

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

UserTable represents the connection to the db instance

func (*UserTable) DeleteByID

func (table *UserTable) DeleteByID(id uuid.UUID) (err error)

DeleteByID permanently removes the user with uuid from table

func (*UserTable) GetByEmail

func (table *UserTable) GetByEmail(email string) (user User, err error)

GetByEmail gets an user by email

func (*UserTable) GetByID

func (table *UserTable) GetByID(id uuid.UUID) (user User, err error)

GetByID finds a user with id

func (*UserTable) Insert

func (table *UserTable) Insert(user User) (returnedUser User, err error)

Insert adds a new user into the table.

func (*UserTable) Login

func (table *UserTable) Login(user User) (found User, err error)

Login accepts a user object and checks that the user's email is in the database and that the passwords match

func (*UserTable) Update

func (table *UserTable) Update(id uuid.UUID, newUser User) (updated User, err error)

Update will update the user row with an incoming user

Jump to

Keyboard shortcuts

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