lint: remove unused code from platform/arcgis.go, platform/text, rmo
- Remove 7 unused functions from platform/arcgis.go (generateCodeChallenge, generateCodeVerifier, newTimestampedFilename, logResponseHeaders, saveResponse, saveOrUpdateDBRecords, rowmapViaQuery) plus orphaned stubs - Delete platform/text/db.go (entirely unused) - Remove insertTextLog from platform/text/send.go - Delete rmo/image.go, rmo/mailer.go, rmo/scss.go, rmo/district.go, rmo/water.go
This commit is contained in:
parent
9ce5058e85
commit
b9a68aab04
8 changed files with 0 additions and 566 deletions
|
|
@ -1,69 +0,0 @@
|
|||
package rmo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"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/gorilla/mux"
|
||||
)
|
||||
|
||||
type ContentDistrict struct {
|
||||
Name string
|
||||
OfficePhone string
|
||||
URLLogo string
|
||||
URLRMO string
|
||||
URLWebsite string
|
||||
}
|
||||
type ContentDistrictList struct {
|
||||
Districts []ContentDistrict
|
||||
URL ContentURL
|
||||
}
|
||||
|
||||
func districtBySlug(r *http.Request) (*models.Organization, error) {
|
||||
vars := mux.Vars(r)
|
||||
slug := vars["slug"]
|
||||
district, err := models.Organizations.Query(
|
||||
models.SelectWhere.Organizations.Slug.EQ(slug),
|
||||
).One(r.Context(), db.PGInstance.BobDB)
|
||||
return district, err
|
||||
}
|
||||
func getDistrictList(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
rows, err := models.Organizations.Query(
|
||||
models.SelectWhere.Organizations.ImportDistrictGid.IsNotNull(),
|
||||
sm.OrderBy("name"),
|
||||
).All(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
respondError(w, "failed to query for districts", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
districts := make([]ContentDistrict, 0)
|
||||
for _, row := range rows {
|
||||
districts = append(districts, *newContentDistrict(row))
|
||||
}
|
||||
html.RenderOrError(
|
||||
w,
|
||||
"rmo/district-list.html",
|
||||
ContentDistrictList{
|
||||
Districts: districts,
|
||||
URL: makeContentURL(nil),
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
func newContentDistrict(d *models.Organization) *ContentDistrict {
|
||||
if d == nil {
|
||||
return nil
|
||||
}
|
||||
return &ContentDistrict{
|
||||
Name: d.Name,
|
||||
OfficePhone: "123-456-7890",
|
||||
URLLogo: config.MakeURLNidus("/api/district/%s/logo", d.Slug.GetOr("unset")),
|
||||
URLRMO: config.MakeURLReport("/district/%s", d.Slug.GetOr("unset")),
|
||||
URLWebsite: d.Website.GetOr(""),
|
||||
}
|
||||
}
|
||||
25
rmo/image.go
25
rmo/image.go
|
|
@ -1,25 +0,0 @@
|
|||
package rmo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/file"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// ServeImageByUUID reads an image with the given UUID from disk and writes it to the HTTP response
|
||||
func getImageByUUID(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
u := vars["uuid"]
|
||||
if u == "" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
uid, err := uuid.Parse(u)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to parse uuid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
file.ImageFileToWriter(file.CollectionPublicImage, uid, w)
|
||||
}
|
||||
155
rmo/mailer.go
155
rmo/mailer.go
|
|
@ -1,155 +0,0 @@
|
|||
package rmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/scan"
|
||||
//"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
)
|
||||
|
||||
type address struct {
|
||||
Country string `db:"country"`
|
||||
Locality string `db:"locality"`
|
||||
LocationGeoJSON string `db:"location_geo_json"`
|
||||
Number int32 `db:"number_"`
|
||||
OrganizationSlug string `db:"slug"`
|
||||
PostalCode string `db:"postal_code"`
|
||||
Region string `db:"region"`
|
||||
Street string `db:"street"`
|
||||
}
|
||||
type contentMailer struct {
|
||||
Address address
|
||||
PublicID string
|
||||
URLLogo string
|
||||
}
|
||||
|
||||
func getMailer(ctx context.Context, r *http.Request) (*html.Response[contentMailer], *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["public_id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewErrorStatus(http.StatusBadRequest, "No 'public_id' in the url params")
|
||||
}
|
||||
|
||||
/*
|
||||
compliance_request, err := models.ComplianceReportRequests.Query(
|
||||
models.Preload.ComplianceReportRequest.Site(),
|
||||
models.SelectWhere.ComplianceReportRequests.PublicID.EQ(public_id),
|
||||
).One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
respondError(w, "failed to get compliance request", err, http.StatusBadRequest)
|
||||
}
|
||||
site := compliance_request.
|
||||
*/
|
||||
report, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
"address.number_",
|
||||
"address.street",
|
||||
"address.locality",
|
||||
"ST_AsGeoJSON(address.geom) AS location_geo_json",
|
||||
"address.region",
|
||||
"address.postal_code",
|
||||
"address.country",
|
||||
"organization.slug",
|
||||
),
|
||||
sm.From("compliance_report_request").As("crr"),
|
||||
sm.InnerJoin("lead").OnEQ(psql.Quote("crr", "lead_id"), psql.Quote("lead", "id")),
|
||||
sm.InnerJoin("site").OnEQ(psql.Quote("lead", "site_id"), psql.Quote("site", "id")),
|
||||
sm.InnerJoin("organization").OnEQ(psql.Quote("lead", "organization_id"), psql.Quote("organization", "id")),
|
||||
sm.InnerJoin("address").OnEQ(psql.Quote("site", "address_id"), psql.Quote("address", "id")),
|
||||
sm.Where(psql.Quote("crr", "public_id").EQ(psql.Arg(public_id))),
|
||||
), scan.StructMapper[address]())
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("failed to get compliance report")
|
||||
return nil, nhttp.NewErrorStatus(http.StatusNotFound, "No compliance report with that public ID")
|
||||
}
|
||||
return html.NewResponse(
|
||||
"rmo/mailer/root.html", contentMailer{
|
||||
Address: report,
|
||||
PublicID: public_id,
|
||||
URLLogo: config.MakeURLNidus("/api/district/%s/logo", report.OrganizationSlug),
|
||||
},
|
||||
), nil
|
||||
|
||||
}
|
||||
func getMailerConfirm(ctx context.Context, r *http.Request) (*html.Response[contentMailer], *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["public_id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewErrorStatus(http.StatusBadRequest, "No 'public_id' in the url params")
|
||||
}
|
||||
return html.NewResponse(
|
||||
"rmo/mailer/confirm.html", contentMailer{
|
||||
PublicID: public_id,
|
||||
},
|
||||
), nil
|
||||
}
|
||||
func getMailerContribute(ctx context.Context, r *http.Request) (*html.Response[contentMailer], *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["public_id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewErrorStatus(http.StatusBadRequest, "No 'public_id' in the url params")
|
||||
}
|
||||
return html.NewResponse(
|
||||
"rmo/mailer/contribute.html", contentMailer{
|
||||
PublicID: public_id,
|
||||
},
|
||||
), nil
|
||||
}
|
||||
func getMailerEvidence(ctx context.Context, r *http.Request) (*html.Response[contentMailer], *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["public_id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewErrorStatus(http.StatusBadRequest, "No 'public_id' in the url params")
|
||||
}
|
||||
return html.NewResponse(
|
||||
"rmo/mailer/evidence.html", contentMailer{
|
||||
PublicID: public_id,
|
||||
},
|
||||
), nil
|
||||
}
|
||||
func getMailerSchedule(ctx context.Context, r *http.Request) (*html.Response[contentMailer], *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["public_id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewErrorStatus(http.StatusBadRequest, "No 'public_id' in the url params")
|
||||
}
|
||||
return html.NewResponse(
|
||||
"rmo/mailer/schedule.html", contentMailer{
|
||||
PublicID: public_id,
|
||||
},
|
||||
), nil
|
||||
}
|
||||
func getMailerUpdate(ctx context.Context, r *http.Request) (*html.Response[contentMailer], *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["public_id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewErrorStatus(http.StatusBadRequest, "No 'public_id' in the url params")
|
||||
}
|
||||
return html.NewResponse(
|
||||
"rmo/mailer/update.html", contentMailer{
|
||||
PublicID: public_id,
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
type formMailerConfirm struct{}
|
||||
|
||||
func postMailerConfirm(ctx context.Context, r *http.Request, form formMailerConfirm) (string, *nhttp.ErrorWithStatus) {
|
||||
log.Info().Msg("Fake confirm location")
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["public_id"]
|
||||
if public_id == "" {
|
||||
return "", nhttp.NewErrorStatus(http.StatusBadRequest, "No 'public_id' in the url params")
|
||||
}
|
||||
return config.MakeURLReport("/mailer/%s/evidence", public_id), nil
|
||||
}
|
||||
42
rmo/scss.go
42
rmo/scss.go
|
|
@ -1,42 +0,0 @@
|
|||
package rmo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func getScssDebug(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
path := vars["*"]
|
||||
full_path := "scss/" + path
|
||||
//log.Debug().Str("path", path).Str("full_path", full_path).Msg("working on SCSS debug")
|
||||
file, err := os.Open(full_path)
|
||||
if err != nil {
|
||||
respondError(w, "failed to open file", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer lint.LogOnErr(file.Close, "close scss file")
|
||||
fileInfo, err := file.Stat()
|
||||
if err != nil {
|
||||
respondError(w, "failed to stat file", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// Set appropriate headers
|
||||
w.Header().Set("Content-Type", "text/scss")
|
||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", fileInfo.Size()))
|
||||
// Copy file contents to response writer
|
||||
_, err = io.Copy(w, file)
|
||||
if err != nil {
|
||||
// Note: At this point, we've already started writing the response,
|
||||
// so we can't change the status code anymore. The best we can do
|
||||
// is log the error and abandon the connection.
|
||||
log.Warn().Str("path", path).Msg("Failed to write scss file to output")
|
||||
}
|
||||
}
|
||||
38
rmo/water.go
38
rmo/water.go
|
|
@ -1,38 +0,0 @@
|
|||
package rmo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
)
|
||||
|
||||
type ContentWater struct {
|
||||
District *ContentDistrict
|
||||
URL ContentURL
|
||||
}
|
||||
|
||||
func getWater(w http.ResponseWriter, r *http.Request) {
|
||||
html.RenderOrError(
|
||||
w,
|
||||
"rmo/water.html",
|
||||
ContentWater{
|
||||
District: nil,
|
||||
URL: makeContentURL(nil),
|
||||
},
|
||||
)
|
||||
}
|
||||
func getWaterDistrict(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,
|
||||
"rmo/water.html",
|
||||
ContentWater{
|
||||
District: newContentDistrict(district),
|
||||
URL: makeContentURL(district),
|
||||
},
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue