You've already forked orderservice
chore: refactored project according to clean architecture
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user