diff --git a/internal/handlers/equipment.go b/internal/handlers/equipment.go index 6043ff6..a2cfb8a 100644 --- a/internal/handlers/equipment.go +++ b/internal/handlers/equipment.go @@ -317,6 +317,13 @@ func (c Equipment) BlockEquipmentFunc(repository domain.EquipmentRepository) equ startDate := time.Time(s.Data.StartDate) endDate := time.Time(s.Data.EndDate) + currentDate := time.Now() + + if startDate.Before(currentDate) || endDate.Before(currentDate) { + return equipment.NewBlockEquipmentDefault(http.StatusBadRequest). + WithPayload(buildBadRequestErrorPayload(messages.ErrStartDateBeforeCurrentDate, "")) + } + if startDate.After(endDate) { return equipment.NewBlockEquipmentDefault(http.StatusBadRequest). WithPayload(buildBadRequestErrorPayload(messages.ErrStartDateAfterEnd, "")) diff --git a/internal/messages/messages.go b/internal/messages/messages.go index 8b310a4..d4837d3 100644 --- a/internal/messages/messages.go +++ b/internal/messages/messages.go @@ -45,22 +45,23 @@ var ( // Equipment - ErrCreateEquipment = "error while creating equipment" - ErrMapEquipment = "error while mapping equipment" - ErrGetEquipment = "error while getting equipment" - ErrEquipmentNotFound = "equipment not found" - ErrEquipmentArchive = "error while archiving equipment" - ErrEquipmentBlock = "error while blocking equipment" - ErrEquipmentUnblock = "error while unblocking equipment" - ErrDeleteEquipment = "error while deleting equipment" - ErrQueryTotalEquipments = "error while getting total of all equipments" - ErrQueryEquipments = "error while getting all equipments" - ErrUpdateEquipment = "error while updating equipment" - ErrFindEquipment = "error while finding equipment" - ErrEquipmentBlockForbidden = "you don't have rights to block the equipment" - ErrEquipmentUnblockForbidden = "you don't have rights to unblock the equipment" - ErrStartDateAfterEnd = "start date should be before end date" - MsgEquipmentDeleted = "equipment deleted" + ErrCreateEquipment = "error while creating equipment" + ErrMapEquipment = "error while mapping equipment" + ErrGetEquipment = "error while getting equipment" + ErrEquipmentNotFound = "equipment not found" + ErrEquipmentArchive = "error while archiving equipment" + ErrEquipmentBlock = "error while blocking equipment" + ErrEquipmentUnblock = "error while unblocking equipment" + ErrDeleteEquipment = "error while deleting equipment" + ErrQueryTotalEquipments = "error while getting total of all equipments" + ErrQueryEquipments = "error while getting all equipments" + ErrUpdateEquipment = "error while updating equipment" + ErrFindEquipment = "error while finding equipment" + ErrEquipmentBlockForbidden = "you don't have rights to block the equipment" + ErrEquipmentUnblockForbidden = "you don't have rights to unblock the equipment" + ErrStartDateAfterEnd = "start date should be before end date" + ErrStartDateBeforeCurrentDate = "Start date or end date must be after current date" + MsgEquipmentDeleted = "equipment deleted" // Order Status