fa3d466579
- Added a new error for submission sync failures, improving error handling in the tender approval process. - Updated the `ToggleTenderApproval` method to handle the new error, providing clearer responses for sync issues. - Introduced a method to reopen terminal submissions when tender approvals are resubmitted, enhancing submission state management. - Implemented optimistic locking in the repository to prevent concurrent updates, improving data integrity. - Added unit tests for new submission handling logic, ensuring robust functionality and error management. This update strengthens the tender approval workflow and submission handling, ensuring better error reporting and state management.
47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
package tender_submission
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
ErrTenderSubmissionNotFound = errors.New("tender submission not found")
|
|
ErrTenderSubmissionExists = errors.New("tender submission already exists for this tender and company")
|
|
ErrInvalidStatus = errors.New("invalid tender submission status")
|
|
ErrInvalidStage = errors.New("invalid tender submission stage")
|
|
ErrTenderNotFound = errors.New("tender not found")
|
|
ErrApprovalRequired = errors.New("tender must be approved before starting submission workflow")
|
|
ErrInvalidStatusTransition = errors.New("invalid status transition")
|
|
ErrTerminalStatus = errors.New("tender submission is in a terminal state and cannot be updated")
|
|
ErrConcurrentUpdate = errors.New("tender submission was modified concurrently")
|
|
)
|
|
|
|
// InvalidStatusTransitionError is returned when a status change is not allowed.
|
|
type InvalidStatusTransitionError struct {
|
|
CurrentStatus string
|
|
NewStatus string
|
|
Allowed []string
|
|
}
|
|
|
|
func (e *InvalidStatusTransitionError) Error() string {
|
|
if len(e.Allowed) == 0 {
|
|
return fmt.Sprintf("Tender submission status is already %s and cannot be changed", e.CurrentStatus)
|
|
}
|
|
return fmt.Sprintf(
|
|
"Cannot change tender submission status from %s to %s. Allowed next statuses: %s",
|
|
e.CurrentStatus,
|
|
e.NewStatus,
|
|
strings.Join(e.Allowed, ", "),
|
|
)
|
|
}
|
|
|
|
func NewInvalidStatusTransitionError(currentStatus, newStatus string, allowed []string) *InvalidStatusTransitionError {
|
|
return &InvalidStatusTransitionError{
|
|
CurrentStatus: currentStatus,
|
|
NewStatus: newStatus,
|
|
Allowed: allowed,
|
|
}
|
|
}
|