Merge branch 'modifyAnEvent' into dev

This commit is contained in:
soukainna
2023-02-22 14:17:53 +01:00
11 changed files with 743 additions and 23 deletions

View File

@@ -3,22 +3,22 @@ package storage
import "time"
type Event struct {
ID string `json:"id" bson:"_id"`
Namespace string `json:"namespace"`
Owners []string `json:"owners"`
RestrictedTo []string `json:"restricted_to"`
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Startdate time.Time `json:"startdate"`
Enddate time.Time `json:"enddate"`
Starttime string `json:"starttime"`
Endtime string `json:"endtime"`
Allday bool `json:"allday"`
MaxSubscribers int64 `json:"max_subscribers"`
Subscriptions []Subscription `json:"subscriptions" bson:"subscriptions,omitempty"`
DeletedSubscription []Subscription `json:"deletedsubscriptions" bson:"deletedsubscriptions,omitempty"`
Data map[string]any `json:"data"`
ID string `json:"id" bson:"_id"`
Namespace string `json:"namespace"`
Owners []string `json:"owners"`
RestrictedTo []string `json:"restricted_to"`
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Startdate time.Time `json:"startdate"`
Enddate time.Time `json:"enddate"`
Starttime string `json:"starttime"`
Endtime string `json:"endtime"`
Allday bool `json:"allday"`
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

@@ -141,5 +141,12 @@ func (s MongoDBStorage) UpdateSubscription(eventid string, subscriber string, de
return er
}
}
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

@@ -12,6 +12,7 @@ type Storage interface {
GetEvents(namespaces []string) ([]Event, error)
AddSubscription(eventid string, subscription Subscription) error
UpdateSubscription(eventid string, subscriber string, deletesubscription Subscription) error
UpdateEvent(Event) error
}
type StorageImpl struct {
}