53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gitlab.unjx.de/flohoss/godash/internal/env"
|
|
"gitlab.unjx.de/flohoss/godash/services"
|
|
"gitlab.unjx.de/flohoss/godash/views/home"
|
|
)
|
|
|
|
type BookmarkService interface {
|
|
GetAllBookmarks() *services.Bookmarks
|
|
}
|
|
|
|
type SystemService interface {
|
|
GetLiveInformation() *services.LiveInformation
|
|
GetStaticInformation() *services.StaticInformation
|
|
}
|
|
|
|
type WeatherService interface {
|
|
GetCurrentWeather() *services.OpenWeather
|
|
}
|
|
|
|
func NewAppHandler(env *env.Config, s SystemService, w WeatherService, b BookmarkService) *AppHandler {
|
|
return &AppHandler{
|
|
env: env,
|
|
systemService: s,
|
|
weatherService: w,
|
|
bookmarkService: b,
|
|
}
|
|
}
|
|
|
|
type AppHandler struct {
|
|
env *env.Config
|
|
systemService SystemService
|
|
weatherService WeatherService
|
|
bookmarkService BookmarkService
|
|
}
|
|
|
|
func (bh *AppHandler) appHandler(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" {
|
|
http.Redirect(w, r, "/", http.StatusFound)
|
|
return
|
|
}
|
|
bookmarks := bh.bookmarkService.GetAllBookmarks()
|
|
staticSystem := bh.systemService.GetStaticInformation()
|
|
liveSystem := bh.systemService.GetLiveInformation()
|
|
weather := bh.weatherService.GetCurrentWeather()
|
|
|
|
titlePage := bh.env.Title
|
|
|
|
home.HomeIndex(titlePage, bh.env.Version, home.Home(titlePage, bookmarks, staticSystem, liveSystem, weather)).Render(r.Context(), w)
|
|
}
|