Skip to content

Commit

Permalink
Added a new error message for blocking action
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Makarihkin committed Oct 10, 2023
1 parent 4c22b8f commit e14dafc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
7 changes: 7 additions & 0 deletions internal/handlers/equipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""))
Expand Down
33 changes: 17 additions & 16 deletions internal/messages/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e14dafc

Please sign in to comment.