cerrado @ 8f5f9ff24b0327f7640e3619de109e1f19cfba1d

 1package git
 2
 3import (
 4	"log/slog"
 5	"net/http"
 6
 7	"git.gabrielgio.me/cerrado/pkg/service"
 8	"git.gabrielgio.me/cerrado/templates"
 9	"github.com/gorilla/mux"
10)
11
12type (
13	GitHandler struct {
14		gitService gitService
15	}
16
17	gitService interface {
18		ListRepositories() ([]*service.Repository, error)
19	}
20)
21
22func NewGitHandler(gitService gitService) *GitHandler {
23	return &GitHandler{
24		gitService: gitService,
25	}
26}
27
28func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) {
29	repos, err := g.gitService.ListRepositories()
30	if err != nil {
31		slog.Error("Error listing repo", "error", err)
32		return
33	}
34
35	gitList := &templates.GitListPage{repos}
36	templates.WritePageTemplate(w, gitList)
37}
38
39func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) {
40	name := mux.Vars(r)["name"]
41	gitList := &templates.GitItemPage{
42		Name:        name,
43		GitItemBase: &templates.GitItemSummaryPage{},
44	}
45	templates.WritePageTemplate(w, gitList)
46}
47
48func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) {
49	name := mux.Vars(r)["name"]
50	gitList := &templates.GitItemPage{
51		Name:        name,
52		GitItemBase: &templates.GitItemAboutPage{},
53	}
54	templates.WritePageTemplate(w, gitList)
55}
56
57func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) {
58	name := mux.Vars(r)["name"]
59	gitList := &templates.GitItemPage{
60		Name:        name,
61		GitItemBase: &templates.GitItemRefsPage{},
62	}
63	templates.WritePageTemplate(w, gitList)
64}
65
66func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) {
67	name := mux.Vars(r)["name"]
68	gitList := &templates.GitItemPage{
69		Name:        name,
70		GitItemBase: &templates.GitItemTreePage{},
71	}
72	templates.WritePageTemplate(w, gitList)
73}
74
75func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) {
76	name := mux.Vars(r)["name"]
77	gitList := &templates.GitItemPage{
78		Name:        name,
79		GitItemBase: &templates.GitItemLogPage{},
80	}
81	templates.WritePageTemplate(w, gitList)
82}