mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-1] implement cart service
This commit is contained in:
9
cart/internal/domain/model/cart.go
Normal file
9
cart/internal/domain/model/cart.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
import "route256/cart/internal/domain/entity"
|
||||
|
||||
type Cart struct {
|
||||
UserID entity.UID
|
||||
Items []*Item
|
||||
TotalPrice uint32
|
||||
}
|
||||
10
cart/internal/domain/model/errors.go
Normal file
10
cart/internal/domain/model/errors.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package model
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrProductNotFound = errors.New("invalid sku")
|
||||
|
||||
ErrCartNotFound = errors.New("cart not found")
|
||||
ErrItemNotFoundInCart = errors.New("item not found in cart")
|
||||
)
|
||||
16
cart/internal/domain/model/items.go
Normal file
16
cart/internal/domain/model/items.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Item struct {
|
||||
Product *Product
|
||||
Count uint32 `validate:"gt=0"`
|
||||
}
|
||||
|
||||
func (i *Item) Validate() error {
|
||||
if err := validate.Struct(i); err != nil {
|
||||
return fmt.Errorf("invalid requested values: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
21
cart/internal/domain/model/product.go
Normal file
21
cart/internal/domain/model/product.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"route256/cart/internal/domain/entity"
|
||||
)
|
||||
|
||||
type Product struct {
|
||||
Name string
|
||||
Price int32
|
||||
Sku entity.Sku `validate:"gt=0"`
|
||||
}
|
||||
|
||||
func (p *Product) Validate() error {
|
||||
if err := validate.Struct(p); err != nil {
|
||||
return fmt.Errorf("invalid requested values: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
9
cart/internal/domain/model/validate.go
Normal file
9
cart/internal/domain/model/validate.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
import "github.com/go-playground/validator/v10"
|
||||
|
||||
var validate *validator.Validate
|
||||
|
||||
func init() {
|
||||
validate = validator.New()
|
||||
}
|
||||
Reference in New Issue
Block a user