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{
|
subscription := storage.Subscription{
|
||||||
ID: id,
|
ID: id,
|
||||||
Subscriber: subscriber,
|
Subscriber: subscriber,
|
||||||
|
EventID: eventid,
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
Data: map[string]any{},
|
Data: map[string]any{},
|
||||||
@@ -80,6 +81,7 @@ func (h AgendaHandler) DeleteSubscription(eventid string, subscriber string, dat
|
|||||||
deletesubscription := storage.Subscription{
|
deletesubscription := storage.Subscription{
|
||||||
ID: id,
|
ID: id,
|
||||||
Subscriber: subscriber,
|
Subscriber: subscriber,
|
||||||
|
EventID: eventid,
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
Data: map[string]any{},
|
Data: map[string]any{},
|
||||||
@@ -101,6 +103,17 @@ func (h AgendaHandler) UpdateEvent(event storage.Event) (*storage.Event, error)
|
|||||||
return &event, nil
|
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) {
|
func (h AgendaHandler) GetSubscriptionByUser(subscriber string) (results []storage.Subscription, err error) {
|
||||||
if subscriber == "" {
|
if subscriber == "" {
|
||||||
return nil, errors.New("missing 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()) {
|
for cur.Next(context.TODO()) {
|
||||||
var event Event
|
var event Event
|
||||||
//var elem bson.M
|
|
||||||
|
|
||||||
if err := cur.Decode(&event); err != nil {
|
if err := cur.Decode(&event); err != nil {
|
||||||
return events, err
|
return events, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Println(elem)
|
|
||||||
|
|
||||||
// bsonBytes, _ := bson.Marshal(elem)
|
|
||||||
// fmt.Println(string(bsonBytes))
|
|
||||||
// bson.Unmarshal(bsonBytes, &event)
|
|
||||||
|
|
||||||
events = append(events, event)
|
events = append(events, event)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -155,33 +148,36 @@ func (s MongoDBStorage) UpdateEvent(event Event) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s MongoDBStorage) GetSubscriber(subscriber string) ([]Subscription, error) {
|
func (s MongoDBStorage) GetSubscriber(subscriber string) ([]Subscription, error) {
|
||||||
// collection := s.Client.Database(s.DbName).Collection(s.Collections["events"])
|
collection := s.Client.Database(s.DbName).Collection(s.Collections["events"])
|
||||||
// subscriptions := []Subscription{}
|
subscriptions := []Subscription{}
|
||||||
// cur, err := collection.Find(context.TODO(), bson.M{"subscriptions": bson.M{"$elemMatch": bson.M{"subscriber": subscriber}}})
|
|
||||||
// if err != nil {
|
var cur *mongo.Cursor
|
||||||
// return subscriptions, err
|
|
||||||
// }
|
cur, err := collection.Find(context.TODO(), bson.M{"subscriptions": bson.M{"$elemMatch": bson.M{"subscriber": subscriber}}})
|
||||||
// for cur.Next(context.Background()) {
|
if err != nil {
|
||||||
// var event Event
|
return subscriptions, err
|
||||||
// if err := cur.Decode(&event); err != nil {
|
}
|
||||||
// return subscriptions, err
|
for cur.Next(context.Background()) {
|
||||||
// }
|
var event Event
|
||||||
// for i := range event.Subscriptions {
|
if err := cur.Decode(&event); err != nil {
|
||||||
// if event.Subscriptions[i].Subscriber == subscriber {
|
return subscriptions, err
|
||||||
// subscriptions = append(subscriptions, event.Subscriptions[i])
|
}
|
||||||
// }
|
for i := range event.Subscriptions {
|
||||||
// }
|
if event.Subscriptions[i].Subscriber == subscriber {
|
||||||
// }
|
subscriptions = append(subscriptions, event.Subscriptions[i])
|
||||||
// return subscriptions, nil
|
}
|
||||||
return nil, nil
|
}
|
||||||
|
}
|
||||||
|
fmt.Println(subscriptions)
|
||||||
|
return subscriptions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s MongoDBStorage) GetSubscriptionByUser(subscriber string) ([]Subscription, error) {
|
func (s MongoDBStorage) GetSubscriptionByUser(subscriber string) ([]Subscription, error) {
|
||||||
// events, err := s.GetSubscriber(subscriber)
|
events, err := s.GetSubscriber(subscriber)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// panic(err)
|
panic(err)
|
||||||
// }
|
}
|
||||||
// fmt.Println(events)
|
fmt.Println(events)
|
||||||
// return events, nil
|
return events, nil
|
||||||
return nil, nil
|
//return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ type Storage interface {
|
|||||||
AddSubscription(eventid string, subscription Subscription) error
|
AddSubscription(eventid string, subscription Subscription) error
|
||||||
UpdateSubscription(eventid string, subscriber string, deletesubscription Subscription) error
|
UpdateSubscription(eventid string, subscriber string, deletesubscription Subscription) error
|
||||||
UpdateEvent(Event) error
|
UpdateEvent(Event) error
|
||||||
|
GetSubscriber(subscriber string) ([]Subscription, error)
|
||||||
GetSubscriptionByUser(subscriber string) ([]Subscription, error)
|
GetSubscriptionByUser(subscriber string) ([]Subscription, error)
|
||||||
}
|
}
|
||||||
type StorageImpl struct {
|
type StorageImpl struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user