/*
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* This file is licensed under AGPL-3.0-or-later, see NOTICE and LICENSE for
* more information.
*/
package handlers
import (
"context"
"net/http"
"tixe/db"
"tixe/template"
"tixe/types"
"tixe/util"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
func LinkEdit(c *gin.Context) {
session := sessions.Default(c)
user := session.Get("user").(types.User)
linkId := c.Param("id")
var link types.Link
err := db.PgPool.QueryRow(context.Background(),
"SELECT visual, link FROM links WHERE id = $1 AND user_id = $2",
linkId, user.Id).Scan(&link.Visual, &link.Link)
if err != nil {
errStr := "Could not query link entry from database"
util.RenderError(c, "db error", errStr, user)
return
}
link.Id = linkId
html := template.TmplEngine.Render("linkedit.tmpl", map[string]interface{}{"title": link.Visual, "user": user, "data": link})
c.Data(http.StatusOK, "text/html", html)
}