Add changelog page

This commit is contained in:
pluja 2024-09-09 15:26:40 +02:00
parent e80f52fc63
commit 7533475b72
No known key found for this signature in database
5 changed files with 78 additions and 0 deletions

View File

@ -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"`
}

View File

@ -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{

View File

@ -0,0 +1,28 @@
<section class="container px-4 py-12 mx-auto">
<h1 class="mb-10 text-3xl font-bold text-center text-white/80">Changelog</h1>
<div class="space-y-4">
{{ range .Changes }}
<div class="overflow-hidden border rounded-md border-white/20">
<div class="p-4">
<div class="flex items-center justify-between mb-4">
<h3 class="text-base font-semibold text-white/80">{{.Title}}</h3>
<span class="text-xs text-white/40">{{.Created}}</span>
</div>
<p class="mb-4 text-sm text-white/70">{{.Summary | safe}}</p>
{{ if .Expand.service }}
<div class="pt-2 mt-1 border-t border-white/10">
{{ with .Expand.service }}
<span class="text-sm text-white/50">
Related service: <a class="underline transition-colors duration-200 text-lime-700 hover:text-blue-300"
href="/service/{{.Name}}">{{ .Name }}</a>
</span>
{{ end }}
</div>
{{end}}
</div>
</div>
{{ end }}
</div>
</section>

View File

@ -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)

View File

@ -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("<h3>%s</h3>", 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("<h3>%s</h3>", err.Error())
return
}
}
func (s *Server) handleScoreSummary(c iris.Context) {
serviceName := strings.ToLower(c.Params().Get("name"))