More data on subscriptions

This commit is contained in:
2022-10-17 05:00:35 +02:00
parent 3699479c5e
commit 4a26fc791c
7 changed files with 199 additions and 50 deletions

View File

@@ -2,6 +2,7 @@ package handlers
import (
"fmt"
"time"
"git.coopgo.io/coopgo-platform/agenda/storage"
"github.com/google/uuid"
@@ -12,8 +13,8 @@ func (h AgendaHandler) CreateEvent(event storage.Event) (*storage.Event, error)
event.ID = uuid.NewString()
}
if event.Subscribers == nil {
event.Subscribers = []string{}
if event.Subscriptions == nil {
event.Subscriptions = []storage.Subscription{}
}
if err := h.storage.CreateEvent(event); err != nil {
@@ -35,6 +36,13 @@ func (h AgendaHandler) GetEvents(namespaces []string) (events []storage.Event, e
}
func (h AgendaHandler) SubscribeEvent(eventid string, subscriber string) (err error) {
err = h.storage.AddSubscriber(eventid, subscriber)
subscription := storage.Subscription{
Subscriber: subscriber,
Tags: []string{},
Data: map[string]any{
"created_at": time.Now(),
},
}
err = h.storage.AddSubscription(eventid, subscription)
return
}