Files
cybertron/service/searchService.go
Varnit Goyal a63d66100a TP-55555 | cybertron ui (#13)
* TP-55555 | cybertron ui

* TP-55555 clean up

* TP-55555 clean up

* TP-55555 | latest push
2024-08-21 13:01:17 +05:30

50 lines
1.2 KiB
Go

package service
import (
"cybertron/internal/client/elastic"
"cybertron/pkg/log"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
"github.com/gin-gonic/gin"
"net/http"
)
type SearchService struct {
logger *log.Logger
elasticSearchClient *elastic.ElasticSearchClient
}
func NewSearchService(logger *log.Logger, elasticSearchClient *elastic.ElasticSearchClient) *SearchService {
return &SearchService{
logger: logger,
elasticSearchClient: elasticSearchClient,
}
}
func (s *SearchService) Search(c *gin.Context) {
}
func (s *SearchService) GetErrorDetails(c *gin.Context) {
documentId := c.Query("document_id")
response, _ := s.elasticSearchClient.GetDocument(documentId)
c.JSON(http.StatusOK, response)
}
func (s *SearchService) GetErrorList(c *gin.Context) {
//todo pagination and aggregation of errors
projectId := c.Query("project_id")
println(projectId)
query := &types.Query{
Term: map[string]types.TermQuery{
"project_id": {
Value: projectId,
},
},
}
fields := []string{"error", "significant_stack", "title"}
var response, _ = s.elasticSearchClient.SearchDocuments(query, fields)
c.JSON(http.StatusOK, response)
}