Add inquiry status transition error handling and validation improvements
continuous-integration/drone/push Build is passing

- Introduced InvalidStatusTransitionError to handle invalid status transitions for inquiries, providing clearer error messages.
- Updated UpdateInquiryStatusForm to make the Reason field optional and added logic to set a default reason if not provided.
- Enhanced form validation tests to cover new status transition error scenarios and validation messages.
- Refactored handler methods to utilize new error handling functions for improved response management.

This update improves the robustness of inquiry status management by ensuring proper error handling and validation, enhancing user experience during status updates.
This commit is contained in:
Mazyar
2026-07-01 22:50:44 +03:30
parent 506ac01cda
commit eeafe2a625
9 changed files with 293 additions and 27 deletions
+2 -3
View File
@@ -251,17 +251,16 @@ func (s *inquiryService) validateStatusTransition(ctx context.Context, id string
allowedNextStatuses, exists := allowedTransitions[currentStatus]
if !exists {
return errors.New("invalid current status")
return fmt.Errorf("inquiry has unknown status %q and cannot be updated", currentStatus)
}
// Check if transition is allowed
for _, allowedStatus := range allowedNextStatuses {
if allowedStatus == newStatus {
return nil
}
}
return errors.New("invalid status transition: cannot change from " + currentStatus + " to " + newStatus)
return NewInvalidStatusTransitionError(currentStatus, newStatus, allowedNextStatuses)
}
// Search searches inquiries with search and filters