mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
feat: 网站搜索增加网站关联域名匹配 (#4198)
Refs https://github.com/1Panel-dev/1Panel/pull/4198
This commit is contained in:
parent
6ce35b723b
commit
8f24432a01
@ -18,6 +18,7 @@ type IWebsiteRepo interface {
|
|||||||
WithDefaultServer() DBOption
|
WithDefaultServer() DBOption
|
||||||
WithDomainLike(domain string) DBOption
|
WithDomainLike(domain string) DBOption
|
||||||
WithRuntimeID(runtimeID uint) DBOption
|
WithRuntimeID(runtimeID uint) DBOption
|
||||||
|
WithIDs(ids []uint) DBOption
|
||||||
Page(page, size int, opts ...DBOption) (int64, []model.Website, error)
|
Page(page, size int, opts ...DBOption) (int64, []model.Website, error)
|
||||||
List(opts ...DBOption) ([]model.Website, error)
|
List(opts ...DBOption) ([]model.Website, error)
|
||||||
GetFirst(opts ...DBOption) (model.Website, error)
|
GetFirst(opts ...DBOption) (model.Website, error)
|
||||||
@ -36,9 +37,15 @@ func NewIWebsiteRepo() IWebsiteRepo {
|
|||||||
type WebsiteRepo struct {
|
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 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ type IWebsiteDomainRepo interface {
|
|||||||
WithWebsiteId(websiteId uint) DBOption
|
WithWebsiteId(websiteId uint) DBOption
|
||||||
WithPort(port int) DBOption
|
WithPort(port int) DBOption
|
||||||
WithDomain(domain string) DBOption
|
WithDomain(domain string) DBOption
|
||||||
|
WithDomainLike(domain string) DBOption
|
||||||
Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error)
|
Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error)
|
||||||
GetFirst(opts ...DBOption) (model.WebsiteDomain, error)
|
GetFirst(opts ...DBOption) (model.WebsiteDomain, error)
|
||||||
GetBy(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)
|
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) {
|
func (w WebsiteDomainRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error) {
|
||||||
var domains []model.WebsiteDomain
|
var domains []model.WebsiteDomain
|
||||||
db := getDb(opts...).Model(&model.WebsiteDomain{})
|
db := getDb(opts...).Model(&model.WebsiteDomain{})
|
||||||
|
@ -119,7 +119,16 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons
|
|||||||
}
|
}
|
||||||
opts = append(opts, commonRepo.WithOrderRuleBy(req.OrderBy, req.Order))
|
opts = append(opts, commonRepo.WithOrderRuleBy(req.OrderBy, req.Order))
|
||||||
if req.Name != "" {
|
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 {
|
if req.WebsiteGroupID != 0 {
|
||||||
opts = append(opts, websiteRepo.WithGroupID(req.WebsiteGroupID))
|
opts = append(opts, websiteRepo.WithGroupID(req.WebsiteGroupID))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user