Redmage/server/routes/page_home.go

33 lines
740 B
Go

package routes
import (
"net/http"
"github.com/tigorlazuardi/redmage/pkg/log"
"github.com/tigorlazuardi/redmage/views"
"github.com/tigorlazuardi/redmage/views/homeview"
)
func (routes *Routes) PageHome(rw http.ResponseWriter, r *http.Request) {
ctx, span := tracer.Start(r.Context(), "routes.PageHome")
defer span.End()
vc := views.NewContext(routes.Config, r)
params := parseSubredditListQuery(r)
list, err := routes.API.ListSubreddits(ctx, params)
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
}
data := homeview.Data{
SubredditsList: list,
Error: err,
}
if err := homeview.Home(vc, data).Render(ctx, rw); err != nil {
log.New(ctx).Err(err).Error("failed to render home view")
}
}