updates on the admincontroller and the hubcity fix and queue orders
This commit is contained in:
@@ -352,6 +352,32 @@ func UpdateMilerProfile(c *fiber.Ctx) error {
|
||||
return utils.OK(c, profile)
|
||||
}
|
||||
|
||||
// indexMilerLocation records a rider's position where auto-assignment looks
|
||||
// for riders: the `miler:gps:{userid}` key and the `milers:locations` GEO set
|
||||
// that internal/assignment GEOSEARCHes around a pickup.
|
||||
//
|
||||
// Used by UpdateMilerLocation and MilerStartDuty. Before, only the location
|
||||
// ping wrote here, so a rider who had tapped "Start duty" was Available in the
|
||||
// database but invisible to assignment until their app sent its first GPS
|
||||
// ping — orders created in that gap were never offered to them.
|
||||
func indexMilerLocation(milerUserID int, lat, lon float64) {
|
||||
if db.Rdb == nil || lat == 0 || lon == 0 {
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
redisKey := fmt.Sprintf("miler:gps:%d", milerUserID)
|
||||
val := fmt.Sprintf("%f,%f", lat, lon)
|
||||
db.Rdb.Set(ctx, redisKey, val, 30*time.Minute)
|
||||
|
||||
db.Rdb.GeoAdd(ctx, "milers:locations", &redis.GeoLocation{
|
||||
Name: strconv.Itoa(milerUserID),
|
||||
Latitude: lat,
|
||||
Longitude: lon,
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateMilerLocation(c *fiber.Ctx) error {
|
||||
milerUserID := c.Locals("userid").(int)
|
||||
|
||||
@@ -380,20 +406,7 @@ func UpdateMilerLocation(c *fiber.Ctx) error {
|
||||
return utils.Internal(c, "failed to update location")
|
||||
}
|
||||
|
||||
if db.Rdb != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
redisKey := fmt.Sprintf("miler:gps:%d", milerUserID)
|
||||
val := fmt.Sprintf("%f,%f", req.Latitude, req.Longitude)
|
||||
db.Rdb.Set(ctx, redisKey, val, 30*time.Minute)
|
||||
|
||||
db.Rdb.GeoAdd(ctx, "milers:locations", &redis.GeoLocation{
|
||||
Name: strconv.Itoa(milerUserID),
|
||||
Latitude: req.Latitude,
|
||||
Longitude: req.Longitude,
|
||||
})
|
||||
}
|
||||
indexMilerLocation(milerUserID, req.Latitude, req.Longitude)
|
||||
|
||||
return utils.OK(c, fiber.Map{
|
||||
"latitude": req.Latitude,
|
||||
|
||||
Reference in New Issue
Block a user