|
@ -8,6 +8,7 @@ import ( |
|
|
"git.aiterp.net/rpdata/api/internal/counter" |
|
|
"git.aiterp.net/rpdata/api/internal/counter" |
|
|
"git.aiterp.net/rpdata/api/model/channel" |
|
|
"git.aiterp.net/rpdata/api/model/channel" |
|
|
"git.aiterp.net/rpdata/api/models" |
|
|
"git.aiterp.net/rpdata/api/models" |
|
|
|
|
|
"github.com/globalsign/mgo/bson" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// Add creates a new Log
|
|
|
// Add creates a new Log
|
|
@ -39,5 +40,16 @@ func Add(date time.Time, channelName, title, eventName, description string, open |
|
|
return models.Log{}, err |
|
|
return models.Log{}, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// There can be only one open log in the same channel. TODO: Transaction
|
|
|
|
|
|
if open { |
|
|
|
|
|
query := bson.M{ |
|
|
|
|
|
"open": true, |
|
|
|
|
|
"channel": log.ChannelName, |
|
|
|
|
|
"id": bson.M{"$ne": log.ID}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go collection.UpdateAll(query, bson.M{"$set": bson.M{"open": false}}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return log, nil |
|
|
return log, nil |
|
|
} |
|
|
} |