Files
Suriya c91c887726 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>
2026-06-25 12:31:53 +05:30

56 lines
1.6 KiB
Go

package assignment
import (
"fmt"
"strconv"
"doormile/db"
"doormile/internal/notify"
"doormile/models"
"doormile/utils"
)
// notifyMilerNewAssignment sends an FCM push to the miler when a booking is assigned.
// Non-fatal: failure is logged but never blocks the assignment flow.
func notifyMilerNewAssignment(profile models.MilerProfile, bookingID int) {
if profile.Devicetoken == "" {
return
}
if err := notify.SendToDevice(
profile.Devicetoken,
"New Pickup Assigned",
"New booking assigned — tap to view details",
map[string]string{"booking_id": strconv.Itoa(bookingID)},
); err != nil {
utils.Warn("FCM: failed to notify miler on assignment",
"miler_id", profile.Userid,
"booking_id", bookingID,
"error", err,
)
}
}
// notifyCustomerMilerAssigned sends an FCM push to the customer when their miler is assigned.
// Loads the customer's device token from DB. Non-fatal on any failure.
func notifyCustomerMilerAssigned(booking *models.PickupBooking, milerName string) {
var customer models.AppCustomer
if err := db.DB.Where("appcustomerid = ?", booking.Appcustomerid).First(&customer).Error; err != nil {
return
}
if customer.Devicetoken == "" {
return
}
if err := notify.SendToDevice(
customer.Devicetoken,
"Miler Assigned",
fmt.Sprintf("Miler assigned — %s is on the way", milerName),
map[string]string{"booking_id": strconv.Itoa(booking.Bookingid)},
); err != nil {
utils.Warn("FCM: failed to notify customer on assignment",
"customer_id", booking.Appcustomerid,
"booking_id", booking.Bookingid,
"error", err,
)
}
}