2025-12-16 16:37:53 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/auth"
|
2026-03-27 08:39:38 -07:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform/file"
|
2026-04-01 18:12:46 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/resource"
|
2026-04-01 16:19:11 +00:00
|
|
|
"github.com/gorilla/mux"
|
2025-12-16 16:37:53 +00:00
|
|
|
)
|
|
|
|
|
|
2026-04-01 16:19:11 +00:00
|
|
|
func AddRoutes(r *mux.Router) {
|
2026-04-01 20:35:00 +00:00
|
|
|
router := resource.NewRouter(r)
|
2026-04-01 16:19:11 +00:00
|
|
|
//r.Use(render.SetContentType(render.ContentTypeJSON))
|
2026-03-27 06:08:55 -07:00
|
|
|
// Unauthenticated endpoints
|
2026-04-01 16:19:11 +00:00
|
|
|
r.HandleFunc("/signin", handlerJSONPost(postSignin))
|
2026-04-16 17:14:57 +00:00
|
|
|
r.Handle("/signout", authenticatedHandlerBasic(postSignout))
|
2026-04-01 16:19:11 +00:00
|
|
|
r.HandleFunc("/signup", handlerJSONPost(postSignup))
|
2026-03-27 06:08:55 -07:00
|
|
|
// Authenticated endpoints
|
2026-04-01 16:19:11 +00:00
|
|
|
r.Handle("/audio/{uuid}", auth.NewEnsureAuth(apiAudioPost)).Methods("POST")
|
|
|
|
|
r.Handle("/audio/{uuid}/content", auth.NewEnsureAuth(apiAudioContentPost)).Methods("POST")
|
2026-04-01 21:23:28 +00:00
|
|
|
avatar := resource.Avatar(router)
|
2026-04-02 15:09:59 +00:00
|
|
|
r.Handle("/avatar/{uuid}", authenticatedHandlerGetImage(avatar.ByUUIDGet)).Methods("GET").Name("avatar.ByUUIDGet")
|
2026-04-01 21:23:28 +00:00
|
|
|
r.Handle("/avatar", authenticatedHandlerPostMultipart(avatar.Create, file.CollectionAvatar)).Methods("POST")
|
2026-04-01 16:19:11 +00:00
|
|
|
r.Handle("/client/ios", auth.NewEnsureAuth(handleClientIos)).Methods("GET")
|
2026-04-01 18:12:46 +00:00
|
|
|
communication := resource.Communication(r)
|
|
|
|
|
r.Handle("/communication", authenticatedHandlerJSON(communication.List)).Methods("GET")
|
2026-04-16 10:15:28 +00:00
|
|
|
compliance_request := resource.ComplianceRequest(router)
|
|
|
|
|
r.Handle("/compliance-request/mailer", authenticatedHandlerJSONPost(compliance_request.CreateMailer)).Methods("POST")
|
2026-04-16 19:49:18 +00:00
|
|
|
r.HandleFunc("/compliance-request/image/pool/{public_id}", compliance_request.ImagePoolGet).Methods("GET")
|
|
|
|
|
//r.HandleFunc("/compliance-request/image/pool/{public_id}", getComplianceRequestImagePool).Methods("GET")
|
2026-04-01 16:19:11 +00:00
|
|
|
r.Handle("/configuration/integration/arcgis", authenticatedHandlerJSONPost(postConfigurationIntegrationArcgis)).Methods("POST")
|
|
|
|
|
r.Handle("/events", auth.NewEnsureAuth(streamEvents)).Methods("GET")
|
|
|
|
|
r.Handle("/image/{uuid}", auth.NewEnsureAuth(apiImagePost)).Methods("POST")
|
|
|
|
|
r.Handle("/image/{uuid}/content", auth.NewEnsureAuth(apiImageContentGet)).Methods("GET")
|
|
|
|
|
r.Handle("/image/{uuid}/content", auth.NewEnsureAuth(apiImageContentPost)).Methods("POST")
|
2026-04-02 17:39:16 +00:00
|
|
|
impersonation := resource.Impersonation(router)
|
|
|
|
|
r.Handle("/impersonation", authenticatedHandlerJSONPost(impersonation.Create)).Methods("POST")
|
2026-04-02 21:31:31 +00:00
|
|
|
r.Handle("/impersonation", authenticatedHandlerDelete(impersonation.Delete)).Methods("DELETE")
|
2026-04-01 18:12:46 +00:00
|
|
|
lead := resource.Lead(r)
|
|
|
|
|
r.Handle("/leads", authenticatedHandlerJSON(lead.List)).Methods("GET")
|
|
|
|
|
r.Handle("/leads", authenticatedHandlerJSONPost(lead.Create)).Methods("POST")
|
2026-04-21 19:19:39 +00:00
|
|
|
mailer := resource.Mailer(router)
|
|
|
|
|
r.Handle("/mailer", authenticatedHandlerJSONSlice(mailer.List)).Methods("GET")
|
|
|
|
|
r.Handle("/mailer/{id}", authenticatedHandlerJSONPost(mailer.ByIDGet)).Methods("GET").Name("mailer.ByIDGet")
|
2026-04-01 16:19:11 +00:00
|
|
|
r.Handle("/mosquito-source", auth.NewEnsureAuth(apiMosquitoSource)).Methods("GET")
|
2026-04-03 22:04:22 +00:00
|
|
|
|
2026-04-01 16:19:11 +00:00
|
|
|
r.Handle("/publicreport/invalid", authenticatedHandlerJSONPost(postPublicreportInvalid)).Methods("POST")
|
|
|
|
|
r.Handle("/publicreport/signal", authenticatedHandlerJSONPost(postPublicreportSignal)).Methods("POST")
|
|
|
|
|
r.Handle("/publicreport/message", authenticatedHandlerJSONPost(postPublicreportMessage)).Methods("POST")
|
|
|
|
|
r.Handle("/review/pool", authenticatedHandlerJSONPost(postReviewPool)).Methods("POST")
|
2026-04-01 18:12:46 +00:00
|
|
|
review_task := resource.ReviewTask(r)
|
|
|
|
|
r.Handle("/review-task", authenticatedHandlerJSON(review_task.List)).Methods("GET")
|
2026-04-16 10:15:28 +00:00
|
|
|
pr_compliance := resource.PublicReportCompliance(router)
|
|
|
|
|
r.HandleFunc("/rmo/compliance", handlerJSONPost(pr_compliance.Create)).Methods("POST")
|
2026-04-03 22:04:22 +00:00
|
|
|
nuisance := resource.Nuisance(router)
|
|
|
|
|
r.HandleFunc("/rmo/nuisance", handlerFormPost(nuisance.Create)).Methods("POST")
|
|
|
|
|
water := resource.Water(router)
|
|
|
|
|
r.HandleFunc("/rmo/water", handlerFormPost(water.Create)).Methods("POST")
|
2026-04-14 19:59:32 +00:00
|
|
|
service_request := resource.ServiceRequest(router)
|
|
|
|
|
r.Handle("/service-request", authenticatedHandlerJSONSlice(service_request.List)).Methods("GET")
|
2026-04-02 01:07:55 +00:00
|
|
|
session := resource.Session(router)
|
|
|
|
|
r.Handle("/session", authenticatedHandlerJSON(session.Get)).Methods("GET").Name("session.get")
|
2026-04-01 18:12:46 +00:00
|
|
|
signal := resource.Signal(r)
|
|
|
|
|
r.Handle("/signal", authenticatedHandlerJSON(signal.List)).Methods("GET")
|
2026-04-16 02:45:48 +00:00
|
|
|
site := resource.Site(router)
|
|
|
|
|
r.Handle("/site", authenticatedHandlerJSONSlice(site.List)).Methods("GET")
|
2026-04-17 15:20:17 +00:00
|
|
|
r.Handle("/site/{id}", authenticatedHandlerJSON(site.ByIDGet)).Methods("GET").Name("site.ByIDGet")
|
2026-04-14 19:59:32 +00:00
|
|
|
sync := resource.Sync(r)
|
|
|
|
|
r.Handle("/sync", authenticatedHandlerJSONSlice(sync.List)).Methods("GET")
|
2026-04-01 16:19:11 +00:00
|
|
|
r.Handle("/sudo/email", authenticatedHandlerJSONPost(postSudoEmail)).Methods("POST")
|
|
|
|
|
r.Handle("/sudo/sms", authenticatedHandlerJSONPost(postSudoSMS)).Methods("POST")
|
|
|
|
|
r.Handle("/sudo/sse", authenticatedHandlerJSONPost(postSudoSSE)).Methods("POST")
|
|
|
|
|
r.Handle("/trap-data", auth.NewEnsureAuth(apiTrapData)).Methods("GET")
|
|
|
|
|
r.Handle("/tile/{z}/{y}/{x}", auth.NewEnsureAuth(getTile)).Methods("GET")
|
2026-04-01 18:12:46 +00:00
|
|
|
upload := resource.Upload(r)
|
|
|
|
|
r.Handle("/upload/pool/custom", authenticatedHandlerPostMultipart(upload.PoolCustomCreate, file.CollectionCSV)).Methods("POST")
|
2026-04-15 18:25:12 +00:00
|
|
|
r.Handle("/upload/pool/flyover", authenticatedHandlerPostMultipart(upload.PoolFlyoverCreate, file.CollectionCSV)).Methods("POST")
|
2026-04-01 18:12:46 +00:00
|
|
|
r.Handle("/upload", authenticatedHandlerJSON(upload.List)).Methods("GET")
|
|
|
|
|
r.Handle("/upload/{id}", authenticatedHandlerJSON(upload.ByIDGet)).Methods("GET")
|
|
|
|
|
r.Handle("/upload/{id}/commit", authenticatedHandlerJSONPost(upload.Commit)).Methods("POST")
|
|
|
|
|
r.Handle("/upload/{id}/discard", authenticatedHandlerJSONPost(upload.Discard)).Methods("POST")
|
|
|
|
|
|
2026-04-01 20:35:00 +00:00
|
|
|
user := resource.User(router)
|
2026-04-01 18:12:46 +00:00
|
|
|
r.Handle("/user/self", authenticatedHandlerJSON(user.SelfGet)).Methods("GET")
|
|
|
|
|
r.Handle("/user/suggestion", authenticatedHandlerJSON(user.SuggestionGet)).Methods("GET")
|
2026-04-01 20:22:15 +00:00
|
|
|
r.Handle("/user", authenticatedHandlerJSONSlice(user.List)).Methods("GET")
|
|
|
|
|
r.Handle("/user/{id}", authenticatedHandlerJSON(user.ByIDGet)).Methods("GET").Name("user.ByIDGet")
|
2026-04-01 18:12:46 +00:00
|
|
|
r.Handle("/user/{id}", authenticatedHandlerJSONPut(user.ByIDPut)).Methods("PUT")
|
2025-12-16 16:37:53 +00:00
|
|
|
|
|
|
|
|
// Unauthenticated endpoints
|
2026-04-03 18:17:19 +00:00
|
|
|
district := resource.District(router)
|
|
|
|
|
r.Handle("/district", handlerJSONSlice(district.List)).Methods("GET")
|
2026-04-08 17:49:32 +00:00
|
|
|
r.Handle("/district/{id}", handlerJSON(district.GetByID)).Methods("GET").Name("district.ByIDGet")
|
2026-04-05 21:57:30 +00:00
|
|
|
geocode := resource.Geocode(router)
|
2026-04-06 16:53:26 +00:00
|
|
|
r.Handle("/geocode/by-gid/{id:.*}", handlerJSON(geocode.ByGID)).Methods("GET")
|
|
|
|
|
r.Handle("/geocode/reverse", handlerJSONPost(geocode.Reverse)).Methods("POST")
|
2026-04-05 21:57:30 +00:00
|
|
|
r.Handle("/geocode/suggestion", handlerJSONSlice(geocode.SuggestionList)).Methods("GET")
|
2026-04-08 17:49:32 +00:00
|
|
|
publicreport := resource.Publicreport(router)
|
2026-04-14 16:07:17 +00:00
|
|
|
r.Handle("/publicreport/{id}", handlerBasic(publicreport.ByID)).Methods("GET").Name("publicreport.ByIDGet")
|
2026-04-14 02:35:04 +00:00
|
|
|
r.Handle("/publicreport/compliance/{id}/image", handlerFormPost(publicreport.ImageCreate)).Methods("POST")
|
2026-04-16 10:15:28 +00:00
|
|
|
r.Handle("/publicreport/compliance/{id}", handlerJSON(pr_compliance.ByID)).Methods("GET").Name("publicreport.compliance.ByIDGet")
|
|
|
|
|
r.Handle("/publicreport/compliance/{id}", handlerJSONPut(pr_compliance.Update)).Methods("PUT")
|
2026-04-14 15:31:10 +00:00
|
|
|
r.Handle("/publicreport/nuisance/{id}", handlerJSON(nuisance.ByID)).Methods("GET").Name("publicreport.nuisance.ByIDGet")
|
|
|
|
|
r.Handle("/publicreport/water/{id}", handlerJSON(water.ByID)).Methods("GET").Name("publicreport.water.ByIDGet")
|
2026-04-12 17:01:30 +00:00
|
|
|
|
2026-04-08 17:49:32 +00:00
|
|
|
publicreport_notification := resource.PublicreportNotification(router)
|
|
|
|
|
r.Handle("/publicreport-notification", handlerJSONPost(publicreport_notification.Create)).Methods("POST")
|
2026-04-05 21:57:30 +00:00
|
|
|
|
2026-04-03 18:17:19 +00:00
|
|
|
//r.HandleFunc("/district", apiGetDistrict).Methods("GET")
|
|
|
|
|
r.HandleFunc("/district/{slug}/logo", apiGetDistrictLogo).Methods("GET").Name("district.logo.BySlug")
|
2026-04-01 16:19:11 +00:00
|
|
|
r.HandleFunc("/twilio/call", twilioCallPost).Methods("POST")
|
|
|
|
|
r.HandleFunc("/twilio/call/status", twilioCallStatusPost).Methods("POST")
|
|
|
|
|
r.HandleFunc("/twilio/message", twilioMessagePost).Methods("POST")
|
|
|
|
|
r.HandleFunc("/twilio/text", twilioTextPost).Methods("POST")
|
|
|
|
|
r.HandleFunc("/twilio/text/status", twilioTextStatusPost).Methods("POST")
|
|
|
|
|
r.HandleFunc("/voipms/text", voipmsTextGet).Methods("GET")
|
|
|
|
|
r.HandleFunc("/voipms/text", voipmsTextPost).Methods("POST")
|
|
|
|
|
r.HandleFunc("/webhook/fieldseeker", webhookFieldseeker).Methods("GET")
|
|
|
|
|
r.HandleFunc("/webhook/fieldseeker", webhookFieldseeker).Methods("POST")
|
2025-12-16 16:37:53 +00:00
|
|
|
}
|