graph2: Added Channel type and queries
the build failed

This commit is contained in:
2018-09-13 22:49:36 +02:00
parent 9978d7380b
commit 1be4088a8f
5 changed files with 121 additions and 23 deletions
+32 -23
View File
@@ -16,11 +16,18 @@ var ErrInvalidName = errors.New("Invalid channel name")
// A Channel represents information abount an IRC RP channel, and whether it should be logged
type Channel struct {
Name string `bson:"_id"`
Logged bool `bson:"logged"`
Hub bool `bson:"hub"`
Event string `bson:"event,omitempty"`
Location string `bson:"location,omitempty"`
Name string `bson:"_id"`
Logged bool `bson:"logged"`
Hub bool `bson:"hub"`
EventName string `bson:"event,omitempty"`
LocationName string `bson:"location,omitempty"`
}
// Filter for searching
type Filter struct {
Logged *bool `json:"logged"`
EventName string `json:"eventName"`
LocationName string `json:"locationName"`
}
// Edit edits the channel
@@ -36,13 +43,13 @@ func (channel *Channel) Edit(logged, hub *bool, event, location *string) error {
changes["hub"] = *hub
changed.Hub = *hub
}
if event != nil && channel.Event != *event {
if event != nil && channel.EventName != *event {
changes["event"] = *event
changed.Event = *event
changed.EventName = *event
}
if location != nil && channel.Event != *location {
if location != nil && channel.LocationName != *location {
changes["location"] = *location
changed.Location = *location
changed.LocationName = *location
}
if len(changes) == 0 {
@@ -84,11 +91,11 @@ func New(name string, logged, hub bool, event, location string) (Channel, error)
}
channel := Channel{
Name: name,
Logged: logged,
Hub: hub,
Event: event,
Location: location,
Name: name,
Logged: logged,
Hub: hub,
EventName: event,
LocationName: location,
}
err := collection.Insert(channel)
@@ -109,17 +116,19 @@ func FindName(name string) (Channel, error) {
// List finds channels, if logged is true it will be limited to logged
// channels
func List(logged *bool, eventName *string, locationName *string) ([]Channel, error) {
func List(filter *Filter) ([]Channel, error) {
query := bson.M{}
if logged != nil {
query["logged"] = *logged
}
if eventName != nil {
query["eventName"] = *eventName
}
if locationName != nil {
query["locationName"] = *locationName
if filter != nil {
if filter.Logged != nil {
query["logged"] = *filter.Logged
}
if filter.EventName != "" {
query["eventName"] = filter.EventName
}
if filter.LocationName != "" {
query["locationName"] = filter.LocationName
}
}
channels := make([]Channel, 0, 128)