shifts
This commit is contained in:
@@ -73,6 +73,40 @@ func (ctl *PartnerController) GetPartners(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
// CreateRiderShift opens a working window in a delivery region.
|
||||
//
|
||||
// Riders cannot be hired without one, and until this existed the table could
|
||||
// only be read — a region that shipped with no shift rows was a region no rider
|
||||
// could ever be added to, with nothing in the product able to change that.
|
||||
//
|
||||
// The region comes from the body rather than the query because this is a write
|
||||
// and the whole shift is one object; `getridershifts` beside it reads the same
|
||||
// id from a param, which is the existing convention for reads here.
|
||||
func (ctl *PartnerController) CreateRiderShift(c *fiber.Ctx) error {
|
||||
|
||||
var shift models.Ridershifts
|
||||
if err := c.BodyParser(&shift); err != nil {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"status": false, "code": http.StatusBadRequest, "message": "Invalid request body",
|
||||
})
|
||||
}
|
||||
|
||||
result, err := ctl.partnerService.CreateRiderShift(shift)
|
||||
if err != nil {
|
||||
// 400, not 500. Every failure here is something the person typed — a
|
||||
// region that is not configured, a window that already exists, a time
|
||||
// that is not a time — and each message says which.
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"status": false, "code": http.StatusBadRequest, "message": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
return c.Status(http.StatusCreated).JSON(fiber.Map{
|
||||
"status": true, "code": http.StatusCreated,
|
||||
"message": "Shift created", "details": result,
|
||||
})
|
||||
}
|
||||
|
||||
func (ctl *PartnerController) GetRiderShifts(c *fiber.Ctx) error {
|
||||
|
||||
aid, _ := strconv.Atoi(c.Query("applocationid"))
|
||||
|
||||
Reference in New Issue
Block a user