Browse Source

models2: Fixed incorrect db mappings, fixed Edit not returning mutated model.

1.0
Gisle Aune 6 years ago
parent
commit
bebd99833b
  1. 4
      models/channel.go
  2. 4
      models/channels/edit.go
  3. 2
      models/channels/list.go

4
models/channel.go

@ -5,6 +5,6 @@ type Channel struct {
Name string `bson:"_id"` Name string `bson:"_id"`
Logged bool `bson:"logged"` Logged bool `bson:"logged"`
Hub bool `bson:"hub"` Hub bool `bson:"hub"`
EventName string `bson:"event,omitempty"`
LocationName string `bson:"location,omitempty"`
EventName string `bson:"eventName,omitempty"`
LocationName string `bson:"locationName,omitempty"`
} }

4
models/channels/edit.go

@ -11,15 +11,19 @@ func Edit(channel models.Channel, logged, hub *bool, eventName, locationName *st
if logged != nil && *logged != channel.Logged { if logged != nil && *logged != channel.Logged {
mutation["logged"] = *logged mutation["logged"] = *logged
channel.Logged = *logged
} }
if hub != nil && *hub != channel.Hub { if hub != nil && *hub != channel.Hub {
mutation["hub"] = *hub mutation["hub"] = *hub
channel.Hub = *hub
} }
if eventName != nil && *eventName != channel.EventName { if eventName != nil && *eventName != channel.EventName {
mutation["eventName"] = *eventName mutation["eventName"] = *eventName
channel.EventName = *eventName
} }
if locationName != nil && *locationName != channel.LocationName { if locationName != nil && *locationName != channel.LocationName {
mutation["locationName"] = *locationName mutation["locationName"] = *locationName
channel.LocationName = *locationName
} }
if len(mutation) == 0 { if len(mutation) == 0 {

2
models/channels/list.go

@ -30,7 +30,7 @@ func List(filter *Filter) ([]models.Channel, error) {
} }
channels := make([]models.Channel, 0, 128) channels := make([]models.Channel, 0, 128)
err := collection.Find(query).All(&channels)
err := collection.Find(query).Sort("_id").All(&channels)
return channels, err return channels, err
} }

Loading…
Cancel
Save