diff --git a/backend/app/repo/website.go b/backend/app/repo/website.go index c525337a8..4c4cc2545 100644 --- a/backend/app/repo/website.go +++ b/backend/app/repo/website.go @@ -18,6 +18,7 @@ type IWebsiteRepo interface { WithDefaultServer() DBOption WithDomainLike(domain string) DBOption WithRuntimeID(runtimeID uint) DBOption + WithIDs(ids []uint) DBOption Page(page, size int, opts ...DBOption) (int64, []model.Website, error) List(opts ...DBOption) ([]model.Website, error) GetFirst(opts ...DBOption) (model.Website, error) @@ -36,9 +37,15 @@ func NewIWebsiteRepo() IWebsiteRepo { type WebsiteRepo struct { } -func (w *WebsiteRepo) WithAppInstallId(appInstallId uint) DBOption { +func (w *WebsiteRepo) WithAppInstallId(appInstallID uint) DBOption { return func(db *gorm.DB) *gorm.DB { - return db.Where("app_install_id = ?", appInstallId) + return db.Where("app_install_id = ?", appInstallID) + } +} + +func (w *WebsiteRepo) WithIDs(ids []uint) DBOption { + return func(db *gorm.DB) *gorm.DB { + return db.Where("id in (?)", ids) } } diff --git a/backend/app/repo/website_domain.go b/backend/app/repo/website_domain.go index 6624a2108..fa5c45560 100644 --- a/backend/app/repo/website_domain.go +++ b/backend/app/repo/website_domain.go @@ -14,6 +14,7 @@ type IWebsiteDomainRepo interface { WithWebsiteId(websiteId uint) DBOption WithPort(port int) DBOption WithDomain(domain string) DBOption + WithDomainLike(domain string) DBOption Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error) GetFirst(opts ...DBOption) (model.WebsiteDomain, error) GetBy(opts ...DBOption) ([]model.WebsiteDomain, error) @@ -44,6 +45,11 @@ func (w WebsiteDomainRepo) WithDomain(domain string) DBOption { return db.Where("domain = ?", domain) } } +func (w WebsiteDomainRepo) WithDomainLike(domain string) DBOption { + return func(db *gorm.DB) *gorm.DB { + return db.Where("domain like ?", "%"+domain+"%") + } +} func (w WebsiteDomainRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error) { var domains []model.WebsiteDomain db := getDb(opts...).Model(&model.WebsiteDomain{}) diff --git a/backend/app/service/website.go b/backend/app/service/website.go index ed2cd7826..6bfdca35d 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -119,7 +119,16 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons } opts = append(opts, commonRepo.WithOrderRuleBy(req.OrderBy, req.Order)) if req.Name != "" { - opts = append(opts, websiteRepo.WithDomainLike(req.Name)) + domains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithDomainLike(req.Name)) + if len(domains) > 0 { + var websiteIds []uint + for _, domain := range domains { + websiteIds = append(websiteIds, domain.WebsiteID) + } + opts = append(opts, websiteRepo.WithIDs(websiteIds)) + } else { + opts = append(opts, websiteRepo.WithDomainLike(req.Name)) + } } if req.WebsiteGroupID != 0 { opts = append(opts, websiteRepo.WithGroupID(req.WebsiteGroupID))