handlers

package
v0.0.0-...-1122a87 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package classification of STLKER API

Documentation for STLKER API

Schemes: http BasePath: / Version: 1.0.0

Consumes: - application/json

Produces: - application/json swagger:meta

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)

CompanyOverview 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

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 a 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 *slog.Logger, wc pb.WatcherClient, rOptions *redis.Ring,
	portRepo r.IPortfolioRepository, secRepo r.ISecurityRepository, userRepo r.IUserRepository) *ControlHandler

NewControlHandler constructs a new ControlHandler struct

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)

swagger:route POST /portfolios portfolios createPortfolio Creates a new portfolio for a user responses:

200: messageResponse
400: errorResponse
500: errorResponse

func (*ControlHandler) CreateSecurity

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

swagger:route POST /portfolios/{name} securities createSecurity Creates a new security responses:

200: messageResponse
400: errorResponse
500: errorResponse

func (*ControlHandler) DeletePortfolio

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

swagger:route DELETE /portfolios/{name} portfolios deletePortfolio Deletes a given portfolio for a user responses:

200: messageResponse
400: errorResponse
500: errorResponse

func (*ControlHandler) DeleteSecurity

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

swagger:route DELETE /portfolios/{name}/{ticker} securities deleteSecurity Deletes a security from a given portfolio responses:

200: messageResponse
400: errorResponse
500: errorResponse

func (*ControlHandler) DeleteUser

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

DeleteUser deletes the user from

func (*ControlHandler) GetAll

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

swagger:route GET /portfolios portfolios getPortfolios Outputs all of the portfolios for a user responses:

200: profitsResponse
400: errorResponse
500: errorResponse

func (*ControlHandler) GetInfo

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

swagger:route GET /stocks/{ticker}/{currency} stocks getInfo Outputs a stock's financial details to the client in the requested currency responses:

200: stockResponse
400: errorResponse
500: errorResponse

func (*ControlHandler) GetPortfolio

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

swagger:route GET /portfolios/{name} portfolios getPortfolio Outputs a particular portfolio for a user responses:

200: profitResponse
400: errorResponse
500: errorResponse

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)

swagger:route GET /stocks/more/{ticker} stocks moreInfo Outputs more sophisticated stock information responses:

200: moreStockResponse
400: errorResponse
500: errorResponse

func (*ControlHandler) ReadSecurity

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

swagger:route GET /portfolios/{name}/{ticker} securities readSecurity Outputs a security's details to the client responses:

200: securityResponse
400: errorResponse
500: errorResponse

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)

swagger:route PUT /portfolios portfolios updatePortfolio Updates a given portfolio responses:

200: messageResponse
400: errorResponse
500: errorResponse

func (*ControlHandler) UpdateSecurity

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

swagger:route PUT /portfolios/{name} securities updateSecurity Updates a security's information for a given portfolio responses:

200: messageResponse
400: errorResponse
500: errorResponse

type IsAdmin

type IsAdmin struct{}

type NamePair

type NamePair struct {
	Name     string
	Username string
}

type ReqPortfolio

type ReqPortfolio struct {
	// A single portfolio
	// in: body
	Body m.Portfolio
}

swagger:parameters createPortfolio updatePortfolio

type ReqSecurity

type ReqSecurity struct {
	// ticker of the security
	//
	// required: true
	// example: AAPL
	Ticker string `json:"Ticker"`
	// number of shares of the security
	//
	// required: true
	// example: 5.32
	Shares float64 `json:"Shares"`
}

swagger:model

type ReqSecurityWrapper

type ReqSecurityWrapper struct {
	// A single portfolio
	// in: body
	Body ReqSecurity
}

swagger:parameters createSecurity updateSecurity

type ResponseMessage

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

type Username

type Username struct{}

Jump to

Keyboard shortcuts

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