// findOneOrder returns one Order from the order database or from the order history database func findOneOrder(find *bson.M, selection *bson.M, sort string, customProvider OrderCustomProvider, fromHistory bool) (*Order, error) { var p *persistence.Persistor if fromHistory { p = GetOrderVersionsPersistor() } else { p = GetOrderPersistor() } order := &Order{} if find == nil { find = &bson.M{} } if selection == nil { selection = &bson.M{} } if sort != "" { err := p.GetCollection().Find(find).Select(selection).Sort(sort).One(order) if err != nil { return nil, err } } else { err := p.GetCollection().Find(find).Select(selection).One(order) if err != nil { return nil, err } } if customProvider != nil { var err error order, err = mapDecode(order, customProvider) if err != nil { return nil, err } } //event_log.SaveShopEvent(event_log.ActionRetrieveOrder, order.GetID(), nil, "") return order, nil }
// findOneCustomer returns one Customer from the customer database or from the customer history database func findOneCustomer(find *bson.M, selection *bson.M, sort string, customProvider CustomerCustomProvider, fromHistory bool) (*Customer, error) { var p *persistence.Persistor if fromHistory { p = GetCustomerVersionsPersistor() } else { p = GetCustomerPersistor() } customer := &Customer{} if find == nil { find = &bson.M{} } if selection == nil { selection = &bson.M{} } if sort != "" { err := p.GetCollection().Find(find).Select(selection).Sort(sort).One(customer) if err != nil { return nil, err } } else { err := p.GetCollection().Find(find).Select(selection).One(customer) if err != nil { return nil, err } } if customProvider != nil { var err error customer, err = mapDecode(customer, customProvider) if err != nil { return nil, err } } if customer == nil { return nil, errors.New("No result for " + utils.ToJSON(find)) } //event_log.SaveShopEvent(event_log.ActionRetrieveCustomer, customer.GetID(), nil, customer.GetEmail()) return customer, nil }
// Find returns an iterator for all entries found matching on query. func (proc *DefaultProcessor) Find(query *bson.M, p *persistence.Persistor) (iter func() (data interface{}, err error), err error) { log.Println("Default Processor Find") _, err = p.GetCollection().Find(query).Count() if err != nil { log.Println(err) } q := p.GetCollection().Find(query) count, err := q.Count() log.Println("Found", count, "items in database ", "("+proc.GetId()+")") if err != nil { return } mgoiter := q.Iter() iter = func() (interface{}, error) { data := proc.GetDataWrapper() if mgoiter.Next(data) { return data, nil } return nil, nil } return }
//------------------------------------------------------------------ // ~ PRIVATE METHODS //------------------------------------------------------------------ // findOneGroup returns one Group from the database func findOneObj(obj interface{}, find *bson.M, selection *bson.M, sort string, customProvider PriceRuleCustomProvider) (interface{}, error) { var p *persistence.Persistor p = GetPersistorForObject(obj) if find == nil { find = &bson.M{} } if selection == nil { selection = &bson.M{} } if sort != "" { err := p.GetCollection().Find(find).Select(selection).Sort(sort).One(obj) if err != nil { return nil, err } } else { err := p.GetCollection().Find(find).Select(selection).One(obj) if err != nil { return nil, err } } if customProvider != nil { var err error typedObject, err := mapDecodeObj(obj, customProvider) if err != nil { return nil, err } obj = typedObject } if obj == nil { return nil, errors.New(string(shop_error.ErrorNotFound)) } return obj, nil }