updates on the env and pagination

This commit is contained in:
2026-09-15 17:08:22 +05:30
parent 5c73d769ca
commit bf5a9026fe
5 changed files with 287 additions and 2 deletions

View File

@@ -1127,7 +1127,18 @@ func GetTenantCustomers(c *fiber.Ctx) error {
func GetAdminCustomers(c *fiber.Ctx) error {
pageno := max(1, c.QueryInt("pageno", 1))
pagesize := min(100, max(1, c.QueryInt("pagesize", 20)))
// Ceiling comes from utils.MaxPageSize rather than a literal, so this
// endpoint and utils.ParsePage cannot disagree about what a caller may
// ask for. The hard-coded 100 here silently capped every client that
// asked for more: the console drains this list a page at a time and
// requests 1000, so it was issuing ten times the round trips for the
// same rows and hitting its own page budget at 1,200 — past which the
// counts it renders are floors, not totals.
//
// The DEFAULT stays 20. Callers that do not ask for a page size keep
// exactly the response they get today; only a caller that explicitly
// requests more sees any change.
pagesize := min(utils.MaxPageSize, max(1, c.QueryInt("pagesize", 20)))
offset := (pageno - 1) * pagesize
keyword := c.Query("keyword")
@@ -2099,7 +2110,18 @@ func applyDestinationCounts(bookings []models.PickupBooking, counts []bookingDes
func GetAdminBookings(c *fiber.Ctx) error {
pageno := max(1, c.QueryInt("pageno", 1))
pagesize := min(100, max(1, c.QueryInt("pagesize", 20)))
// Ceiling comes from utils.MaxPageSize rather than a literal, so this
// endpoint and utils.ParsePage cannot disagree about what a caller may
// ask for. The hard-coded 100 here silently capped every client that
// asked for more: the console drains this list a page at a time and
// requests 1000, so it was issuing ten times the round trips for the
// same rows and hitting its own page budget at 1,200 — past which the
// counts it renders are floors, not totals.
//
// The DEFAULT stays 20. Callers that do not ask for a page size keep
// exactly the response they get today; only a caller that explicitly
// requests more sees any change.
pagesize := min(utils.MaxPageSize, max(1, c.QueryInt("pagesize", 20)))
offset := (pageno - 1) * pagesize
tenantID, allowed := effectiveTenantID(c)
@@ -2133,8 +2155,27 @@ func GetAdminBookings(c *fiber.Ctx) error {
// sort needs no tiebreaker and the paging cannot wobble between equal
// timestamps. It also matches the order the console already sorts into
// client-side, so page 1 is the newest page by both definitions.
// Destinations ride the list, not just the detail read.
//
// A customer-app booking is one pickup carrying N drops, and the console's
// Bookings page is the screen that shows them. Without this the list could
// only report `destinationcount` and the row's mirrored destination 0, so a
// three-drop pickup looked identical to a one-drop pickup until somebody
// opened the drawer — which is the whole reason that page was reaching for
// the customer app's own endpoint instead.
//
// One extra query for the page (GORM batches a Preload with an IN clause),
// not one per row, and ordered by seq because seq is the customer-facing
// position: it is the {index} in
// PATCH /customer/bookings/{ref}/destinations/{index}, so the order the
// console renders has to be the order the customer addresses. Same preload
// GetAdminBookingDetails already uses, so the list and the drawer cannot
// disagree about a booking's drops.
var bookings []models.PickupBooking
if err := query.Preload("Parcels").Preload("ServiceOptions").
Preload("Destinations", func(d *gorm.DB) *gorm.DB {
return d.Order("seq ASC")
}).
Order("bookingid DESC").
Offset(offset).Limit(pagesize).Find(&bookings).Error; err != nil {
return utils.Internal(c, "failed to fetch bookings")