feat(crm): route crm search through meilisearch

This commit is contained in:
2026-06-05 04:16:49 +08:00
parent 7a7bc4197a
commit 202da194e1
11 changed files with 318 additions and 18 deletions
+15 -7
View File
@@ -24,11 +24,15 @@ type mockSearchRepo struct {
msgTotal int64
msgErr error
contacts []model.Contact
contacts []model.Contact
contactTotal int64
contactErr error
articles []model.Article
companies []model.Company
companyTotal int64
companyErr error
articles []model.Article
articleTotal int64
articleErr error
}
@@ -45,6 +49,10 @@ func (m *mockSearchRepo) SearchContacts(ctx context.Context, accountID uint, que
return m.contacts, m.contactTotal, m.contactErr
}
func (m *mockSearchRepo) SearchCompanies(ctx context.Context, accountID uint, query string, filter *search.SearchFilter) ([]model.Company, int64, error) {
return m.companies, m.companyTotal, m.companyErr
}
func (m *mockSearchRepo) SearchArticles(ctx context.Context, accountID uint, query string, filter *search.SearchFilter) ([]model.Article, int64, error) {
return m.articles, m.articleTotal, m.articleErr
}
@@ -263,8 +271,8 @@ func TestSearchHandler_SearchMessages_ServiceError(t *testing.T) {
func TestSearchHandler_SearchContacts_Success(t *testing.T) {
repo := &mockSearchRepo{
contacts: []model.Contact{makeContact(1, "Alice")},
contactTotal: 1,
contacts: []model.Contact{makeContact(1, "Alice")},
contactTotal: 1,
}
svc := search.NewSearchService(repo)
handler := NewSearchHandler(svc)
@@ -315,8 +323,8 @@ func TestSearchHandler_SearchContacts_ServiceError(t *testing.T) {
func TestSearchHandler_SearchArticles_Success(t *testing.T) {
repo := &mockSearchRepo{
articles: []model.Article{makeArticle(1, 1, "FAQ Guide", "desc", "content", "published")},
articleTotal: 1,
articles: []model.Article{makeArticle(1, 1, "FAQ Guide", "desc", "content", "published")},
articleTotal: 1,
}
svc := search.NewSearchService(repo)
handler := NewSearchHandler(svc)
@@ -361,4 +369,4 @@ func TestSearchHandler_SearchArticles_ServiceError(t *testing.T) {
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusUnprocessableEntity, w.Code)
}
}