From c71851add2b7daf5830246bb8a7046fa8641663e Mon Sep 17 00:00:00 2001 From: mfrigo Date: Fri, 8 Dec 2023 13:33:13 +0100 Subject: [PATCH] add Getsubscriber and getsubscriptionbyuser in comments for the moment to avoid crashing --- storage/mongodb.go | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/storage/mongodb.go b/storage/mongodb.go index 78c49ca..74a6e36 100644 --- a/storage/mongodb.go +++ b/storage/mongodb.go @@ -155,21 +155,33 @@ func (s MongoDBStorage) UpdateEvent(event Event) error { } func (s MongoDBStorage) GetSubscriber(subscriber string) ([]Subscription, error) { - collection := s.Client.Database(s.DbName).Collection(s.Collections["events"]) - - filter := bson.M{"namespace": subscriber} - - subscription := []Subscription{} - if err := collection.FindOne(context.TODO(), filter).Decode(subscription); err != nil { - return nil, err - } - return subscription, nil + // collection := s.Client.Database(s.DbName).Collection(s.Collections["events"]) + // subscriptions := []Subscription{} + // cur, err := collection.Find(context.TODO(), bson.M{"subscriptions": bson.M{"$elemMatch": bson.M{"subscriber": subscriber}}}) + // if err != nil { + // return subscriptions, err + // } + // for cur.Next(context.Background()) { + // var event Event + // if err := cur.Decode(&event); err != nil { + // return subscriptions, err + // } + // for i := range event.Subscriptions { + // if event.Subscriptions[i].Subscriber == subscriber { + // subscriptions = append(subscriptions, event.Subscriptions[i]) + // } + // } + // } + // return subscriptions, nil + return nil, nil } func (s MongoDBStorage) GetSubscriptionByUser(subscriber string) ([]Subscription, error) { - events, err := s.GetSubscriber(subscriber) - if err != nil { - panic(err) - } - return events, nil + // events, err := s.GetSubscriber(subscriber) + // if err != nil { + // panic(err) + // } + // fmt.Println(events) + // return events, nil + return nil, nil }