More data on subscriptions
This commit is contained in:
@@ -3,26 +3,33 @@ 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"`
|
||||
Subscribers []string `json:"subscribers" bson:"subscribers,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"`
|
||||
//Subscribers []string `json:"subscribers" bson:"subscribers,omitempty`
|
||||
Subscriptions []Subscription `json:"subscriptions" bson:"subscriptions,omitempty"`
|
||||
Data map[string]any `json:"data"`
|
||||
}
|
||||
|
||||
type Subscription struct {
|
||||
Subscriber string `json:"subscriber"`
|
||||
Tags []string `json:"tags"`
|
||||
Data map[string]any `json:"data"`
|
||||
}
|
||||
|
||||
func (e Event) RemainingSubscriptions() int {
|
||||
if e.MaxSubscribers == 0 {
|
||||
return 999
|
||||
}
|
||||
return int(e.MaxSubscribers) - len(e.Subscribers)
|
||||
return int(e.MaxSubscribers) - len(e.Subscriptions)
|
||||
}
|
||||
|
||||
@@ -111,11 +111,11 @@ func (s MongoDBStorage) GetEvents(namespaces []string) (events []Event, err erro
|
||||
return
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) AddSubscriber(eventid string, subscriber string) error {
|
||||
func (s MongoDBStorage) AddSubscription(eventid string, subscription Subscription) error {
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["events"])
|
||||
|
||||
filter := bson.M{"_id": eventid}
|
||||
push := bson.M{"$push": bson.M{"subscribers": subscriber}}
|
||||
push := bson.M{"$push": bson.M{"subscriptions": subscription}}
|
||||
|
||||
_, err := collection.UpdateOne(context.TODO(), filter, push)
|
||||
return err
|
||||
|
||||
@@ -10,7 +10,7 @@ type Storage interface {
|
||||
CreateEvent(Event) error
|
||||
GetEvent(string) (*Event, error)
|
||||
GetEvents(namespaces []string) ([]Event, error)
|
||||
AddSubscriber(eventid string, subscriber string) error
|
||||
AddSubscription(eventid string, subscription Subscription) error
|
||||
}
|
||||
type StorageImpl struct {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user