swirl/api/event.go

63 lines
1.3 KiB
Go
Raw Normal View History

2021-12-06 12:24:22 +00:00
package api
import (
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/errors"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/model"
)
// EventHandler encapsulates event related handlers.
type EventHandler struct {
Search web.HandlerFunc `path:"/search" auth:"event.view" desc:"search events"`
Prune web.HandlerFunc `path:"/prune" method:"post" auth:"event.delete" desc:"delete events"`
}
// NewEvent creates an instance of EventHandler
func NewEvent(b biz.EventBiz) *EventHandler {
return &EventHandler{
Search: eventSearch(b),
Prune: eventPrune(b),
}
}
func eventSearch(b biz.EventBiz) web.HandlerFunc {
return func(ctx web.Context) (err error) {
var (
2021-12-16 08:11:16 +00:00
args = &model.EventSearchArgs{}
2021-12-16 12:23:08 +00:00
events []*model.Event
2021-12-06 12:24:22 +00:00
total int
)
if err = ctx.Bind(args); err == nil {
events, total, err = b.Search(args)
}
if err != nil {
return
}
return success(ctx, data.Map{
"items": events,
"total": total,
})
}
}
func eventPrune(b biz.EventBiz) web.HandlerFunc {
type Args struct {
Date string `json:"date"`
}
return func(ctx web.Context) (err error) {
var args = &Args{}
if err = ctx.Bind(args); err == nil {
// TODO
//err = b.Prune(args.Date)
err = errors.NotImplemented
}
return ajax(ctx, err)
}
}