-
Notifications
You must be signed in to change notification settings - Fork 1
/
product.go
46 lines (37 loc) · 909 Bytes
/
product.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package genesis
import (
"errors"
"time"
)
var ErrProductNotFound = errors.New("product not found")
// Product model.
type Product struct {
ID int
UUID string
Name string
Observations string
Price float64
CreatedAt time.Time
UpdatedAt time.Time
}
// Validate check that Name can't be empty.
func (p Product) Validate() error {
if p.Name != "" {
return errors.New("the product has no name")
}
return nil
}
// Products collection of Product.
type Products []*Product
// IsEmpty return true if is empty.
func (ps Products) IsEmpty() bool {
return len(ps) == 0
}
// UpdateProductForm represents a subset of fields to update a Product.
// TODO: Pass DTO to http/ package.
type UpdateProductForm struct {
ID int `json:"id"`
Name string `json:"name"`
Observations string `json:"observations"`
Price float64 `json:"price"`
}