types(feat) create product type

This commit is contained in:
Theo Technicguy 2023-06-21 22:46:26 +02:00
parent 2e5c91b410
commit 2de5aa94d7
Signed by: theo.technicguy
GPG Key ID: 3BC661201BCA53D9
1 changed files with 62 additions and 0 deletions

62
types/poduct.go Normal file
View File

@ -0,0 +1,62 @@
/**
* file: types/product.go
* author: Theo Technicguy
* license: Apache 2.0
*
* Product type and functions
*/
package types
type TTL struct {
Normal uint `json:"normal"`
Fridge uint `json:"fridge"`
Freezer uint `json:"freezer"`
}
type Product struct {
Id uint `json:"id"`
EAN uint `json:"ean"`
Name string `json:"name"`
TTL TTL `json:"ttl"`
Tags []Tag `json:"tags"`
}
func (t *TTL) ValidTTL() bool {
if t.Normal == 0 {
return true
}
var fridge, freezer bool
if t.Fridge > 0 {
fridge = t.Normal < t.Fridge
} else {
fridge = true
}
if t.Freezer > 0 {
freezer = t.Normal < t.Freezer
} else {
freezer = true
}
return fridge && freezer
}
func (t *TTL) Valid() bool {
return t.ValidTTL()
}
func (p *Product) ValidName() bool {
return p.Name != ""
}
func (p *Product) Valid() bool {
for _, tag := range p.Tags {
if !tag.Valid() {
return false
}
}
return p.TTL.Valid() && p.ValidName()
}