- pricingid null: lookupDoormilePrice now returns matched rule ID; wired to BookingServiceOption.Pricingid - Zone rename: Interstate→Regional, OtherState→National throughout (code + DB migrated) - Zone from pincodes: CheckPrice now accepts pickup_pincode+delivery_pincode and auto-resolves zone - Delivery geocoding: pincodeToLatLon() maps 3-digit prefix to city coords when lat/lon are 0 - Device tokens: device_token field added to PinVerify DTOs; saved on both customer and miler login - Assignment retry: RejectMilerAssignment now re-triggers AssignCustomerMiler/AssignCRMMiler immediately - Provider empty B2C: defaults to Doormile when no pricing provider row matches - City gate 422→400: StatusUnprocessableEntity corrected to StatusBadRequest - Miler GPS 0,0: WS tracking falls back to MilerProfile DB coords when Redis key is expired Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
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.StatusBadRequest).JSON(fiber.Map{
|
|
"error": "We are not yet operating in your city. Stay tuned!",
|
|
"code": "CITY_NOT_SUPPORTED",
|
|
})
|
|
}
|