Redmage/server/routes/page_schedule_history.go

39 lines
1.1 KiB
Go
Raw Normal View History

package routes
import (
"net/http"
"github.com/tigorlazuardi/redmage/pkg/errs"
"github.com/tigorlazuardi/redmage/pkg/log"
"github.com/tigorlazuardi/redmage/views"
2024-06-03 16:19:34 +07:00
"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)
2024-06-03 16:19:34 +07:00
var data schedulehistories.Data
2024-06-03 16:19:34 +07:00
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
2024-06-03 16:19:34 +07:00
if err := schedulehistories.View(c, data).Render(ctx, rw); err != nil {
log.New(ctx).Err(err).Error("Failed to render schedule histories view")
}
return
}
2024-06-03 16:19:34 +07:00
data.ScheduleHistories = result.Schedules
2024-06-03 16:19:34 +07:00
if err := schedulehistories.View(c, data).Render(ctx, rw); err != nil {
log.New(ctx).Err(err).Error("Failed to render schedule histories view")
}
}