diff --git a/rmo/mock.go b/rmo/mock.go index a49554bd..7d6a6599 100644 --- a/rmo/mock.go +++ b/rmo/mock.go @@ -22,13 +22,6 @@ type ContentDistrict struct { URLLogo string URLWebsite string } -type ContentURL struct { - Nuisance string - NuisanceSubmitComplete string - Status string - Tegola string - Water string -} type ContentMock struct { District ContentDistrict MapboxToken string @@ -48,7 +41,7 @@ func addMockRoutes(r chi.Router) { r.Get("/status", renderMock(mockStatusT)) } -func makeContentURL(slug string) ContentURL { +func makeContentURLMock(slug string) ContentURL { return ContentURL{ Nuisance: makeURLMock(slug, "nuisance"), NuisanceSubmitComplete: makeURLMock(slug, "nuisance-submit-complete"), @@ -77,7 +70,7 @@ func renderMock(t *html.BuiltTemplate) func(http.ResponseWriter, *http.Request) }, MapboxToken: config.MapboxToken, ReportID: "abcd-1234-5678", - URL: makeContentURL(slug), + URL: makeContentURLMock(slug), }, ) } diff --git a/rmo/root.go b/rmo/root.go index 18b5284f..b9edf4ab 100644 --- a/rmo/root.go +++ b/rmo/root.go @@ -15,7 +15,16 @@ type ContentPrivacy struct { Site string URLReport string } -type ContentRoot struct{} +type ContentRoot struct { + URL ContentURL +} +type ContentURL struct { + Nuisance string + NuisanceSubmitComplete string + Status string + Tegola string + Water string +} var ( PrivacyT = buildTemplate("privacy", "base") @@ -23,6 +32,14 @@ var ( TermsT = buildTemplate("terms", "base") ) +func boolFromForm(r *http.Request, k string) bool { + s := r.PostFormValue(k) + if s == "on" { + return true + } + return false +} + func getPrivacy(w http.ResponseWriter, r *http.Request) { html.RenderOrError( w, @@ -48,27 +65,26 @@ func getRobots(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Allow: /\n") } func getTerms(w http.ResponseWriter, r *http.Request) { - htmlpage.RenderOrError( + html.RenderOrError( w, TermsT, ContentRoot{}, ) } -// Respond with an error that is visible to the user -func respondError(w http.ResponseWriter, m string, e error, s int) { - log.Warn().Int("status", s).Err(e).Str("user message", m).Msg("Responding with an error") - http.Error(w, m, s) -} - -func boolFromForm(r *http.Request, k string) bool { - s := r.PostFormValue(k) - if s == "on" { - return true +func makeContentURL(slug string) ContentURL { + return ContentURL{ + Nuisance: makeURL("nuisance"), + NuisanceSubmitComplete: makeURL("nuisance-submit-complete"), + Status: makeURL("status"), + Tegola: config.MakeURLTegola("/"), + Water: makeURL("water"), } - return false } +func makeURL(p string) string { + return config.MakeURLReport("/%s", p) +} func postFormValueOrNone(r *http.Request, k string) string { v := r.PostFormValue(k) if v == "" { @@ -76,3 +92,9 @@ func postFormValueOrNone(r *http.Request, k string) string { } return v } + +// Respond with an error that is visible to the user +func respondError(w http.ResponseWriter, m string, e error, s int) { + log.Warn().Int("status", s).Err(e).Str("user message", m).Msg("Responding with an error") + http.Error(w, m, s) +}