当前位置: 首页>>代码示例>>Golang>>正文


Golang interfaces.Filter类代码示例

本文整理汇总了Golang中github.com/opesun/nocrud/frame/interfaces.Filter的典型用法代码示例。如果您正苦于以下问题:Golang Filter类的具体用法?Golang Filter怎么用?Golang Filter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Filter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetClosest

// Returns the closest interval on the same day to the given interval.
func (e *Entries) GetClosest(a iface.Filter, data map[string]interface{}) (*evenday.Interval, error) {
	e.getOptions(a.Subject())
	prof, err := e.db.ToId(data["professional"].(string))
	if err != nil {
		return nil, err
	}
	from := data["from"].(int64)
	length := data["length"].(int64)
	err = e.intervalIsValid(data, prof, length)
	if err != nil {
		return nil, err
	}
	tt, err := e.getTimeTable(prof)
	if err != nil {
		return nil, err
	}
	day := evenday.DateToDayName(from)
	open := tt[day]
	taken, err := e.getTaken(a, from)
	if err != nil {
		return nil, err
	}
	adv := evenday.NewAdvisor(open, taken)
	to := from + length*60
	adv.Amount(1)
	interv, err := evenday.NewInterval(evenday.DateToMinute(from), evenday.DateToMinute(to))
	if err != nil {
		return nil, err
	}
	ret := adv.Advise(interv)
	if len(ret) == 0 {
		return nil, fmt.Errorf("Can't advise you, all day is taken.")
	}
	return ret[0], nil
}
开发者ID:crufter,项目名称:nocrud,代码行数:36,代码来源:meeting.go

示例2: UpdateAll

func (b *Basics) UpdateAll(a iface.Filter, data map[string]interface{}) error {
	upd := map[string]interface{}{
		"$set": data,
	}
	_, err := a.UpdateAll(upd)
	return err
}
开发者ID:crufter,项目名称:nocrud,代码行数:7,代码来源:basics.go

示例3: Save

func (tt *TimeTable) Save(a iface.Filter, data map[string]interface{}) error {
	if !tt.userIsProfessional {
		return fmt.Errorf("Only professionals can save timetables.")
	}
	ssl := toSS(data["timeTable"].([]interface{}))
	timeTable, err := evenday.StringsToTimeTable(ssl)
	if err != nil {
		return err
	}
	count, err := a.Count()
	if err != nil {
		return err
	}
	m := map[string]interface{}{}
	m["createdBy"] = tt.userId
	m["timeTable"] = timeTable
	if count == 0 {
		return a.Insert(m)
	} else if count == 1 {
		doc, err := a.SelectOne()
		if err != nil {
			return err
		}
		return doc.Update(m)
	}
	_, err = a.RemoveAll()
	if err != nil {
		return err
	}
	return a.Insert(m)
}
开发者ID:crufter,项目名称:nocrud,代码行数:31,代码来源:meeting.go

示例4: othersAlreadyTook

func (e *Entries) othersAlreadyTook(a iface.Filter, from, to int64) error {
	entryQ := map[string]interface{}{
		"$or": []interface{}{
			map[string]interface{}{
				"from": map[string]interface{}{
					"$gt": from,
					"$lt": to,
				},
			},
			map[string]interface{}{
				"to": map[string]interface{}{
					"$gt": from,
					"$lt": to,
				},
			},
		},
	}
	a.AddQuery(entryQ)
	eC, err := a.Count()
	if err != nil {
		return err
	}
	if eC > 0 {
		return fmt.Errorf("That time is already taken.")
	}
	return nil
}
开发者ID:crufter,项目名称:nocrud,代码行数:27,代码来源:meeting.go

示例5: Insert

func (e *Entries) Insert(a iface.Filter, data map[string]interface{}) error {
	e.getOptions(a.Subject())
	from := data["from"].(int64)
	length := data["length"].(int64)
	prof, err := e.db.ToId(data["professional"].(string))
	if err != nil {
		return err
	}
	err = e.intervalIsValid(data, prof, length)
	if err != nil {
		return err
	}
	to := from + length*60
	err = e.okAccordingToTimeTable(data, from, to)
	if err != nil {
		return err
	}
	err = e.othersAlreadyTook(a, from, to)
	if err != nil {
		return err
	}
	i := map[string]interface{}{
		"createdBy":       e.userId,
		"from":            from,
		"to":              to,
		"length":          length,
		"day":             dateToString(from),
		"forProfessional": prof,
	}
	return a.Insert(i)
}
开发者ID:crufter,项目名称:nocrud,代码行数:31,代码来源:meeting.go

示例6: _new

func _new(db iface.Db, f iface.Filter, hooks iface.Hooks, client iface.Client) (*User, error) {
	uidI, err := client.GetDecrypted("user")
	if err != nil {
		return nil, err
	}
	id, err := db.ToId(uidI.(string))
	if err != nil {
		return nil, err
	}
	q := map[string]interface{}{
		"_id": id,
	}
	f.AddQuery(q)
	userDoc, err := f.SelectOne()
	if err != nil {
		return nil, err
	}
	var langs []string
	if langz, ok := userDoc.Data()["languages"].([]interface{}); ok {
		for _, v := range langz {
			langs = append(langs, v.(string))
		}
	} else if client.Languages() != nil {
		langs = client.Languages()
	} else {
		langs = []string{"en"}
	}
	return &User{
		userDoc,
		numcon.IntP(userDoc.Data()["level"]),
		langs,
	}, nil
}
开发者ID:Laller,项目名称:nocrud,代码行数:33,代码来源:user.go

示例7: RegenerateFulltext

func (c *C) RegenerateFulltext(a iface.Filter) error {
	cb := func(g iface.Document) error {
		upd := c.updateFromDoc(g.Data())
		return g.Update(upd)
	}
	return a.Iterate(cb)
}
开发者ID:Laller,项目名称:nocrud,代码行数:7,代码来源:fulltext.go

示例8: New

func (c *C) New(a iface.Filter) ([]map[string]interface{}, error) {
	scheme, err := c.getScheme(a.Subject(), "Insert")
	if err != nil {
		return nil, err
	}
	return convert.SchemeToFields(scheme, nil)
}
开发者ID:crufter,项目名称:nocrud,代码行数:7,代码来源:skeleton.go

示例9: DeleteFile

func (c *C) DeleteFile(a iface.Filter, data map[string]interface{}) error {
	upd := map[string]interface{}{
		"$pull": map[string]interface{}{
			data["key"].(string): data["file"],
		},
	}
	return a.Update(upd)
}
开发者ID:Laller,项目名称:nocrud,代码行数:8,代码来源:file.go

示例10: FindLogin

func FindLogin(a iface.Filter, name, password string) (iface.Document, error) {
	encoded_pass := hashPass(password)
	q := map[string]interface{}{
		"name":     name,
		"password": encoded_pass,
	}
	return a.AddQuery(q).SelectOne()
}
开发者ID:crufter,项目名称:nocrud,代码行数:8,代码来源:user_model.go

示例11: SaveFulltext

func (c *C) SaveFulltext(a iface.Filter) error {
	doc, err := a.FindOne()
	if err != nil {
		return err
	}
	upd := c.updateFromDoc(doc)
	return a.Update(upd)
}
开发者ID:Laller,项目名称:nocrud,代码行数:8,代码来源:fulltext.go

示例12: Update

func (c *C) Update(a iface.Filter, data map[string]interface{}) error {
	m, err := c.decrypt(data)
	if err != nil {
		return err
	}
	m["modified"] = time.Now().UnixNano()
	return a.Update(m)
}
开发者ID:crufter,项目名称:nocrud,代码行数:8,代码来源:jsonedit.go

示例13: Insert

func (c *C) Insert(a iface.Filter, data map[string]interface{}) error {
	m, err := c.decrypt(data)
	if err != nil {
		return err
	}
	m["created"] = time.Now().UnixNano() // Should include user too maybe.
	return a.Insert(m)
}
开发者ID:crufter,项目名称:nocrud,代码行数:8,代码来源:jsonedit.go

示例14: TopModFilter

// This way professionals will only see entries posted for them,
// and users will only see entries posted by them.
// However, a professional will not be able to act as a user: he wont see entries posted by him, posted for other professionals.
func (e *Entries) TopModFilter(a iface.Filter) {
	if e.userIsProfessional {
		a.AddQuery(map[string]interface{}{
			"forProfessional": e.userId,
		})
	} else {
		a.AddQuery(map[string]interface{}{
			"createdBy": e.userId,
		})
	}
}
开发者ID:crufter,项目名称:nocrud,代码行数:14,代码来源:meeting.go

示例15: Edit

func (c *C) Edit(a iface.Filter) ([]map[string]interface{}, error) {
	doc, err := a.FindOne()
	if err != nil {
		return nil, err
	}
	scheme, err := c.getScheme(a.Subject(), "Update")
	if err != nil {
		return nil, err
	}
	return convert.SchemeToFields(scheme, doc)
}
开发者ID:crufter,项目名称:nocrud,代码行数:11,代码来源:skeleton.go


注:本文中的github.com/opesun/nocrud/frame/interfaces.Filter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。