Improve agenda
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
@@ -29,19 +29,43 @@ func (h AgendaHandler) GetEvent(id string) (event *storage.Event, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (h AgendaHandler) GetEvents(namespaces []string) (events []storage.Event, err error) {
|
||||
events, err = h.storage.GetEvents(namespaces)
|
||||
fmt.Println(events)
|
||||
func (h AgendaHandler) GetEvents(namespaces []string, mindate *time.Time, maxdate *time.Time) (results []storage.Event, err error) {
|
||||
results = []storage.Event{}
|
||||
events, err := h.storage.GetEvents(namespaces)
|
||||
if err == nil {
|
||||
for _, event := range events {
|
||||
if mindate != nil {
|
||||
if event.Enddate.Add(24 * time.Hour).Before(*mindate) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if maxdate != nil {
|
||||
if event.Enddate.Add(24 * time.Hour).After(*mindate) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
results = append(results, event)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (h AgendaHandler) SubscribeEvent(eventid string, subscriber string) (err error) {
|
||||
func (h AgendaHandler) SubscribeEvent(eventid string, subscriber string, data map[string]any) (err error) {
|
||||
if eventid == "" || subscriber == "" {
|
||||
return errors.New("missing eventid or subscriber")
|
||||
}
|
||||
now := time.Now()
|
||||
id := uuid.NewString()
|
||||
subscription := storage.Subscription{
|
||||
ID: id,
|
||||
Subscriber: subscriber,
|
||||
Tags: []string{},
|
||||
Data: map[string]any{
|
||||
"created_at": time.Now(),
|
||||
},
|
||||
CreatedAt: now,
|
||||
Data: map[string]any{},
|
||||
}
|
||||
// Initiate data map
|
||||
for k, v := range data {
|
||||
subscription.Data[k] = v
|
||||
}
|
||||
err = h.storage.AddSubscription(eventid, subscription)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user