Add district-specific nuisance reporting page.
This commit is contained in:
parent
93079c5c8e
commit
2066840a40
4 changed files with 29 additions and 7 deletions
|
|
@ -1,8 +1,12 @@
|
|||
package rmo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type ContentDistrict struct {
|
||||
|
|
@ -11,6 +15,13 @@ type ContentDistrict struct {
|
|||
URLWebsite string
|
||||
}
|
||||
|
||||
func districtBySlug(r *http.Request) (*models.Organization, error) {
|
||||
slug := chi.URLParam(r, "slug")
|
||||
district, err := models.Organizations.Query(
|
||||
models.SelectWhere.Organizations.Slug.EQ(slug),
|
||||
).One(r.Context(), db.PGInstance.BobDB)
|
||||
return district, err
|
||||
}
|
||||
func newContentDistrict(d *models.Organization) *ContentDistrict {
|
||||
if d == nil {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -48,6 +48,22 @@ func getNuisance(w http.ResponseWriter, r *http.Request) {
|
|||
},
|
||||
)
|
||||
}
|
||||
func getNuisanceDistrict(w http.ResponseWriter, r *http.Request) {
|
||||
district, err := districtBySlug(r)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to lookup organization", err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
html.RenderOrError(
|
||||
w,
|
||||
NuisanceT,
|
||||
ContentNuisance{
|
||||
District: newContentDistrict(district),
|
||||
MapboxToken: config.MapboxToken,
|
||||
URL: makeContentURL(nil),
|
||||
},
|
||||
)
|
||||
}
|
||||
func getSubmitComplete(w http.ResponseWriter, r *http.Request) {
|
||||
report_id := r.URL.Query().Get("report")
|
||||
district, err := report.DistrictForReport(r.Context(), report_id)
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
|
@ -67,10 +65,7 @@ func getRoot(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
}
|
||||
func getRootDistrict(w http.ResponseWriter, r *http.Request) {
|
||||
slug := chi.URLParam(r, "slug")
|
||||
district, err := models.Organizations.Query(
|
||||
models.SelectWhere.Organizations.Slug.EQ(slug),
|
||||
).One(r.Context(), db.PGInstance.BobDB)
|
||||
district, err := districtBySlug(r)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to lookup organization", err, http.StatusBadRequest)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ func Router() chi.Router {
|
|||
r.Get("/submit-complete", getSubmitComplete)
|
||||
|
||||
r.Get("/district/{slug}", getRootDistrict)
|
||||
//r.Get("/district/{slug}/nuisance", renderMock(mockNuisanceT))
|
||||
r.Get("/district/{slug}/nuisance", getNuisanceDistrict)
|
||||
//r.Get("/district/{slug}/nuisance-submit-complete", renderMock(mockNuisanceSubmitCompleteT))
|
||||
//r.Get("/district/{slug}/status", renderMock(mockStatusT))
|
||||
//r.Get("/district/{slug}/water", renderMock(mockWaterT))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue