service/app/mix/dao/store.go

85 lines
2.4 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package dao
import (
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
bannerproto "service/api/proto/banner/proto"
catalogproto "service/api/proto/catalog/proto"
productproto "service/api/proto/product/proto"
"service/app/mix/conf"
"service/dbstruct"
"service/library/logger"
)
type IStore interface {
// 商品
CreateProduct(ctx *gin.Context, product *dbstruct.Product) error
UpdateProduct(ctx *gin.Context, product *dbstruct.Product) error
DeleteProduct(ctx *gin.Context, id int64) error
GetProductList(ctx *gin.Context, req *productproto.OpListReq) ([]*dbstruct.Product, error)
GetProductById(ctx *gin.Context, id string) (*dbstruct.Product, error)
// 分类
CreateCatalog(ctx *gin.Context, catalog *dbstruct.Catalog) error
UpdateCatalog(ctx *gin.Context, catalog *dbstruct.Catalog) error
DeleteCatalog(ctx *gin.Context, id int64) error
GetCatalogList(ctx *gin.Context, req *catalogproto.OpListReq) ([]*dbstruct.Catalog, error)
GetCatalogListByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.Catalog, error)
// banner
CreateBanner(ctx *gin.Context, banner *dbstruct.Banner) error
UpdateBanner(ctx *gin.Context, banner *dbstruct.Banner) error
DeleteBanner(ctx *gin.Context, id int64) error
GetBannerList(ctx *gin.Context, req *bannerproto.OpListReq) ([]*dbstruct.Banner, error)
GetBannerListByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.Banner, error)
// resource
SetL2CatalogIndex(ctx *gin.Context, list []*dbstruct.L2CatalogIndex) error
GetL2CatalogIndex(ctx *gin.Context, l1Id int64) ([]*dbstruct.L2CatalogIndex, error)
SetBannerIndex(ctx *gin.Context, list []*dbstruct.BannerIndex) error
GetBannerIndex(ctx *gin.Context) ([]*dbstruct.BannerIndex, error)
// image
SaveImage(ctx *gin.Context, image *dbstruct.Image) error
SaveVideo(ctx *gin.Context, video *dbstruct.Video) error
// video
// vas
CreateOrder(ctx *gin.Context, tx *sqlx.Tx, order *dbstruct.Order) error
}
type Store struct {
*Mongo
*Mysql
2024-05-11 19:29:33 +08:00
*ElasticSearch
2023-12-21 22:17:40 +08:00
}
func NewStore(cfg *conf.ConfigSt) (store *Store, err error) {
mongo, err := NewMongo(cfg)
if err != nil {
logger.Error("NewMongo fail, err: %v", err)
return
}
mysql, err := NewMysql(cfg)
if err != nil {
logger.Error("NewMysql fail, err: %v", err)
return
}
2024-05-11 19:29:33 +08:00
es, err := NewElasticSearch(cfg)
if err != nil {
logger.Error("NewElasticSearch fail, err: %v", err)
return
}
2023-12-21 22:17:40 +08:00
store = &Store{
2024-05-11 19:29:33 +08:00
Mongo: mongo,
Mysql: mysql,
ElasticSearch: es,
2023-12-21 22:17:40 +08:00
}
return
}