Redmage/server/routes/page_schedule_history.go
Tigor Hutasuhut 44128365c0
Some checks failed
/ push (push) Has been cancelled
schedule-histories: revamped page data
2024-06-03 16:19:34 +07:00

39 lines
1.1 KiB
Go

package routes
import (
"net/http"
"github.com/tigorlazuardi/redmage/pkg/errs"
"github.com/tigorlazuardi/redmage/pkg/log"
"github.com/tigorlazuardi/redmage/views"
"github.com/tigorlazuardi/redmage/views/schedulehistories"
)
func (routes *Routes) PageScheduleHistory(rw http.ResponseWriter, req *http.Request) {
ctx, span := tracer.Start(req.Context(), "*Routes.PageScheduleHistory")
defer span.End()
c := views.NewContext(routes.Config, req)
var data schedulehistories.Data
data.Params.FillFromQuery(req.URL.Query())
result, err := routes.API.ScheduleHistoryListByDate(ctx, data.Params)
if err != nil {
log.New(ctx).Err(err).Error("Failed to list schedule histories")
code, message := errs.HTTPMessage(err)
rw.WriteHeader(code)
data.Error = message
if err := schedulehistories.View(c, data).Render(ctx, rw); err != nil {
log.New(ctx).Err(err).Error("Failed to render schedule histories view")
}
return
}
data.ScheduleHistories = result.Schedules
if err := schedulehistories.View(c, data).Render(ctx, rw); err != nil {
log.New(ctx).Err(err).Error("Failed to render schedule histories view")
}
}