Documentation ¶
Index ¶
- Constants
- func CreateSesh(dbParams string, dbName string) (*mgo.Session, error)
- func DB(dbParams string, dbName string) martini.Handler
- type Base
- type Group
- type GroupRepo
- type Groups
- type Investment
- type InvestmentRepo
- func (r *InvestmentRepo) CreateOne(toCreate Investment) (Investment, error)
- func (r *InvestmentRepo) DeleteOne(id string) error
- func (r *InvestmentRepo) FindMultiple(params map[string]interface{}) (Investments, error)
- func (r *InvestmentRepo) FindOne(id string) (Investment, error)
- func (r *InvestmentRepo) FindOneBySymbol(symbol string) (Investment, error)
- func (r *InvestmentRepo) UpdateOne(id string, toUpdate Investment) (Investment, error)
- type InvestmentRepositor
- type InvestmentRequest
- type Investments
- type Repositor
Constants ¶
const ERR_NOT_FOUND = "not_found"
Variables ¶
This section is empty.
Functions ¶
func CreateSesh ¶
CreateSesh will create a new database session with the database params and database name passed in as strings. Returns a poiner to an mgo.Session or an error if one occurred.
Types ¶
type Base ¶
type Base struct { Id bson.ObjectId `json:"id" bson:"_id"` CreatedAt time.Time `json:"created_at" bson:"create_at"` UpdatedAt time.Time `json:"updated_at" bson:"updated_at"` }
Base is a base model for all other models to inherit from. It has fields that are common to all modules.
type Group ¶
Group is a struct representing a group schema. The json schema is defined as follows:
{ id: int, name: string, }
type GroupRepo ¶
type GroupRepo struct {
Collection *mgo.Collection
}
GroupRepo is responsible for all actions on the database related to the Group model.
func NewGroupRepo ¶
NewGroupRepo creates a new group repository, sets the correct database collection and ensures any indexes on the collection. Returns the new repository.
type Investment ¶
type Investment struct { Base `bson:",inline"` Symbol string `json:"symbol" bson:"symbol" binding:"required"` Group *Group `json:"group,omitempty" bson:",omitempty"` Fields bson.M `json:"fields"` }
Investment models a single entity on the stock market searchable by its symbol. It may have a group associated with it. It's fields is a investment schema:
/public/schema/investment.json
type InvestmentRepo ¶
type InvestmentRepo struct {
Collection *mgo.Collection
}
InvestmentRepo is responsible for all actions on the database related to the Investment model
func NewInvestmentRepo ¶
func NewInvestmentRepo(sesh *mgo.Database) InvestmentRepo
NewInvestmentRepo acreates a new investment repository, sets the correct database collection and ensures any indexes on the collection. Returns the new repository.
func (*InvestmentRepo) CreateOne ¶
func (r *InvestmentRepo) CreateOne(toCreate Investment) (Investment, error)
CreateOne will attempt to update the base time fields and then insert one Investment into the database by taking a Investment to be created. Returns the created investment.
func (*InvestmentRepo) DeleteOne ¶
func (r *InvestmentRepo) DeleteOne(id string) error
DeleteOne will delete an investment from the repo by ID. It will return an error if the document wasn't found or there was some other error condition.
func (*InvestmentRepo) FindMultiple ¶
func (r *InvestmentRepo) FindMultiple(params map[string]interface{}) ( Investments, error)
Get multiple will take a map of params to search on and return a list of investments that fulfill the params.
func (*InvestmentRepo) FindOne ¶
func (r *InvestmentRepo) FindOne(id string) (Investment, error)
GetOne will search for an investment and return it if found, return a not found error if not found, or return other error if one occurred.
func (*InvestmentRepo) FindOneBySymbol ¶
func (r *InvestmentRepo) FindOneBySymbol(symbol string) (Investment, error)
GetOneBySymbol will search for an investment by its symbol and will return it if it exists. If the "not found" error occurs, will return a NOT_FOUND error, or just the error otherwise. Because symbol is unique, this is not part of a list of investments but just a single investment.
func (*InvestmentRepo) UpdateOne ¶
func (r *InvestmentRepo) UpdateOne(id string, toUpdate Investment) (Investment, error)
UpdateOne will take a bson id as a string and an Investment model that will complete replace the model in the db. It will do a mongo update by passing in the id as the query and the investment model as the data.
type InvestmentRepositor ¶
type InvestmentRepositor interface { CreateOne(toCreate Investment) (Investment, error) DeleteOne(id bson.ObjectId) error }
InvestmentRepository is an interface for something that can run basic crud operations on an Investment model.
type InvestmentRequest ¶
type InvestmentRequest struct {
Investment Investment `json:"investment"`
}
InvestmentRequest models a request of an investment.
/public/schema/investment_request.json