DEVELOPMENT ENVIRONMENT

~liljamo/tixe

ref: fd89e5586bdbdf5e55057348c82306f33718cdb8 tixe/handlers/link.go -rw-r--r-- 980 bytes
fd89e558Jonni Liljamo fix: fix cookie issue 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * 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)
}