本文整理汇总了Golang中github.com/opesun/nocrud/frame/interfaces.Filter.Subject方法的典型用法代码示例。如果您正苦于以下问题:Golang Filter.Subject方法的具体用法?Golang Filter.Subject怎么用?Golang Filter.Subject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/opesun/nocrud/frame/interfaces.Filter
的用法示例。
在下文中一共展示了Filter.Subject方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Update
func (c *C) Update(a iface.Filter, data map[string]interface{}) error {
upd := map[string]interface{}{
"$set": data,
}
has_files := len(c.fileBiz) > 0
if has_files {
ids, err := a.Ids()
if err != nil {
return err
}
err = c.moveFiles(a.Subject(), ids[0].String())
if err != nil {
return err
}
upd["$addToSet"] = eachIfNeeded(fileNames(c.fileBiz))
}
err := a.Update(upd)
if err != nil {
return err
}
if c.Hooks != nil {
c.Hooks.Select("Updated").Fire(a)
c.Hooks.Select(a.Subject() + "Updated").Fire(a)
}
return nil
}
示例2: 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)
}
示例3: 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
}
示例4: 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)
}
示例5: 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)
}
示例6: Login
func (a *C) Login(f iface.Filter, data map[string]interface{}) error {
name := data["name"].(string)
pass := data["password"].(string)
// Maybe there could be a check here to not log in somebody who is already logged in.
if user, err := user_model.FindLogin(f, name, pass); err == nil {
a.client.StoreEncrypted("user", f.Subject()+"|"+user.Id().String())
} else {
return err
}
return nil
}
示例7: Update
func (b *Basics) Update(a iface.Filter, data map[string]interface{}) error {
upd := map[string]interface{}{
"$set": data,
}
err := a.Update(upd)
if err != nil {
return err
}
if b.Hooks != nil {
b.Hooks.Select("Updated").Fire(a)
b.Hooks.Select(a.Subject() + "Updated").Fire(a)
}
return nil
}
示例8: Insert
func (b *Basics) Insert(a iface.Filter, data map[string]interface{}) (iface.Id, error) {
id := b.Db.NewId()
data["_id"] = id
err := a.Insert(data)
if err != nil {
return nil, err
}
if b.Hooks != nil {
q := map[string]interface{}{
"_id": id,
}
filt := a.Clone().AddQuery(q)
b.Hooks.Select("Inserted").Fire(filt)
b.Hooks.Select(a.Subject() + "Inserted").Fire(filt)
}
return id, nil
}
示例9: Insert
func (c *C) Insert(a iface.Filter, data map[string]interface{}) (iface.Id, error) {
has_files := len(c.fileBiz) > 0
if has_files {
merge(data, fileNames(c.fileBiz))
}
id, err := c.Basics.Insert(a, data)
if err != nil {
return id, err
}
if has_files {
err := c.moveFiles(a.Subject(), id.String())
if err != nil {
return nil, err
}
}
return id, nil
}
示例10: Reduce
func (f *Filter) Reduce(a ...iface.Filter) (iface.Filter, error) {
l := len(a)
if l == 0 {
return &Filter{}, fmt.Errorf("Nothing to reduce.")
}
var prev iface.Filter
prev = f
for _, v := range a {
ids, err := prev.Ids()
if err != nil {
return &Filter{}, err
}
v.AddParents("_"+prev.Subject(), ids)
prev = v
}
return prev, nil
}