Documentation ¶
Index ¶
- Constants
- Variables
- func FindLeaseByIDHandler(collection cfmgo.Collection) http.HandlerFunc
- func FindLeasesHandler(collection cfmgo.Collection) http.HandlerFunc
- func Formatter() *render.Render
- func InsertInventoryItemHandler(collection cfmgo.Collection) http.HandlerFunc
- func InventoryItemAvailableStatus(id bson.ObjectId, collection cfmgo.Collection) error
- func InventoryItemLeasedStatus(id bson.ObjectId, leaseId bson.ObjectId, collection cfmgo.Collection) error
- func InventoryItemReservingStatus(id bson.ObjectId, collection cfmgo.Collection) error
- func LeaseInventoryItemHandler(ic cfmgo.Collection, lc cfmgo.Collection) http.HandlerFunc
- func ListInventoryItemsHandler(collection cfmgo.Collection) http.HandlerFunc
- func NewServer(appEnv *cfenv.App) *negroni.Negroni
- type InventoryItem
- type Lease
- type RedactedInventoryItem
- type RedactedLease
Constants ¶
const ( //InventoryCollectionName holds the name of the inventory collection InventoryCollectionName = "inventory" //LeaseCollectionName holds the name of the leases collection LeaseCollectionName = "leases" //InventoryItemStatusAvailable - this means the InventoryItem is in an available state InventoryItemStatusAvailable = "available" //InventoryItemStatusReserving - this means the InventoryItem is in a reserving state InventoryItemStatusReserving = "reserving" //InventoryItemStatusLeased = this means the InventoryItem is in a leased state InventoryItemStatusLeased = "leased" )
Variables ¶
var ( //ErrInventoryNotAvailable indicates the given InventoryItem is either //not found or is not available to be leased. ErrInventoryNotAvailable = errors.New("The InventoryItem specified is not available") )
Functions ¶
func FindLeaseByIDHandler ¶
func FindLeaseByIDHandler(collection cfmgo.Collection) http.HandlerFunc
FindLeaseByIDHandler will return a redacted lease record for the given ID.
func FindLeasesHandler ¶
func FindLeasesHandler(collection cfmgo.Collection) http.HandlerFunc
FindLeasesHandler will return a collection of redacted lease records constrained by optional request parameters:
func Formatter ¶
Formatter returns the address for a global response formatter realized in the `github.com/unrolled/render` package.
func InsertInventoryItemHandler ¶
func InsertInventoryItemHandler(collection cfmgo.Collection) http.HandlerFunc
InsertInventoryItemHandler uses MongoDB UPSERT to add new records, or update existing records, to the InventoryItems collection.
func InventoryItemAvailableStatus ¶
func InventoryItemAvailableStatus(id bson.ObjectId, collection cfmgo.Collection) error
InventoryItemAvailableStatus reverts the status from "reserving" to "available" in the case where a lease operation is unsuccessful.
func InventoryItemLeasedStatus ¶
func InventoryItemLeasedStatus(id bson.ObjectId, leaseId bson.ObjectId, collection cfmgo.Collection) error
InventoryItemLeasedStatus updates the status from "reserving" to "leased" and supplies the lease_id value.
func InventoryItemReservingStatus ¶
func InventoryItemReservingStatus(id bson.ObjectId, collection cfmgo.Collection) error
InventoryItemReservingStatus updates the status from "available" to "reserving".
func LeaseInventoryItemHandler ¶
func LeaseInventoryItemHandler(ic cfmgo.Collection, lc cfmgo.Collection) http.HandlerFunc
LeaseInventoryItemHandler creates a new lease record against an available InventoryItem and calls dispenser to provision that InventoryItem to the requestor.
Unless supplied, the StartDate and EndDate values will be calculated according to the time of the invocation and the DurationDays value. If DurationDays is not supplied, it will default to 14.
NOTE: The call to dispenser is not yet implemented.
func ListInventoryItemsHandler ¶
func ListInventoryItemsHandler(collection cfmgo.Collection) http.HandlerFunc
ListInventoryItemsHandler returns a collection of InventoryItems based on supplied paramaters.
Types ¶
type InventoryItem ¶
type InventoryItem struct { ID bson.ObjectId `bson:"_id,omitempty" json:"id"` SKU string `json:"sku"` Tier int `json:"tier"` OfferingType string `json:"offering_type"` Size string `json:"size"` Attributes map[string]interface{} `json:"attributes"` PrivateAttributes map[string]interface{} `json:"private_attributes,omitempty"` Status string `json:"status"` LeaseID bson.ObjectId `bson:"lease_id,omitempty" json:"lease_id"` }
InventoryItem wraps the inventory collection.
type Lease ¶
type Lease struct { ID bson.ObjectId `bson:"_id,omitempty" json:"id"` InventoryItemID bson.ObjectId `bson:"inventory_item_id,omitempty" json:"inventory_item_id"` User string `json:"user"` DurationDays int `json:"duration_days"` StartDate string `json:"start_date"` EndDate string `json:"end_date"` Status string `json:"status"` Attributes map[string]interface{} `json:"attributes"` PrivateAttributes map[string]interface{} `json:"private_attributes,omitempty"` }
Lease wraps the leases collection.
type RedactedInventoryItem ¶
type RedactedInventoryItem struct { ID bson.ObjectId `bson:"_id,omitempty" json:"id,omitempty"` SKU string `json:"sku,omitempty"` Tier int `json:"tier,omitempty"` OfferingType string `json:"offering_type,omitempty"` Size string `json:"size,omitempty"` Attributes map[string]interface{} `json:"attributes,omitempty"` Status string `json:"status,omitempty"` LeaseID bson.ObjectId `bson:"lease_id,omitempty" json:"lease_id,omitempty"` }
RedactedInventoryItem wraps the inventory collection omitting private attributes.
type RedactedLease ¶
type RedactedLease struct { ID bson.ObjectId `bson:"_id,omitempty" json:"id,omitempty"` InventoryItemID bson.ObjectId `bson:"inventory_item_id,omitempty" json:"inventory_item_id,omitempty"` User string `json:"user,omitempty"` DurationDays int `json:"duration_days,omitempty"` StartDate string `json:"start_date,omitempty"` EndDate string `json:"end_date,omitempty"` Status string `json:"status,omitempty"` Attributes map[string]interface{} `json:"attributes,omitempty"` }
RedactedLease wraps the leases collection omitting private attributes.