agenda/handlers/events.go

49 lines
1.0 KiB
Go

package handlers
import (
"fmt"
"time"
"git.coopgo.io/coopgo-platform/agenda/storage"
"github.com/google/uuid"
)
func (h AgendaHandler) CreateEvent(event storage.Event) (*storage.Event, error) {
if event.ID == "" {
event.ID = uuid.NewString()
}
if event.Subscriptions == nil {
event.Subscriptions = []storage.Subscription{}
}
if err := h.storage.CreateEvent(event); err != nil {
return nil, err
}
return &event, nil
}
func (h AgendaHandler) GetEvent(id string) (event *storage.Event, err error) {
event, err = h.storage.GetEvent(id)
return
}
func (h AgendaHandler) GetEvents(namespaces []string) (events []storage.Event, err error) {
events, err = h.storage.GetEvents(namespaces)
fmt.Println(events)
return
}
func (h AgendaHandler) SubscribeEvent(eventid string, subscriber string) (err error) {
subscription := storage.Subscription{
Subscriber: subscriber,
Tags: []string{},
Data: map[string]any{
"created_at": time.Now(),
},
}
err = h.storage.AddSubscription(eventid, subscription)
return
}