2020-11-06 23:19:54 +03:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
2021-01-30 12:34:52 +03:00
|
|
|
"github.com/gorilla/mux"
|
2020-11-06 23:19:54 +03:00
|
|
|
conf "github.com/muety/wakapi/config"
|
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
"github.com/muety/wakapi/models/view"
|
|
|
|
"github.com/muety/wakapi/services"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ImprintHandler struct {
|
|
|
|
config *conf.Config
|
2020-11-08 12:12:49 +03:00
|
|
|
keyValueSrvc services.IKeyValueService
|
2020-11-06 23:19:54 +03:00
|
|
|
}
|
|
|
|
|
2020-11-08 12:12:49 +03:00
|
|
|
func NewImprintHandler(keyValueService services.IKeyValueService) *ImprintHandler {
|
2020-11-06 23:19:54 +03:00
|
|
|
return &ImprintHandler{
|
|
|
|
config: conf.Get(),
|
|
|
|
keyValueSrvc: keyValueService,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:34:52 +03:00
|
|
|
func (h *ImprintHandler) RegisterRoutes(router *mux.Router) {
|
|
|
|
router.Path("/imprint").Methods(http.MethodGet).HandlerFunc(h.GetImprint)
|
|
|
|
}
|
|
|
|
|
2020-11-06 23:19:54 +03:00
|
|
|
func (h *ImprintHandler) GetImprint(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if h.config.IsDev() {
|
|
|
|
loadTemplates()
|
|
|
|
}
|
|
|
|
|
|
|
|
text := "failed to load content"
|
|
|
|
if data, err := h.keyValueSrvc.GetString(models.ImprintKey); err == nil {
|
|
|
|
text = data.Value
|
|
|
|
}
|
|
|
|
|
|
|
|
templates[conf.ImprintTemplate].Execute(w, h.buildViewModel(r).WithHtmlText(text))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *ImprintHandler) buildViewModel(r *http.Request) *view.ImprintViewModel {
|
2023-01-02 20:05:28 +03:00
|
|
|
return &view.ImprintViewModel{}
|
2020-11-06 23:19:54 +03:00
|
|
|
}
|