2024-05-04 22:17:50 +07:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2024-05-05 22:34:05 +07:00
|
|
|
"time"
|
2024-05-04 22:17:50 +07:00
|
|
|
|
2024-05-05 22:34:05 +07:00
|
|
|
"github.com/tigorlazuardi/redmage/api"
|
|
|
|
"github.com/tigorlazuardi/redmage/pkg/errs"
|
2024-05-04 22:17:50 +07:00
|
|
|
"github.com/tigorlazuardi/redmage/pkg/log"
|
|
|
|
"github.com/tigorlazuardi/redmage/views"
|
2024-05-05 22:34:05 +07:00
|
|
|
"github.com/tigorlazuardi/redmage/views/schedulehistoriesview"
|
2024-05-04 22:17:50 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
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-05-05 22:34:05 +07:00
|
|
|
var data schedulehistoriesview.Data
|
|
|
|
if tz := req.URL.Query().Get("tz"); tz == "" {
|
|
|
|
data.Timezone = time.Local
|
|
|
|
} else {
|
|
|
|
var err error
|
|
|
|
data.Timezone, err = time.LoadLocation(tz)
|
|
|
|
if err != nil {
|
|
|
|
data.Timezone = time.Local
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var params api.ScheduleHistoryListParams
|
|
|
|
params.FillFromQuery(req.URL.Query())
|
|
|
|
|
|
|
|
result, err := routes.API.ScheduleHistoryList(ctx, 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 := schedulehistoriesview.ScheduleHistoriesview(c, data).Render(ctx, rw); err != nil {
|
|
|
|
log.New(ctx).Err(err).Error("Failed to render schedule histories view")
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data.Schedules = result.Schedules
|
|
|
|
data.Total = result.Total
|
2024-05-04 22:17:50 +07:00
|
|
|
|
2024-05-05 22:34:05 +07:00
|
|
|
if err := schedulehistoriesview.ScheduleHistoriesview(c, data).Render(ctx, rw); err != nil {
|
2024-05-04 22:17:50 +07:00
|
|
|
log.New(ctx).Err(err).Error("Failed to render schedule histories view")
|
|
|
|
}
|
|
|
|
}
|