34 lines
615 B
Go
34 lines
615 B
Go
|
|
package handlers
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"knowledge-graph-backend/services"
|
||
|
|
)
|
||
|
|
|
||
|
|
type SearchHandler struct {
|
||
|
|
dataService *services.DataService
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewSearchHandler(dataService *services.DataService) *SearchHandler {
|
||
|
|
return &SearchHandler{
|
||
|
|
dataService: dataService,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *SearchHandler) SearchNodes(c *gin.Context) {
|
||
|
|
query := c.Query("q")
|
||
|
|
if query == "" {
|
||
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
||
|
|
"error": "Bad Request",
|
||
|
|
"message": "Query parameter 'q' is required",
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
results := h.dataService.SearchNodes(query)
|
||
|
|
|
||
|
|
c.JSON(http.StatusOK, results)
|
||
|
|
}
|