new sw show template

This commit is contained in:
2026-01-28 18:53:14 +01:00
parent b6466061bd
commit 123af105f4
10 changed files with 125 additions and 64 deletions
+5 -26
View File
@@ -17,7 +17,7 @@ func NewSoftwareController(software_service domain.SoftwareServiceInterface) *So
return &SoftwareController{softwareService: software_service}
}
func (c *SoftwareController) index(w http.ResponseWriter, r *http.Request) {
func (c *SoftwareController) Index(w http.ResponseWriter, r *http.Request) {
softwares, err := c.softwareService.List()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -33,41 +33,20 @@ func (c *SoftwareController) index(w http.ResponseWriter, r *http.Request) {
tmpl.Execute(w, softwares)
}
type SoftwareShowData struct {
Software *domain.Software
LatestRelease *domain.Release
}
func (c *SoftwareController) show(w http.ResponseWriter, r *http.Request) {
func (c *SoftwareController) Show(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name")
software, err := c.softwareService.GetByName(name)
data, err := c.softwareService.GetForShowByName(name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if software == nil {
http.NotFound(w, r)
return
}
latest_release, err := c.softwareService.GetLatestRelease(software.Name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if latest_release == nil {
http.NotFound(w, r)
return
}
tmpl, err := template_utils.GetTemplate("software_show", "http/views/shared/layout.html", "http/views/software/show.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpl.Execute(w, SoftwareShowData{
Software: software,
LatestRelease: latest_release,
})
tmpl.Execute(w, data)
}