This commit is contained in:
@@ -2,6 +2,7 @@ package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
contract "git.cin.su/m/Assistant/contracts/continuity"
|
||||
)
|
||||
@@ -10,12 +11,37 @@ var (
|
||||
ErrProspectiveNotFound = errors.New("prospective item not found")
|
||||
ErrProspectiveRevision = errors.New("prospective item revision conflict")
|
||||
ErrInvalidTransition = errors.New("invalid prospective item transition")
|
||||
ErrInvalidSatisfaction = errors.New("invalid delivered satisfaction command")
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
items map[contract.ProspectiveItemID]contract.ProspectiveItem
|
||||
}
|
||||
|
||||
func ValidateSatisfyDelivered(command contract.SatisfyDeliveredCommand) error {
|
||||
if command.ActionIntentID == "" || command.AuthorizedActionID == "" || command.OwnerPrincipalID == "" ||
|
||||
command.Subject.ProspectiveItemID == "" || command.Subject.ExpectedRevision == 0 ||
|
||||
command.Subject.FromState != contract.ProspectiveDelivered || command.Subject.ToState != contract.ProspectiveSatisfied ||
|
||||
strings.TrimSpace(command.Subject.EvidenceRef) == "" {
|
||||
return ErrInvalidSatisfaction
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) SatisfyDelivered(id contract.ProspectiveItemID, revision contract.ProspectiveRevision, evidenceRef string) (contract.ProspectiveItem, error) {
|
||||
item, err := s.current(id, revision)
|
||||
if err != nil {
|
||||
return contract.ProspectiveItem{}, err
|
||||
}
|
||||
if item.State != contract.ProspectiveDelivered || strings.TrimSpace(evidenceRef) == "" {
|
||||
return contract.ProspectiveItem{}, ErrInvalidTransition
|
||||
}
|
||||
item.State = contract.ProspectiveSatisfied
|
||||
item.Revision++
|
||||
s.items[id] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func Recover(items []contract.ProspectiveItem) Store {
|
||||
stored := make(map[contract.ProspectiveItemID]contract.ProspectiveItem, len(items))
|
||||
for _, item := range items {
|
||||
|
||||
Reference in New Issue
Block a user