apps/bookmarks/app.go 1.3 K raw
1
package main
2
3
import (
4
	"database/sql"
5
	"embed"
6
	"html/template"
7
	"log/slog"
8
9
	"github.com/stevedylandev/andromeda/pkg/auth"
10
)
11
12
//go:embed templates/*.html static/*
13
var appFS embed.FS
14
15
type App struct {
16
	DB           *sql.DB
17
	Log          *slog.Logger
18
	Templates    *template.Template
19
	Sessions     *auth.Store
20
	Password     string
21
	APIKey       string
22
	CookieSecure bool
23
}
24
25
type Category struct {
26
	ID       int64  `json:"id"`
27
	ShortID  string `json:"short_id"`
28
	Name     string `json:"name"`
29
	Position int64  `json:"position"`
30
}
31
32
type Link struct {
33
	ID         int64   `json:"id"`
34
	ShortID    string  `json:"short_id"`
35
	Title      string  `json:"title"`
36
	URL        string  `json:"url"`
37
	FaviconURL *string `json:"favicon_url,omitempty"`
38
	CategoryID int64   `json:"category_id"`
39
	CreatedAt  int64   `json:"created_at"`
40
}
41
42
type adminLinkRow struct {
43
	ShortID    string
44
	Title      string
45
	URL        string
46
	FaviconURL *string
47
	Category   string
48
}
49
50
type categoryGroup struct {
51
	Name  string
52
	Links []Link
53
}
54
55
type indexPageData struct {
56
	Groups []categoryGroup
57
}
58
59
type loginPageData struct {
60
	Error string
61
}
62
63
type adminPageData struct {
64
	Success    string
65
	Error      string
66
	Categories []Category
67
	Links      []adminLinkRow
68
}
69
70
type apiCreateLinkBody struct {
71
	Category string `json:"category"`
72
	Title    string `json:"title"`
73
	URL      string `json:"url"`
74
}