From 86df552bd1a60cc4ff65fbdea4cb78cdc18cbe9f Mon Sep 17 00:00:00 2001 From: mfrigo Date: Wed, 6 Dec 2023 16:12:29 +0100 Subject: [PATCH] GetSubscriber in Mongodb --- storage/mongodb.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/storage/mongodb.go b/storage/mongodb.go index e3cbe6d..78c49ca 100644 --- a/storage/mongodb.go +++ b/storage/mongodb.go @@ -154,10 +154,22 @@ func (s MongoDBStorage) UpdateEvent(event Event) error { return nil } -func (psql MongoDBStorage) GetSubscriber(subscriber string) ([]Subscription, error) { - return nil, nil +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 } -func (psql MongoDBStorage) GetSubscriptionByUser(subscriber string) ([]Subscription, error) { - return nil, nil +func (s MongoDBStorage) GetSubscriptionByUser(subscriber string) ([]Subscription, error) { + events, err := s.GetSubscriber(subscriber) + if err != nil { + panic(err) + } + return events, nil }