Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
498f5bc170 | ||
|
|
84e2db1b73 | ||
|
|
5a67e2c377 | ||
|
|
0e42bd7f79 |
@@ -59,6 +59,7 @@ func (h AgendaHandler) SubscribeEvent(eventid string, subscriber string, data ma
|
||||
subscription := storage.Subscription{
|
||||
ID: id,
|
||||
Subscriber: subscriber,
|
||||
EventID: eventid,
|
||||
Tags: []string{},
|
||||
CreatedAt: now,
|
||||
Data: map[string]any{},
|
||||
@@ -80,6 +81,7 @@ func (h AgendaHandler) DeleteSubscription(eventid string, subscriber string, dat
|
||||
deletesubscription := storage.Subscription{
|
||||
ID: id,
|
||||
Subscriber: subscriber,
|
||||
EventID: eventid,
|
||||
Tags: []string{},
|
||||
CreatedAt: now,
|
||||
Data: map[string]any{},
|
||||
@@ -101,6 +103,17 @@ func (h AgendaHandler) UpdateEvent(event storage.Event) (*storage.Event, error)
|
||||
return &event, nil
|
||||
}
|
||||
|
||||
func (h AgendaHandler) GetSubscriber(subscriber string) (results []storage.Subscription, err error) {
|
||||
if subscriber == "" {
|
||||
return nil, errors.New("missing subscriber")
|
||||
}
|
||||
results, err = h.storage.GetSubscriber(subscriber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (h AgendaHandler) GetSubscriptionByUser(subscriber string) (results []storage.Subscription, err error) {
|
||||
if subscriber == "" {
|
||||
return nil, errors.New("missing subscriber")
|
||||
|
||||
@@ -92,18 +92,11 @@ func (s MongoDBStorage) GetEvents(namespaces []string) (events []Event, err erro
|
||||
|
||||
for cur.Next(context.TODO()) {
|
||||
var event Event
|
||||
//var elem bson.M
|
||||
|
||||
if err := cur.Decode(&event); err != nil {
|
||||
return events, err
|
||||
}
|
||||
|
||||
// fmt.Println(elem)
|
||||
|
||||
// bsonBytes, _ := bson.Marshal(elem)
|
||||
// fmt.Println(string(bsonBytes))
|
||||
// bson.Unmarshal(bsonBytes, &event)
|
||||
|
||||
events = append(events, event)
|
||||
|
||||
}
|
||||
@@ -155,33 +148,36 @@ 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"])
|
||||
// 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
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["events"])
|
||||
subscriptions := []Subscription{}
|
||||
|
||||
var cur *mongo.Cursor
|
||||
|
||||
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])
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println(subscriptions)
|
||||
return subscriptions, nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) GetSubscriptionByUser(subscriber string) ([]Subscription, error) {
|
||||
// events, err := s.GetSubscriber(subscriber)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// fmt.Println(events)
|
||||
// return events, nil
|
||||
return nil, nil
|
||||
events, err := s.GetSubscriber(subscriber)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(events)
|
||||
return events, nil
|
||||
//return nil, nil
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ type Storage interface {
|
||||
AddSubscription(eventid string, subscription Subscription) error
|
||||
UpdateSubscription(eventid string, subscriber string, deletesubscription Subscription) error
|
||||
UpdateEvent(Event) error
|
||||
GetSubscriber(subscriber string) ([]Subscription, error)
|
||||
GetSubscriptionByUser(subscriber string) ([]Subscription, error)
|
||||
}
|
||||
type StorageImpl struct {
|
||||
|
||||
Reference in New Issue
Block a user