godash/handlers/app.handlers.go

50 lines
1.3 KiB
Go
Raw Normal View History

2024-03-12 15:49:08 +01:00
package handlers
import (
"github.com/labstack/echo/v4"
"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
}
2024-03-15 18:56:32 +01:00
type WeatherService interface {
GetCurrentWeather() *services.OpenWeather
}
func NewAppHandler(env *env.Config, s SystemService, w WeatherService, b BookmarkService) *AppHandler {
2024-03-12 15:49:08 +01:00
return &AppHandler{
env: env,
SystemService: s,
2024-03-15 18:56:32 +01:00
WeatherService: w,
2024-03-12 15:49:08 +01:00
BookmarkService: b,
}
}
type AppHandler struct {
env *env.Config
SystemService SystemService
2024-03-15 18:56:32 +01:00
WeatherService WeatherService
2024-03-12 15:49:08 +01:00
BookmarkService BookmarkService
}
func (bh *AppHandler) appHandler(c echo.Context) error {
bookmarks := bh.BookmarkService.GetAllBookmarks()
staticSystem := bh.SystemService.GetStaticInformation()
liveSystem := bh.SystemService.GetLiveInformation()
2024-03-15 18:56:32 +01:00
weather := bh.WeatherService.GetCurrentWeather()
2024-03-12 15:49:08 +01:00
titlePage := bh.env.Title
2024-03-18 18:21:13 +01:00
return renderView(c, home.HomeIndex(titlePage, bh.env.Version, home.Home(titlePage, bookmarks, staticSystem, liveSystem, weather)))
2024-03-12 15:49:08 +01:00
}