0cce9ef1b5
- Introduced the `tender_submission` domain, including entity, repository, service, and handler implementations for managing tender submissions. - Added new routes for both admin and public access to tender submissions, allowing for listing, ensuring, and retrieving submissions by ID and tender. - Enhanced the tender approval service to synchronize submission workflows with approval changes, ensuring proper state management. - Implemented validation and response structures for tender submission operations, improving API consistency and usability. - Added unit tests for tender submission status transitions and workflow logic, ensuring robust functionality. This update enhances the tender management system by providing comprehensive support for tender submissions, improving overall workflow and user experience.
46 lines
1.5 KiB
Go
46 lines
1.5 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")
|
|
)
|
|
|
|
// 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,
|
|
}
|
|
}
|