Add assignment engine, FCM, WebSockets, city gate, and internal APIs
- internal/assignment: GEORADIUS miler assignment with retry/escalation, customer-side provider scoring, FCM notifications on assign - internal/notify: Firebase Admin SDK (FCM) client initialisation - internal/ws: WebSocket handlers for live parcel tracking and customer↔miler chat - middlewares: city gate (pincode prefix validation), internal API key auth, WebSocket JWT auth - controllers: InternalNotify + InternalReassign for machine-to-machine calls; pricing helpers wired into CreateCustomerBooking and CreateCRMBooking - routes: /internal/*, /ws/bookings/:id/track, /ws/bookings/:id/chat - models/users, models/doormile_pricing: new fields for device tokens, assignment state, pricing bands - seed_data.sql: initial pricing seed rows .env and Firebase service-account JSON intentionally excluded. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
40
middlewares/city_gate.go
Normal file
40
middlewares/city_gate.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// operatingCityPrefixes maps supported 3-digit pincode prefixes to city names.
|
||||
var operatingCityPrefixes = map[string]string{
|
||||
"641": "Coimbatore",
|
||||
"600": "Chennai",
|
||||
"560": "Bengaluru",
|
||||
"500": "Hyderabad",
|
||||
}
|
||||
|
||||
// CityGateMiddleware rejects bookings from pincodes outside Doormile's operating cities.
|
||||
// It reads pickuppincode from the JSON body without consuming it, so the downstream
|
||||
// controller can still call c.BodyParser() as usual.
|
||||
func CityGateMiddleware(c *fiber.Ctx) error {
|
||||
var body struct {
|
||||
Pickuppincode string `json:"pickuppincode"`
|
||||
}
|
||||
if err := json.Unmarshal(c.Body(), &body); err != nil || body.Pickuppincode == "" {
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
pincode := strings.TrimSpace(body.Pickuppincode)
|
||||
if len(pincode) >= 3 {
|
||||
if _, ok := operatingCityPrefixes[pincode[:3]]; ok {
|
||||
return c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
||||
"error": "We are not yet operating in your city. Stay tuned!",
|
||||
"code": "CITY_NOT_SUPPORTED",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user