handlers

package
v0.0.0-...-070c868 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(next http.Handler) http.Handler

func CompanyOverview

func CompanyOverview(ticker string, client pb.WatcherClient) (*data.MoreStock, error)

MoreInfo returns a pointer to a MoreStock struct and an error if one arises

func Info

func Info(ticker, destination string, client pb.WatcherClient) (*data.Stock, error)

Info returns a pointer to a Stock struct and an error if one arises

func ReadEnvVar

func ReadEnvVar(key string) (string, error)

ReadEnvVar reads an environmental variable specified by key after loading vars.env

Types

type Claims

type Claims struct {
	Name  string `json:"Name"`
	Admin bool   `json:"Admin"`
	jwt.StandardClaims
}

func ValidateJWT

func ValidateJWT(r *http.Request, tokenName string) (int, *Claims)

ValidateJWT checks if the JWT token in the request token is valid and returns an http status code depending on if it is along with a pointer to a claim struct

type ControlHandler

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

ControlHandler is a http.Handler

func NewControlHandler

func NewControlHandler(log *log.Logger, wc pb.WatcherClient, rOptions *redis.Ring) *ControlHandler

NewControlHandler is a constructor

func (*ControlHandler) Cache

func (c *ControlHandler) Cache(next http.Handler) http.Handler

Cache is a middleware that checks if a user cached their portfolio's profits in the past 15 minutes

func (*ControlHandler) CreatePortfolio

func (c *ControlHandler) CreatePortfolio(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) CreateSecurity

func (c *ControlHandler) CreateSecurity(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) DeletePortfolio

func (c *ControlHandler) DeletePortfolio(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) DeleteSecurity

func (c *ControlHandler) DeleteSecurity(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) GetAll

func (c *ControlHandler) GetAll(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) GetInfo

func (c *ControlHandler) GetInfo(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) GetPortfolio

func (c *ControlHandler) GetPortfolio(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) LogIn

func (c *ControlHandler) LogIn(w http.ResponseWriter, r *http.Request)

LogIn handles requests to /login and creates JWTs for valid users

func (*ControlHandler) LogOut

func (c *ControlHandler) LogOut(w http.ResponseWriter, r *http.Request)

LogOut deletes the token cookie

func (*ControlHandler) Logger

func (c *ControlHandler) Logger(next http.Handler) http.Handler

func (*ControlHandler) MoreInfo

func (c *ControlHandler) MoreInfo(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) ReadSecurity

func (c *ControlHandler) ReadSecurity(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) Refresh

func (c *ControlHandler) Refresh(w http.ResponseWriter, r *http.Request)

Refresh handles requests to /refresh and regenerates tokens if the current token is within a minute of expiry

func (*ControlHandler) SignUp

func (c *ControlHandler) SignUp(w http.ResponseWriter, r *http.Request)

SignUp handles requests to /signup and adds new users to the db

func (*ControlHandler) UpdatePortfolio

func (c *ControlHandler) UpdatePortfolio(w http.ResponseWriter, r *http.Request)

func (*ControlHandler) UpdateSecurity

func (c *ControlHandler) UpdateSecurity(w http.ResponseWriter, r *http.Request)

type IsAdmin

type IsAdmin struct{}

type NamePair

type NamePair struct {
	Name     string
	Username string
}

type Portfolio

type Portfolio struct {
	STLKERModel
	// Name is the name of the portfolio
	Name     string `json:"Name"`
	Username string `json:"Username"`
	// Stocks is a slice of Security structs
	Securities []*Security `json:"Securities" gorm:"foreignKey:PortfolioID"`
}

A Portfolio is a GORM model that is intended to mirror the structure of a simple portfolio

type Profits

type Profits struct {
	Name          string      `json:"Portfolio Name"`
	OriginalValue float64     `json:"Original Value"`
	NewValue      float64     `json:"Current Value"`
	NetGain       float64     `json:"Net Gain"`
	NetChange     string      `json:"Net Change"`
	Moves         []*Security `json:"Securities"`
}

type ResponseMessage

type ResponseMessage struct {
	Msg string `json:"Message"`
}

type STLKERModel

type STLKERModel struct {
	ID        uint         `gorm:"primaryKey" json:"-"`
	CreatedAt time.Time    `json:"-"`
	UpdatedAt time.Time    `json:"-"`
	DeletedAt sql.NullTime `json:"-" gorm:"index"`
}

type Security

type Security struct {
	STLKERModel
	SecurityID  int     `gorm:"primary_key" json:"-"`
	Ticker      string  `json:"Ticker"`
	BoughtPrice float64 `json:"Bought Price"`
	CurrPrice   float64 `json:"Current Price"`
	Shares      float64 `json:"Shares"`
	Gain        float64 `json:"Gain"`
	Change      string  `json:"Percent Change"`
	// Currency is the destination currency of the stock
	Currency string `json:"Currency" gorm:"default:USD"`
	// Foreign key
	PortfolioID uint `json:"-"`
}

type User

type User struct {
	gorm.Model
	Username string `json:"Username"`
	Password string `json:"Password"`
}

type Username

type Username struct{}

Jump to

Keyboard shortcuts

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