You've already forked orderservice
33 lines
652 B
Go
33 lines
652 B
Go
package domain
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
ErrOrderAlreadyExist = errors.New("order already exist")
|
|
ErrOrderNotFound = errors.New("order not found")
|
|
ErrInvalidOrderData = errors.New("invalid order data")
|
|
)
|
|
|
|
type Order struct {
|
|
ID string
|
|
Item string
|
|
Quantity int32
|
|
}
|
|
|
|
func (o *Order) Validate() error {
|
|
if strings.TrimSpace(o.Item) == "" {
|
|
return fmt.Errorf("%w: item cannot be empty", ErrInvalidOrderData)
|
|
}
|
|
if o.Quantity <= 0 {
|
|
return fmt.Errorf("%w: quantity must be positive", ErrInvalidOrderData)
|
|
}
|
|
if o.ID == "" {
|
|
return fmt.Errorf("%w: ID cannot be empty", ErrInvalidOrderData)
|
|
}
|
|
return nil
|
|
}
|