Miler app P0 + contract gaps found in the live audit: - GET /miler/bookings now returns consignmentid + consignmentstatus on every row (nullable), so the app can call deliver/skip/start-delivery straight from the list. /miler/assignments is the active-only queue, so this is the authoritative fix for stops that have moved onto the delivery leg. - GET /miler/bookings now returns sequencedat per row: non-null means the console/optimizer fixed this stop's order and the app follows step exactly; null means no route assigned and the app may fall back to nearest-first. - Route sequencing (internal/routing) now runs automatically after every assignment — customer auto-assign, express auto-assign, manual assign, and accept — via SequenceMilerStopsAsync (fire-and-forget, no-op below two active stops). Previously only hub batch-assign sequenced, so most riders saw step=0. - GET /admin/bookings now surfaces the live consignmentstatus alongside the frozen booking status, so a Converted_To_Consignment booking can still show Out_for_Delivery / Delivered instead of a generic "Active". Two-step hyperlocal flow (Arrived_At_Pickup, Collected_By_Miler, start-delivery) stays gated behind MILER_COLLECTED_STATE_ENABLED (default off) until the app ships; consignmentid/status, GET /miler/consignments/:id, stable error codes and Idempotency-Key handling are unconditional and safe on the current app. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WRaFH5hMRqmUQvVPQsyjZD
53 lines
1.9 KiB
Go
53 lines
1.9 KiB
Go
package utils
|
|
|
|
import "github.com/gofiber/fiber/v2"
|
|
|
|
func OK(c *fiber.Ctx, data interface{}) error {
|
|
return c.JSON(fiber.Map{"success": true, "data": data})
|
|
}
|
|
|
|
func Created(c *fiber.Ctx, data interface{}) error {
|
|
return c.Status(fiber.StatusCreated).JSON(fiber.Map{"success": true, "data": data})
|
|
}
|
|
|
|
func List(c *fiber.Ctx, data interface{}, total int64) error {
|
|
return c.JSON(fiber.Map{"success": true, "data": data, "total": total})
|
|
}
|
|
|
|
func Message(c *fiber.Ctx, msg string) error {
|
|
return c.JSON(fiber.Map{"success": true, "message": msg})
|
|
}
|
|
|
|
func BadRequest(c *fiber.Ctx, msg string) error {
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"success": false, "message": msg})
|
|
}
|
|
|
|
func Unauthorized(c *fiber.Ctx, msg string) error {
|
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"success": false, "message": msg})
|
|
}
|
|
|
|
func Forbidden(c *fiber.Ctx, msg string) error {
|
|
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{"success": false, "message": msg})
|
|
}
|
|
|
|
func NotFound(c *fiber.Ctx, msg string) error {
|
|
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"success": false, "message": msg})
|
|
}
|
|
|
|
func Conflict(c *fiber.Ctx, msg string) error {
|
|
return c.Status(fiber.StatusConflict).JSON(fiber.Map{"success": false, "message": msg})
|
|
}
|
|
|
|
func Internal(c *fiber.Ctx, msg string) error {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"success": false, "message": msg})
|
|
}
|
|
|
|
// Fail is the error response for clients that branch on a stable, machine-
|
|
// readable code rather than the human message. The message stays for logs and
|
|
// fallback display; `code` is the contract (see constants.Err*). Use this on
|
|
// endpoints whose failures the app has to distinguish programmatically; the
|
|
// bare BadRequest/NotFound/... helpers remain fine where it doesn't.
|
|
func Fail(c *fiber.Ctx, status int, code, msg string) error {
|
|
return c.Status(status).JSON(fiber.Map{"success": false, "code": code, "message": msg})
|
|
}
|