2018-12-16 16:27:33 +01:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Product struct {
|
|
|
|
gorm.Model
|
|
|
|
Name string
|
2018-12-20 20:50:01 +01:00
|
|
|
Company Company `json:",omitempty"`
|
2018-12-16 16:27:33 +01:00
|
|
|
CompanyID uint
|
|
|
|
Code string `gorm:"unique; unique_index"`
|
2018-12-20 20:50:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetProducts() ([]*Product) {
|
|
|
|
|
|
|
|
products := make([]*Product, 0)
|
|
|
|
GetDB().Find(&products)
|
|
|
|
|
|
|
|
return products
|
2019-01-05 16:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetProduct(barcode string) (*Product) {
|
|
|
|
|
|
|
|
product := &Product{}
|
|
|
|
if GetDB().Where("code = ?", barcode).First(product).RecordNotFound() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return product
|
|
|
|
}
|
|
|
|
|
|
|
|
func (product *Product) CreateOrUpdate() (*Product) {
|
|
|
|
|
|
|
|
GetDB().Save(product)
|
|
|
|
|
|
|
|
return product;
|
2018-12-16 16:27:33 +01:00
|
|
|
}
|