godash/handlers/app.handlers.go

52 lines
1.4 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
}
2024-03-25 20:31:51 +01:00
func NewAppHandler(env *env.Config, authHandler *AuthHandler, s SystemService, w WeatherService, b BookmarkService) *AppHandler {
2024-03-12 15:49:08 +01:00
return &AppHandler{
env: env,
2024-03-25 20:31:51 +01:00
authHandler: authHandler,
systemService: s,
weatherService: w,
bookmarkService: b,
2024-03-12 15:49:08 +01:00
}
}
type AppHandler struct {
env *env.Config
2024-03-25 20:31:51 +01:00
authHandler *AuthHandler
systemService SystemService
weatherService WeatherService
bookmarkService BookmarkService
2024-03-12 15:49:08 +01:00
}
func (bh *AppHandler) appHandler(c echo.Context) error {
2024-03-25 20:31:51 +01:00
bookmarks := bh.bookmarkService.GetAllBookmarks()
staticSystem := bh.systemService.GetStaticInformation()
liveSystem := bh.systemService.GetLiveInformation()
weather := bh.weatherService.GetCurrentWeather()
user := bh.authHandler.GetUserInfo()
2024-03-12 15:49:08 +01:00
titlePage := bh.env.Title
2024-03-25 20:31:51 +01:00
return renderView(c, home.HomeIndex(titlePage, bh.env.Version, home.Home(titlePage, user, bookmarks, staticSystem, liveSystem, weather)))
2024-03-12 15:49:08 +01:00
}