Initial commit
This commit is contained in:
40
handlers/events.go
Normal file
40
handlers/events.go
Normal 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
18
handlers/handlers.go
Normal 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user