From 7533475b72a89f5ac3da685c4b314a0212582d8b Mon Sep 17 00:00:00 2001 From: pluja Date: Mon, 9 Sep 2024 15:26:40 +0200 Subject: [PATCH] Add changelog page --- src/database/models.go | 9 +++++++++ src/database/pocketbase.go | 20 +++++++++++++++++++ src/frontend/templates/changelog.html | 28 +++++++++++++++++++++++++++ src/server/server.go | 1 + src/server/web_handlers.go | 20 +++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 src/frontend/templates/changelog.html diff --git a/src/database/models.go b/src/database/models.go index 9ed6b48..b7aad5e 100644 --- a/src/database/models.go +++ b/src/database/models.go @@ -60,3 +60,12 @@ type Announcement struct { Warning bool Active bool } + +type Change struct { + Created string `json:"created"` + Summary string `json:"summary"` + ID string `json:"id"` + Title string `json:"title"` + Updated string `json:"updated"` + Expand map[string]Service `json:"expand,omitempty"` +} diff --git a/src/database/pocketbase.go b/src/database/pocketbase.go index f8e0c8a..bb8821a 100644 --- a/src/database/pocketbase.go +++ b/src/database/pocketbase.go @@ -58,6 +58,26 @@ func (p *PbClient) GetServices(filters, sort string) ([]Service, error) { return response.Items, nil } +func (p *PbClient) GetChanges() ([]Change, error) { + + collection := pocketbase.CollectionSet[Change](p.Client, "changes") + params := pocketbase.ParamsList{ + Page: 1, + Size: 200, + Expand: "service", + Fields: "*,expand.service.*", + Sort: "-created", + } + + response, err := collection.List(params) + if err != nil { + log.Error().Err(err).Msg("err") + return nil, errors.New("database error") + } + + return response.Items, nil +} + func (p *PbClient) GetServiceByNameOrUrl(id string) (*Service, error) { collection := pocketbase.CollectionSet[Service](p.Client, "services") params := pocketbase.ParamsList{ diff --git a/src/frontend/templates/changelog.html b/src/frontend/templates/changelog.html new file mode 100644 index 0000000..c0fceee --- /dev/null +++ b/src/frontend/templates/changelog.html @@ -0,0 +1,28 @@ +
+

Changelog

+ +
+ {{ range .Changes }} +
+
+
+

{{.Title}}

+ {{.Created}} +
+

{{.Summary | safe}}

+ + {{ if .Expand.service }} +
+ {{ with .Expand.service }} + + Related service: {{ .Name }} + + {{ end }} +
+ {{end}} +
+
+ {{ end }} +
+
\ No newline at end of file diff --git a/src/server/server.go b/src/server/server.go index d1c2936..dec2e7c 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -95,6 +95,7 @@ func (s *Server) RegisterRoutes() { // GET s.Router.Get("/", s.handleIndex) + s.Router.Get("/changelog", s.handleChangelog) s.Router.Get("/about", s.handleAbout) s.Router.Get("/pending", s.handlePending) s.Router.Get("/service/{name:string}", s.handleService) diff --git a/src/server/web_handlers.go b/src/server/web_handlers.go index 87935c2..163121c 100644 --- a/src/server/web_handlers.go +++ b/src/server/web_handlers.go @@ -126,6 +126,26 @@ func (s *Server) handleService(c iris.Context) { } } +func (s *Server) handleChangelog(c iris.Context) { + changes, err := database.Pb.GetChanges() + if err != nil { + c.HTML("

%s

", err.Error()) + return + } + + log.Printf("%+v", changes) + + c.ViewLayout("main") + data := iris.Map{ + "Title": "Changelog | KYCNOT.ME", + "Changes": changes, + } + if err := c.View("changelog", data); err != nil { + c.HTML("

%s

", err.Error()) + return + } +} + func (s *Server) handleScoreSummary(c iris.Context) { serviceName := strings.ToLower(c.Params().Get("name"))