Initial commit

This commit is contained in:
2022-09-05 07:27:52 +02:00
commit 3699479c5e
19 changed files with 2730 additions and 0 deletions

40
handlers/events.go Normal file
View File

@@ -0,0 +1,40 @@
package handlers
import (
"fmt"
"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.Subscribers == nil {
event.Subscribers = []string{}
}
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) {
err = h.storage.AddSubscriber(eventid, subscriber)
return
}

18
handlers/handlers.go Normal file
View File

@@ -0,0 +1,18 @@
package handlers
import (
"git.coopgo.io/coopgo-platform/agenda/storage"
"github.com/spf13/viper"
)
type AgendaHandler struct {
config *viper.Viper
storage storage.Storage
}
func NewHandler(cfg *viper.Viper, storage storage.Storage) AgendaHandler {
return AgendaHandler{
config: cfg,
storage: storage,
}
}