feat get和list使用引用query

This commit is contained in:
timerzz 2024-08-31 12:46:18 +08:00
parent 27bd1558d4
commit 6063310bb3
3 changed files with 8 additions and 8 deletions

View File

@ -8,9 +8,9 @@ import (
type ArticleApi interface {
Upsert(article v2.Article) error
Find(query FindArticleQuery) (articles []v2.Article, err error)
Find(query *FindArticleQuery) (articles []v2.Article, err error)
List(query PageListQuery) (articles []v2.Article, total int64, err error)
Get(query GetArticleQuery) (article v2.Article, err error)
Get(query *GetArticleQuery) (article v2.Article, err error)
}
type articleApi struct {
@ -84,7 +84,7 @@ func (l *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB {
return db
}
func (a *articleApi) Find(query FindArticleQuery) (articles []v2.Article, err error) {
func (a *articleApi) Find(query *FindArticleQuery) (articles []v2.Article, err error) {
err = a.db.Scopes(query.Scope).Find(&articles).Error
return
}
@ -146,7 +146,7 @@ func (g *GetArticleQuery) Scope(db *gorm.DB) *gorm.DB {
return db
}
func (a *articleApi) Get(query GetArticleQuery) (article v2.Article, err error) {
func (a *articleApi) Get(query *GetArticleQuery) (article v2.Article, err error) {
err = a.db.Scopes(query.Scope).First(&article).Error
return
}

View File

@ -8,7 +8,7 @@ import (
// ProviderArticleApi 管理供应商商品的接口
type ProviderArticleApi interface {
Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Get(query *GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Upsert(article v2.ProviderArticle) error
AutoMigrate() error
}
@ -77,7 +77,7 @@ func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
return db
}
func (p *providerArticleApi) Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error) {
func (p *providerArticleApi) Get(query *GetProviderArticleQuery) (article v2.ProviderArticle, err error) {
err = p.db.Scopes(query.Scope).Preload("CalculateProcess").First(&article).Error
return
}

View File

@ -8,7 +8,7 @@ import (
// SellerArticleApi 管理供应商商品的接口
type SellerArticleApi interface {
Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Get(query *GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Upsert(article v2.SellerArticle) error
AutoMigrate() error
}
@ -70,7 +70,7 @@ func (g *GetSellerArticleQuery) Scope(db *gorm.DB) *gorm.DB {
return db
}
func (p *sellerArticleApi) Get(query GetSellerArticleQuery) (article v2.SellerArticle, err error) {
func (p *sellerArticleApi) Get(query *GetSellerArticleQuery) (article v2.SellerArticle, err error) {
err = p.db.Scopes(query.Scope).First(&article).Error
return
}