gorm/examples/mock.go
Alvaro Viebrantz 7c762943d4 Add mock example and mock implementation of Database interface.
stretchr/testify has used as mock library
2016-01-17 16:10:34 -03:00

37 lines
649 B
Go

package examples
import (
"github.com/jinzhu/gorm"
)
type Product struct {
gorm.Model
Name string
Price float64
StoreId int64
CategoryId int64
}
type ProductRepository interface {
FindAll(storeId int64, categoryId int64) ([]Product, error)
}
type ProductRepositoryImpl struct {
DB gorm.Database
}
func (r *ProductRepositoryImpl) FindAll(storeId int64, categoryId int64) ([]Product, error) {
qb := r.DB
if storeId > 0 {
qb = qb.Where("storeId = ?", storeId)
}
if categoryId > 0 {
qb = qb.Where("categoryId = ?", categoryId)
}
var products []Product
err := qb.Find(&products).GetError()
return products, err
}