add logic to store event modification and deleted event

This commit is contained in:
soukainna
2023-02-01 09:58:37 +01:00
parent 5feb1b720e
commit 301f636072
11 changed files with 364 additions and 122 deletions

View File

@@ -18,6 +18,7 @@ type Event struct {
MaxSubscribers int64 `json:"max_subscribers"`
Subscriptions []Subscription `json:"subscriptions" bson:"subscriptions,omitempty"`
Data map[string]any `json:"data"`
Deleted bool `json:"deleted"`
}
type Subscription struct {

View File

@@ -120,3 +120,13 @@ func (s MongoDBStorage) AddSubscription(eventid string, subscription Subscriptio
_, err := collection.UpdateOne(context.TODO(), filter, push)
return err
}
func (s MongoDBStorage) UpdateEvent(event Event) error {
collection := s.Client.Database(s.DbName).Collection(s.Collections["events"])
if _, err := collection.ReplaceOne(context.TODO(), bson.M{"_id": event.ID}, event); err != nil {
fmt.Println(err)
return err
}
return nil
}

View File

@@ -11,6 +11,7 @@ type Storage interface {
GetEvent(string) (*Event, error)
GetEvents(namespaces []string) ([]Event, error)
AddSubscription(eventid string, subscription Subscription) error
UpdateEvent(Event) error
}
type StorageImpl struct {
}