BrainMinder/cmd/web/helpers.go
2024-08-22 10:13:16 +02:00

64 lines
1.2 KiB
Go

package main
import (
"net/http"
"brainminder.speedtech.it/internal/version"
"brainminder.speedtech.it/models"
"github.com/justinas/nosurf"
)
func (app *application) newTemplateData(r *http.Request) map[string]any {
data := map[string]any{
"AuthenticatedUser": contextGetAuthenticatedUser(r),
"CSRFToken": nosurf.Token(r),
"Version": version.Get(),
}
typeModel := &models.TypeModel{DB: app.db}
current_notebook_id := app.getCurrentNotebok_id(r)
criteria := map[string]any{
"notebook_id": current_notebook_id,
}
types, _, _ := typeModel.Find(criteria)
data["typesList"] = types
notebookModel := &models.NotebookModel{DB: app.db}
data["notebooksList"] = notebookModel.AllAsOptions(true)
data["current_notebook_id"] = current_notebook_id
return data
}
func (app *application) newEmailData() map[string]any {
data := map[string]any{
"BaseURL": app.config.baseURL,
}
return data
}
/*
func (app *application) backgroundTask(r *http.Request, fn func() error) {
app.wg.Add(1)
go func() {
defer app.wg.Done()
defer func() {
err := recover()
if err != nil {
app.reportServerError(r, fmt.Errorf("%s", err))
}
}()
err := fn()
if err != nil {
app.reportServerError(r, err)
}
}()
}
*/