Moved channels to new system, fixed change insert not working.
the build was successful

This commit is contained in:
2019-06-24 20:30:14 +02:00
parent f46b6f0774
commit acb6b637a5
16 changed files with 498 additions and 97 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ func (r *changeRepository) Insert(ctx context.Context, change models.Change) (*m
change.ID = "Change_" + strconv.Itoa(next)
err = r.changes.Insert(change)
err = r.changes.Insert(&change)
if err != nil {
return nil, err
}
+28 -1
View File
@@ -7,6 +7,27 @@ import (
"github.com/globalsign/mgo/bson"
)
func newChannelRepository(db *mgo.Database) (*channelRepository, error) {
collection := db.C("common.channels")
err := collection.EnsureIndexKey("logged")
if err != nil {
return nil, err
}
err = collection.EnsureIndexKey("event")
if err != nil {
return nil, err
}
err = collection.EnsureIndexKey("location")
if err != nil {
return nil, err
}
return &channelRepository{
channels: collection,
}, nil
}
type channelRepository struct {
channels *mgo.Collection
}
@@ -32,6 +53,9 @@ func (r *channelRepository) List(ctx context.Context, filter models.ChannelFilte
if filter.LocationName != nil {
query["locationName"] = *filter.LocationName
}
if len(filter.Names) > 0 {
query["_id"] = bson.M{"$in": filter.Names}
}
channels := make([]*models.Channel, 0, 32)
err := r.channels.Find(query).Limit(filter.Limit).Sort("_id").All(&channels)
@@ -47,7 +71,7 @@ func (r *channelRepository) List(ctx context.Context, filter models.ChannelFilte
}
func (r *channelRepository) Insert(ctx context.Context, channel models.Channel) (*models.Channel, error) {
err := r.channels.Insert(&channel)
err := r.channels.Insert(channel)
if err != nil {
return nil, err
}
@@ -59,12 +83,15 @@ func (r *channelRepository) Update(ctx context.Context, channel models.Channel,
updateBson := bson.M{}
if update.Logged != nil {
updateBson["logged"] = *update.Logged
channel.Logged = *update.Logged
}
if update.LocationName != nil {
updateBson["locationName"] = *update.LocationName
channel.LocationName = *update.LocationName
}
if update.EventName != nil {
updateBson["eventName"] = *update.EventName
channel.EventName = *update.EventName
}
err := r.channels.UpdateId(channel.Name, bson.M{"$set": updateBson})
+7
View File
@@ -79,6 +79,12 @@ func Init(cfg config.Database) (*MongoDB, error) {
return nil, err
}
channels, err := newChannelRepository(db)
if err != nil {
session.Close()
return nil, err
}
changes, err := newChangeRepository(db)
if err != nil {
session.Close()
@@ -104,6 +110,7 @@ func Init(cfg config.Database) (*MongoDB, error) {
changes: changes,
characters: characters,
channels: channels,
tags: newTagRepository(db),
logs: logs,
posts: posts,