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
+38
View File
@@ -0,0 +1,38 @@
package inquiry
import (
"errors"
"strings"
"tm/pkg/response"
"github.com/labstack/echo/v4"
)
func handleBindError(c echo.Context, err error) error {
return response.BadRequest(c, "Invalid request format", err.Error())
}
func handleValidationError(c echo.Context, err error) error {
return response.ValidationError(c, "Please fix the validation errors", FormatValidationErrors(err))
}
func handleServiceError(c echo.Context, err error, fallback string) error {
if err == nil {
return nil
}
if errors.Is(err, ErrInquiryNotFound) {
return response.NotFound(c, "Inquiry not found")
}
var transitionErr *InvalidStatusTransitionError
if errors.As(err, &transitionErr) {
return response.BadRequest(c, transitionErr.Error(), "")
}
if strings.Contains(err.Error(), "cannot be updated") {
return response.BadRequest(c, err.Error(), "")
}
return response.InternalServerError(c, fallback)
}