You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
855 B
39 lines
855 B
package logs
|
|
|
|
import (
|
|
"git.aiterp.net/rpdata/api/models"
|
|
"github.com/globalsign/mgo/bson"
|
|
)
|
|
|
|
// Edit sets a log's meta-data.
|
|
func Edit(log models.Log, title *string, event *string, description *string, open *bool) (models.Log, error) {
|
|
changes := bson.M{}
|
|
|
|
if title != nil && *title != log.Title {
|
|
changes["title"] = *title
|
|
log.Title = *title
|
|
}
|
|
if event != nil && *event != log.EventName {
|
|
changes["event"] = *event
|
|
log.EventName = *event
|
|
}
|
|
if description != nil && *description != log.Description {
|
|
changes["description"] = *description
|
|
log.Description = *description
|
|
}
|
|
if open != nil && *open != log.Open {
|
|
changes["open"] = *open
|
|
log.Open = *open
|
|
}
|
|
|
|
if len(changes) == 0 {
|
|
return log, nil
|
|
}
|
|
|
|
err := collection.UpdateId(log.ID, bson.M{"$set": changes})
|
|
if err != nil {
|
|
return models.Log{}, err
|
|
}
|
|
|
|
return log, nil
|
|
}
|