2024-02-11 19:28:00 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2024-02-15 22:47:56 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/config"
|
2024-02-11 19:28:00 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/models/query"
|
2024-02-12 10:22:14 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/web/templates/components"
|
2024-02-11 22:48:37 +00:00
|
|
|
"github.com/gorilla/sessions"
|
2024-02-11 19:28:00 +00:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
2024-02-12 10:22:14 +00:00
|
|
|
var Pages = []*components.Page{
|
2024-02-15 22:47:56 +00:00
|
|
|
{Path: "/", Title: "Status", Breadcrumb: "Status"},
|
|
|
|
{Path: "/incidents", Title: "Incidents", Breadcrumb: "Incidents"},
|
|
|
|
{Path: "/settings", Title: "Settings", Breadcrumb: "Settings"},
|
2024-02-12 10:22:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-12 13:20:38 +00:00
|
|
|
func GetPageByTitle(pages []*components.Page, title string) *components.Page {
|
|
|
|
for _, p := range pages {
|
2024-02-12 10:22:14 +00:00
|
|
|
if p.Title == title {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-11 19:28:00 +00:00
|
|
|
type BaseHandler struct {
|
|
|
|
db *gorm.DB
|
|
|
|
query *query.Query
|
2024-02-15 22:47:56 +00:00
|
|
|
config *config.Config
|
2024-02-11 22:48:37 +00:00
|
|
|
|
|
|
|
store *sessions.CookieStore
|
2024-02-11 19:28:00 +00:00
|
|
|
}
|
|
|
|
|
2024-02-15 22:47:56 +00:00
|
|
|
func NewBaseHandler(db *gorm.DB, q *query.Query, config *config.Config) *BaseHandler {
|
2024-02-15 17:43:35 +00:00
|
|
|
store := sessions.NewCookieStore([]byte(config.SessionSecret))
|
2024-02-11 22:48:37 +00:00
|
|
|
|
|
|
|
return &BaseHandler{db, q, config, store}
|
2024-02-11 19:28:00 +00:00
|
|
|
}
|