feat: 网站搜索改为模糊查询

This commit is contained in:
zhengkunwang223 2023-03-02 14:56:06 +08:00 committed by ssongliu
parent 11b40b8cf9
commit f0923169d3
2 changed files with 8 additions and 1 deletions

View file

@ -16,6 +16,7 @@ type IWebsiteRepo interface {
WithWebsiteSSLID(sslId uint) DBOption
WithGroupID(groupId uint) DBOption
WithDefaultServer() DBOption
WithDomainLike(domain string) DBOption
Page(page, size int, opts ...DBOption) (int64, []model.Website, error)
List(opts ...DBOption) ([]model.Website, error)
GetFirst(opts ...DBOption) (model.Website, error)
@ -45,6 +46,12 @@ func (w *WebsiteRepo) WithDomain(domain string) DBOption {
}
}
func (w *WebsiteRepo) WithDomainLike(domain string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("primary_domain like ?", "%"+domain+"%")
}
}
func (w *WebsiteRepo) WithAlias(alias string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("alias = ?", alias)

View file

@ -63,7 +63,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons
)
opts = append(opts, commonRepo.WithOrderBy("created_at desc"))
if req.Name != "" {
opts = append(opts, websiteRepo.WithDomain(req.Name))
opts = append(opts, websiteRepo.WithDomainLike(req.Name))
}
if req.WebsiteGroupID != 0 {
opts = append(opts, websiteRepo.WithGroupID(req.WebsiteGroupID))