2026-03-27 06:08:55 -07:00
|
|
|
package api
|
2026-02-27 16:51:41 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2026-03-06 22:45:53 +00:00
|
|
|
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
|
|
|
|
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
2026-02-27 16:51:41 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
2026-03-03 17:08:58 +00:00
|
|
|
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
2026-03-12 23:49:16 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
2026-03-06 22:45:53 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2026-02-27 16:51:41 +00:00
|
|
|
)
|
|
|
|
|
|
2026-03-06 22:45:53 +00:00
|
|
|
type formArcgisConfiguration struct {
|
|
|
|
|
MapService *string `schema:"map-service"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 23:49:16 +00:00
|
|
|
func postConfigurationIntegrationArcgis(ctx context.Context, r *http.Request, u platform.User, f formArcgisConfiguration) (string, *nhttp.ErrorWithStatus) {
|
2026-03-06 22:45:53 +00:00
|
|
|
if f.MapService != nil {
|
|
|
|
|
_, err := psql.Update(
|
|
|
|
|
um.Table("organization"),
|
|
|
|
|
um.SetCol("arcgis_map_service_id").ToArg(f.MapService),
|
2026-03-22 01:22:44 +00:00
|
|
|
um.Where(psql.Quote("id").EQ(psql.Arg(u.Organization.ID))),
|
2026-03-06 22:45:53 +00:00
|
|
|
).Exec(ctx, db.PGInstance.BobDB)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", nhttp.NewError("Failed to update map service config: %w", err)
|
|
|
|
|
}
|
2026-03-22 01:22:44 +00:00
|
|
|
log.Info().Str("map-service", *f.MapService).Int32("org-id", u.Organization.ID).Msg("changed map service")
|
2026-03-06 22:45:53 +00:00
|
|
|
} else {
|
|
|
|
|
log.Info().Msg("no map service")
|
|
|
|
|
}
|
|
|
|
|
return "/configuration/integration/arcgis", nil
|
|
|
|
|
}
|