diff --git a/http/controller.download.go b/http/controller.download.go index 8a4041f..7499380 100644 --- a/http/controller.download.go +++ b/http/controller.download.go @@ -12,11 +12,18 @@ import ( ) type DownloadController struct { - service domain.DownloadServiceInterface + downloadService domain.DownloadServiceInterface + softwareService domain.SoftwareServiceInterface } -func NewDownloadController(service domain.DownloadServiceInterface) *DownloadController { - return &DownloadController{service: service} +func NewDownloadController( + downloadService domain.DownloadServiceInterface, + softwareService domain.SoftwareServiceInterface, +) *DownloadController { + return &DownloadController{ + downloadService: downloadService, + softwareService: softwareService, + } } func (c *DownloadController) serve(w http.ResponseWriter, r *http.Request, release *domain.Release, is_source bool) { @@ -62,7 +69,7 @@ func (c *DownloadController) handleError(w http.ResponseWriter, err error) { func (c *DownloadController) GetLatestSource(w http.ResponseWriter, r *http.Request) { name := chi.URLParam(r, "name") - release, err := c.service.GetLatestRelease(name) + release, err := c.downloadService.GetLatestRelease(name) if err != nil { c.handleError(w, err) return @@ -73,7 +80,7 @@ func (c *DownloadController) GetLatestSource(w http.ResponseWriter, r *http.Requ func (c *DownloadController) GetLatestCartridge(w http.ResponseWriter, r *http.Request) { name := chi.URLParam(r, "name") - release, err := c.service.GetLatestRelease(name) + release, err := c.downloadService.GetLatestRelease(name) if err != nil { c.handleError(w, err) return @@ -85,7 +92,7 @@ func (c *DownloadController) GetLatestCartridge(w http.ResponseWriter, r *http.R func (c *DownloadController) GetSource(w http.ResponseWriter, r *http.Request) { name := chi.URLParam(r, "name") version := chi.URLParam(r, "version") - release, err := c.service.GetSpecificRelease(name, version) + release, err := c.downloadService.GetSpecificRelease(name, version) if err != nil { c.handleError(w, err) return @@ -97,7 +104,7 @@ func (c *DownloadController) GetSource(w http.ResponseWriter, r *http.Request) { func (c *DownloadController) GetCartridge(w http.ResponseWriter, r *http.Request) { name := chi.URLParam(r, "name") version := chi.URLParam(r, "version") - release, err := c.service.GetSpecificRelease(name, version) + release, err := c.downloadService.GetSpecificRelease(name, version) if err != nil { c.handleError(w, err) return diff --git a/http/controller.play.go b/http/controller.play.go index a1ba78f..7b7367b 100644 --- a/http/controller.play.go +++ b/http/controller.play.go @@ -49,6 +49,12 @@ func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) { return } + softwares, err := c.softwareService.List() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + tmpl, err := template_utils.GetTemplate("play_controller_play", "http/views/shared/layout.html", "http/views/play/play.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -58,6 +64,7 @@ func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) { tmpl.Execute(w, map[string]interface{}{ "Software": software, "WebPlayableRelease": web_playable_release, + "Softwares": softwares, }) } diff --git a/http/controller.root.go b/http/controller.root.go index ce51a59..3b9e9f4 100644 --- a/http/controller.root.go +++ b/http/controller.root.go @@ -8,14 +8,25 @@ import ( ) type RootController struct { - service domain.SoftwareServiceInterface + softwareService domain.SoftwareServiceInterface } -func NewRootController() *RootController { - return &RootController{} +func NewRootController(softwareService domain.SoftwareServiceInterface) *RootController { + return &RootController{ + softwareService: softwareService, + } } func (c *RootController) Index(w http.ResponseWriter, r *http.Request) { + softwares, err := c.softwareService.List() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + data := map[string]interface{}{ + "Softwares": softwares, + } tmpl, err := template_utils.GetTemplate("root_index", "http/views/shared/layout.html", "http/views/root/index.html") if err != nil { @@ -23,5 +34,5 @@ func (c *RootController) Index(w http.ResponseWriter, r *http.Request) { return } - tmpl.Execute(w, nil) + tmpl.Execute(w, data) } diff --git a/http/controller.software.go b/http/controller.software.go index 379ec13..a811726 100644 --- a/http/controller.software.go +++ b/http/controller.software.go @@ -24,24 +24,42 @@ func (c *SoftwareController) Index(w http.ResponseWriter, r *http.Request) { return } + data := map[string]interface{}{ + "Softwares": softwares, + } + tmpl, err := template_utils.GetTemplate("software_index", "http/views/shared/layout.html", "http/views/software/index.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - tmpl.Execute(w, softwares) + tmpl.Execute(w, data) } func (c *SoftwareController) Show(w http.ResponseWriter, r *http.Request) { name := chi.URLParam(r, "name") - data, err := c.softwareService.GetForShowByName(name) + showData, err := c.softwareService.GetForShowByName(name) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } + softwares, err := c.softwareService.List() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + data := map[string]interface{}{ + "Software": showData.Software, + "Releases": showData.Releases, + "LatestRelease": showData.LatestRelease, + "WebPlayableRelease": showData.WebPlayableRelease, + "Softwares": softwares, + } + 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) diff --git a/http/controller.software_updater.go b/http/controller.software_updater.go index 66763d5..35aff1a 100644 --- a/http/controller.software_updater.go +++ b/http/controller.software_updater.go @@ -8,11 +8,18 @@ import ( ) type SoftwareUpdaterController struct { - service domain.SoftwareUpdaterServiceInterface + softwareUpdaterService domain.SoftwareUpdaterServiceInterface + softwareService domain.SoftwareServiceInterface } -func NewSoftwareUpdaterController(service domain.SoftwareUpdaterServiceInterface) *SoftwareUpdaterController { - return &SoftwareUpdaterController{service: service} +func NewSoftwareUpdaterController( + softwareUpdaterService domain.SoftwareUpdaterServiceInterface, + softwareService domain.SoftwareServiceInterface, +) *SoftwareUpdaterController { + return &SoftwareUpdaterController{ + softwareUpdaterService: softwareUpdaterService, + softwareService: softwareService, + } } func (c *SoftwareUpdaterController) Update(w http.ResponseWriter, r *http.Request) { @@ -31,7 +38,7 @@ func (c *SoftwareUpdaterController) Update(w http.ResponseWriter, r *http.Reques return } - if err := c.service.Update(platform, name, version); err != nil { + if err := c.softwareUpdaterService.Update(platform, name, version); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } diff --git a/http/http.go b/http/http.go index 93dbd2f..d6dc8b0 100755 --- a/http/http.go +++ b/http/http.go @@ -8,10 +8,10 @@ import ( func StartHttpServer(domain_instance domain.Domain) { router := NewRouter( NewSoftwareController(domain_instance.SoftwareService), - NewSoftwareUpdaterController(domain_instance.SoftwareUpdaterService), - NewDownloadController(domain_instance.DownloadService), + NewSoftwareUpdaterController(domain_instance.SoftwareUpdaterService, domain_instance.SoftwareService), + NewDownloadController(domain_instance.DownloadService, domain_instance.SoftwareService), NewPlayController(domain_instance.SoftwareService, domain_instance.FileService), - NewRootController(), + NewRootController(domain_instance.SoftwareService), ).Init() http_utils.StartGenericHTTPServer(http_utils.StartGenericHTTPServerContext{ diff --git a/http/views/root/index.html b/http/views/root/index.html index 30647f0..1821947 100644 --- a/http/views/root/index.html +++ b/http/views/root/index.html @@ -2,12 +2,7 @@
- Welcome to Teletype Games! This site is dedicated to showcasing open-source indie games, - created with enthusiasm and as a hobby project. -
-- Explore our collection of unique games, navigate using the top menu to access the Home page, - discover more Softwares, or check out our Youtube channel. + Welcome to Teletype Games! We are an independent, community-driven game development collective. Our mission is to create small, experimental, and full-fledged games in short development cycles while keeping everything open, transparent, and collaborative.
{{end}} diff --git a/http/views/shared/layout.html b/http/views/shared/layout.html index 31e8b4f..f4f3d0c 100644 --- a/http/views/shared/layout.html +++ b/http/views/shared/layout.html @@ -20,9 +20,6 @@{{.Software.Desc}}
-Version: {{.LatestRelease.Version}}
-License: {{.Software.License}}
- +| Title | +{{.Software.Title}} | +
|---|---|
| Author | +{{.Software.Author}} | +
| Description | +{{.Software.Desc}} | +
| Version | +{{.LatestRelease.Version}} | +
| License | +{{.Software.License}} | +
| Website | +{{.Software.Site}} | +