model

package
v0.0.0-...-234aa62 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2014 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ERR_NOT_FOUND = "not_found"

Variables

This section is empty.

Functions

func CreateSesh

func CreateSesh(dbParams string, dbName string) (*mgo.Session, error)

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.

func DB

func DB(dbParams string, dbName string) martini.Handler

DB will return a function to create a new db session by taking in a string of database params and a string of the db names and returning a handler for setting up the db session context.

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.

func (*Base) Create

func (r *Base) Create()

Create will update the current resource by setting its UpdatedAt and CreatedAt value to the current time.

func (*Base) Update

func (r *Base) Update()

Update will update the current resource by setting its UpdatedAt value to the current time.

type Group

type Group struct {
	Base `bson:",inline"`
	Name string `json:"name" bson"name"`
}

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

func NewGroupRepo(sesh *mgo.Database) GroupRepo

NewGroupRepo creates a new group repository, sets the correct database collection and ensures any indexes on the collection. Returns the new repository.

func (*GroupRepo) Create

func (r *GroupRepo) Create(toCreate Group) (Group, error)

Create will insert a new document of schema group to the database. Returns the group struct that was inserted or an error if one was encountered.

func (*GroupRepo) GetOne

func (r *GroupRepo) GetOne(name string) (Group, error)

GetOne returns one group from the database that matches based on the name string passed in. Returns the group or an error if one occurred.

type Groups

type Groups []Group

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

type Investments

type Investments []Investment

Investments is a list of Investment(s).

type Repositor

type Repositor interface {
	CreateOne(m Base) (Base, error)
}

Jump to

Keyboard shortcuts

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