lint: remove unused code across api, comms, h3utils, html, middleware, minio, platform, rmo
Deleted files: api/compliance.go, api/debug.go, rmo/compliance.go, rmo/email.go, rmo/mock.go, platform/publicreport/address.go Removed unused functions/types from: api/api.go, api/configuration.go, api/district.go, api/publicreport.go, api/sudo.go, api/types.go, comms/text/twilio.go, comms/text/voipms.go, h3utils/h3.go, html/embed.go, html/form.go, middleware/terminal.go, minio/client.go, platform/csv/csv.go, platform/csv/flyover.go, platform/file/base.go, platform/file/upload.go, platform/geocode/address.go, platform/types/service_request.go
This commit is contained in:
parent
d74c24339e
commit
53a3f9816a
25 changed files with 6 additions and 975 deletions
34
api/api.go
34
api/api.go
|
|
@ -14,7 +14,6 @@ import (
|
|||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/resource"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/version"
|
||||
//"github.com/gorilla/mux"
|
||||
|
|
@ -188,39 +187,6 @@ func apiTrapData(w http.ResponseWriter, r *http.Request, u platform.User) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiServiceRequest(w http.ResponseWriter, r *http.Request, u platform.User) {
|
||||
bounds, err := parseBounds(r)
|
||||
if err != nil {
|
||||
err = renderShim(w, r, errRender(err))
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
query := db.NewGeoQuery()
|
||||
query.Bounds = *bounds
|
||||
query.Limit = 100
|
||||
requests, err := platform.ServiceRequestQuery()
|
||||
if err != nil {
|
||||
err = renderShim(w, r, errRender(err))
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
data := []Renderable{}
|
||||
for _, sr := range requests {
|
||||
data = append(data, types.ServiceRequestFromModel(sr))
|
||||
}
|
||||
if err := renderList(w, r, data); err != nil {
|
||||
err = renderShim(w, r, errRender(err))
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseBounds(r *http.Request) (*db.GeoBounds, error) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,109 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"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/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/paulmach/orb/geojson"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
func getComplianceRequestImagePool(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
code := vars["public_id"]
|
||||
if code == "" {
|
||||
http.Error(w, "empty public_id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
/*
|
||||
comp, err := models.ComplianceReportRequests.Query(
|
||||
models.Preload.ComplianceReportRequest.Lead(),
|
||||
models.SelectWhere.ComplianceReportRequests.PublicID.EQ(code),
|
||||
).One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
http.Error(w, "no comp", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
lead := comp.R.Lead
|
||||
site := lead.R.Site
|
||||
*/
|
||||
type _Row struct {
|
||||
Envelope string `db:"parcel_envelope"`
|
||||
OrganizationID int32 `db:"organization_id"`
|
||||
}
|
||||
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
"ST_AsGeoJSON(ST_Envelope(parcel.geometry)) AS parcel_envelope",
|
||||
"organization.id AS organization_id",
|
||||
),
|
||||
sm.From("compliance_report_request"),
|
||||
sm.InnerJoin("lead").OnEQ(
|
||||
psql.Quote("compliance_report_request.lead_id"),
|
||||
psql.Quote("organization.id"),
|
||||
),
|
||||
sm.InnerJoin("organization").OnEQ(
|
||||
psql.Quote("lead.organization_id"),
|
||||
psql.Quote("organization.id"),
|
||||
),
|
||||
sm.InnerJoin("site").On(
|
||||
psql.Quote("lead.site_id").EQ(psql.Quote("site.id")),
|
||||
),
|
||||
sm.InnerJoin("parcel").OnEQ(
|
||||
psql.Quote("site.parcel_id"),
|
||||
psql.Quote("parcel.id"),
|
||||
),
|
||||
sm.Where(psql.Quote("compliance_report_request").EQ(psql.Arg(code))),
|
||||
), scan.StructMapper[_Row]())
|
||||
org, err := platform.OrganizationByID(ctx, int(row.OrganizationID))
|
||||
if err != nil {
|
||||
http.Error(w, "org err", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if org == nil {
|
||||
http.Error(w, "no org", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
var polygon geojson.Polygon
|
||||
err = json.Unmarshal([]byte(row.Envelope), &polygon)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("unmarshal json")
|
||||
http.Error(w, "unmarshal envelope json", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ring := polygon[0]
|
||||
p := ring[0]
|
||||
err = writeImage(ctx, w, *org, 19, p[1], p[0])
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("write image")
|
||||
http.Error(w, "failed to write image", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
func writeImage(ctx context.Context, w http.ResponseWriter, org platform.Organization, level uint, lat, lng float64) error {
|
||||
img, err := platform.ImageAtPoint(ctx, org, level, lat, lng)
|
||||
if err != nil {
|
||||
return fmt.Errorf("image at point: %w", err)
|
||||
}
|
||||
log.Info().Int("size", len(img.Content)).Msg("image")
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(img.Content)))
|
||||
_, err = io.Copy(w, bytes.NewBuffer(img.Content))
|
||||
if err != nil {
|
||||
return fmt.Errorf("copy bytes: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -7,122 +7,11 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/arcgis/model"
|
||||
queryarcgis "github.com/Gleipnir-Technology/nidus-sync/db/query/arcgis"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type contentConfigurationRoot struct{}
|
||||
|
||||
func getConfigurationRoot(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentConfigurationRoot], *nhttp.ErrorWithStatus) {
|
||||
return html.NewResponse("sync/configuration/root.html", contentConfigurationRoot{}), nil
|
||||
}
|
||||
|
||||
type contentSettingOrganization struct {
|
||||
Organization platform.Organization
|
||||
}
|
||||
|
||||
type contentSettingIntegration struct {
|
||||
ArcGISAccount *model.Account
|
||||
ArcGISOAuth *model.OAuthToken
|
||||
ServiceMaps []model.ServiceMap
|
||||
}
|
||||
|
||||
func getConfigurationOrganization(ctx context.Context, r *http.Request, u platform.User) (*html.Response[contentSettingOrganization], *nhttp.ErrorWithStatus) {
|
||||
/*
|
||||
var district contentDistrict
|
||||
district, err = bob.One[contentDistrict](ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.From("import.district"),
|
||||
sm.Columns(
|
||||
"address",
|
||||
"agency",
|
||||
"area_4326_sqm",
|
||||
"city1",
|
||||
"city2",
|
||||
"contact",
|
||||
"fax1",
|
||||
"general_mg",
|
||||
"gid",
|
||||
"phone1",
|
||||
"phone2",
|
||||
"postal_c_1",
|
||||
"website",
|
||||
psql.F("ST_AsGeoJSON", "centroid_4326"),
|
||||
psql.F("ST_XMin", "extent_4326"),
|
||||
psql.F("ST_YMin", "extent_4326"),
|
||||
psql.F("ST_XMax", "extent_4326"),
|
||||
psql.F("ST_YMax", "extent_4326"),
|
||||
),
|
||||
sm.Where(psql.Quote("gid").EQ(psql.Arg(gid))),
|
||||
), scan.StructMapper[contentDistrict]())
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get extents", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
*/
|
||||
data := contentSettingOrganization{
|
||||
Organization: u.Organization,
|
||||
}
|
||||
return html.NewResponse("sync/configuration/organization.html", data), nil
|
||||
}
|
||||
func getConfigurationIntegration(ctx context.Context, r *http.Request, u platform.User) (*html.Response[contentSettingIntegration], *nhttp.ErrorWithStatus) {
|
||||
oauth, err := platform.GetOAuthForUser(ctx, u)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get oauth: %w", err)
|
||||
}
|
||||
data := contentSettingIntegration{
|
||||
ArcGISOAuth: oauth,
|
||||
}
|
||||
return html.NewResponse("sync/configuration/integration.html", data), nil
|
||||
}
|
||||
func getConfigurationIntegrationArcgis(ctx context.Context, r *http.Request, u platform.User) (*html.Response[contentSettingIntegration], *nhttp.ErrorWithStatus) {
|
||||
oauth, err := platform.GetOAuthForUser(ctx, u)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get oauth: %w", err)
|
||||
}
|
||||
var account model.Account
|
||||
var service_maps []model.ServiceMap
|
||||
account_id := u.Organization.ArcgisAccountID()
|
||||
if account_id != "" {
|
||||
account, err = queryarcgis.AccountFromID(ctx, account_id)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get arcgis: %w", err)
|
||||
}
|
||||
service_maps, err = queryarcgis.ServiceMapsFromAccountID(ctx, account.ID)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get map services: %w", err)
|
||||
}
|
||||
}
|
||||
data := contentSettingIntegration{
|
||||
ArcGISAccount: &account,
|
||||
ArcGISOAuth: oauth,
|
||||
ServiceMaps: service_maps,
|
||||
}
|
||||
return html.NewResponse("sync/configuration/integration-arcgis.html", data), nil
|
||||
}
|
||||
|
||||
type contentSettingPlaceholder struct{}
|
||||
|
||||
func getConfigurationPesticide(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentSettingPlaceholder], *nhttp.ErrorWithStatus) {
|
||||
content := contentSettingPlaceholder{}
|
||||
return html.NewResponse("sync/configuration/pesticide.html", content), nil
|
||||
}
|
||||
func getConfigurationPesticideAdd(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentSettingPlaceholder], *nhttp.ErrorWithStatus) {
|
||||
content := contentSettingPlaceholder{}
|
||||
return html.NewResponse("sync/configuration/pesticide-add.html", content), nil
|
||||
}
|
||||
func getConfigurationUserAdd(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentSettingPlaceholder], *nhttp.ErrorWithStatus) {
|
||||
content := contentSettingPlaceholder{}
|
||||
return html.NewResponse("sync/configuration/user-add.html", content), nil
|
||||
}
|
||||
func getConfigurationUserList(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentSettingPlaceholder], *nhttp.ErrorWithStatus) {
|
||||
content := contentSettingPlaceholder{}
|
||||
return html.NewResponse("sync/configuration/user-list.html", content), nil
|
||||
}
|
||||
|
||||
type formArcgisConfiguration struct {
|
||||
MapService *string `schema:"map-service"`
|
||||
}
|
||||
|
|
|
|||
26
api/debug.go
26
api/debug.go
|
|
@ -1,26 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func debugSaveRequest(r *http.Request) {
|
||||
tmpFile, err := os.CreateTemp("/tmp", "request-*.data")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to create temp file for debugSaveRequest")
|
||||
return
|
||||
}
|
||||
defer lint.LogOnErr(tmpFile.Close, "close temp file")
|
||||
|
||||
_, err = io.Copy(tmpFile, r.Body)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to copy request body in debugSaveRequest")
|
||||
return
|
||||
}
|
||||
log.Info().Str("filename", tmpFile.Name()).Msg("Saved request body")
|
||||
}
|
||||
|
|
@ -1,67 +1,14 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/file"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func apiGetDistrict(w http.ResponseWriter, r *http.Request) {
|
||||
var latStr, lngStr string
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
if err := renderShim(w, r, errRender(fmt.Errorf("Failed to parse GET form: %w", err))); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
} else {
|
||||
latStr = r.FormValue("lat")
|
||||
lngStr = r.FormValue("lng")
|
||||
}
|
||||
lat, err := strconv.ParseFloat(latStr, 64)
|
||||
if err != nil {
|
||||
if err := renderShim(w, r, errRender(fmt.Errorf("Failed to parse lat as float: %w", err))); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
lng, err := strconv.ParseFloat(lngStr, 64)
|
||||
if err != nil {
|
||||
if err := renderShim(w, r, errRender(fmt.Errorf("Failed to parse lng as float: %w", err))); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
org, err := platform.DistrictForLocation(r.Context(), lng, lat)
|
||||
if err != nil {
|
||||
if err := renderShim(w, r, errRender(fmt.Errorf("Failed to get district: %w", err))); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
if org == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
d := ResponseDistrict{
|
||||
Agency: org.Name,
|
||||
Manager: org.GeneralManagerName.GetOr(""),
|
||||
Phone: org.OfficePhone.GetOr(""),
|
||||
Website: org.Website.GetOr(""),
|
||||
}
|
||||
if err := renderShim(w, r, d); err != nil {
|
||||
if err := renderShim(w, r, errRender(err)); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func apiGetDistrictLogo(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
slug := vars["slug"]
|
||||
|
|
|
|||
|
|
@ -21,10 +21,6 @@ func postPublicreportSignal(ctx context.Context, r *http.Request, user platform.
|
|||
return fmt.Sprintf("/signal/%d", *signal_id), nil
|
||||
}
|
||||
|
||||
type formPublicreportInvalid struct {
|
||||
ReportID string `json:"reportID"`
|
||||
}
|
||||
|
||||
func postPublicreportInvalid(ctx context.Context, r *http.Request, user platform.User, req formPublicreportSignal) (string, *nhttp.ErrorWithStatus) {
|
||||
err := platform.PublicReportInvalid(ctx, user, req.ReportID)
|
||||
if err != nil {
|
||||
|
|
|
|||
20
api/sudo.go
20
api/sudo.go
|
|
@ -8,31 +8,11 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/comms/email"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/comms/text"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type contentSudo struct {
|
||||
ForwardEmailRMOAddress string
|
||||
ForwardEmailNidusAddress string
|
||||
}
|
||||
|
||||
func getSudo(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentSudo], *nhttp.ErrorWithStatus) {
|
||||
if !user.HasRoot() {
|
||||
return nil, &nhttp.ErrorWithStatus{
|
||||
Message: "You have to be a root user to access this",
|
||||
Status: http.StatusForbidden,
|
||||
}
|
||||
}
|
||||
content := contentSudo{
|
||||
ForwardEmailRMOAddress: config.ForwardEmailRMOAddress,
|
||||
ForwardEmailNidusAddress: config.ForwardEmailNidusAddress,
|
||||
}
|
||||
return html.NewResponse("sync/sudo.html", content), nil
|
||||
}
|
||||
|
||||
type FormEmail struct {
|
||||
Body string `schema:"emailBody"`
|
||||
From string `schema:"emailFrom"`
|
||||
|
|
|
|||
18
api/types.go
18
api/types.go
|
|
@ -15,10 +15,6 @@ import (
|
|||
|
||||
type H3Cell uint64
|
||||
|
||||
type hasCreated interface {
|
||||
getCreated() string
|
||||
}
|
||||
|
||||
type Bounds struct {
|
||||
East float64
|
||||
North float64
|
||||
|
|
@ -300,16 +296,4 @@ func toBool16(t null.Val[int16]) *bool {
|
|||
}
|
||||
return &b
|
||||
}
|
||||
func toBool(t null.Val[int32]) *bool {
|
||||
if t.IsNull() {
|
||||
return nil
|
||||
}
|
||||
val := t.MustGet()
|
||||
var b bool
|
||||
if val == 0 {
|
||||
b = false
|
||||
} else {
|
||||
b = true
|
||||
}
|
||||
return &b
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue