From 2dfacfbe2cb2a4ee25e644839a6812c8836add74 Mon Sep 17 00:00:00 2001 From: timerzz Date: Tue, 27 Aug 2024 19:35:21 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0providerArticle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structs/storage/article.go | 6 +++++ structs/storage/provider-article_test.go | 32 ++++++++++++++++++++++++ structs/storage/storage.go | 9 +++---- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 structs/storage/provider-article_test.go diff --git a/structs/storage/article.go b/structs/storage/article.go index f8e4537..2393ae3 100644 --- a/structs/storage/article.go +++ b/structs/storage/article.go @@ -17,6 +17,12 @@ type articleApi struct { db *gorm.DB } +func NewArticleApi(db *gorm.DB) ArticleApi { + return &articleApi{ + db: db, + } +} + // Upsert 插入或者更新商品 func (a *articleApi) Upsert(article v2.Article) error { return a.db.Clauses(clause.OnConflict{ diff --git a/structs/storage/provider-article_test.go b/structs/storage/provider-article_test.go new file mode 100644 index 0000000..36b164c --- /dev/null +++ b/structs/storage/provider-article_test.go @@ -0,0 +1,32 @@ +package storage + +import ( + "testing" + + v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2" +) + +var providerArticle = v2.ProviderArticle{ + ArticleID: 1, + Brand: v2.Brand_Coach, + Cost: v2.ProviderPrice{ + CalMark: "111", + FinalPrice: 1, + OriginalPrice: 0, + ProviderArticleID: 0, + }, + HistoryPrice: []v2.ProviderPrice{ + { + CalMark: "222", + }, + }, +} + +func TestProviderArticleApi_Upsert(t *testing.T) { + db, err := GetDevDB() + if err != nil { + t.Fatal(err) + } + storage := NewStorage(db) + storage.ProviderArticle().Upsert(providerArticle) +} diff --git a/structs/storage/storage.go b/structs/storage/storage.go index 5b23f4c..53c31b6 100644 --- a/structs/storage/storage.go +++ b/structs/storage/storage.go @@ -12,11 +12,10 @@ type Storage struct { func NewStorage(db *gorm.DB) *Storage { return &Storage{ - articleApi: &articleApi{ - db: db, - }, - providerApi: NewProviderApi(db), - sellerApi: NewSellerApi(db), + articleApi: NewArticleApi(db), + providerApi: NewProviderApi(db), + providerArticleApi: NewProviderArticleApi(db), + sellerApi: NewSellerApi(db), } }