Redmage/server/routes/page_home.go

33 lines
740 B
Go
Raw Normal View History

2024-04-09 14:30:54 +07:00
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) {
2024-04-13 00:15:31 +07:00
ctx, span := tracer.Start(r.Context(), "routes.PageHome")
defer span.End()
2024-04-09 14:30:54 +07:00
vc := views.NewContext(routes.Config, r)
2024-04-09 16:09:08 +07:00
params := parseSubredditListQuery(r)
list, err := routes.API.ListSubreddits(ctx, params)
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
}
data := homeview.Data{
SubredditsList: list,
2024-04-09 21:49:23 +07:00
Error: err,
2024-04-09 16:09:08 +07:00
}
if err := homeview.Home(vc, data).Render(ctx, rw); err != nil {
2024-04-09 14:30:54 +07:00
log.New(ctx).Err(err).Error("failed to render home view")
}
}