refactor: 按go modules规范重构
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge-graph-backend/internal/service"
|
||||
)
|
||||
|
||||
type SearchHandler struct {
|
||||
service service.GraphService
|
||||
}
|
||||
|
||||
func NewSearchHandler(svc service.GraphService) *SearchHandler {
|
||||
return &SearchHandler{
|
||||
service: svc,
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 搜索节点
|
||||
// @Description 根据关键词搜索知识图谱中的节点
|
||||
// @Produce json
|
||||
// @Param q query string true "搜索关键词"
|
||||
// @Success 200 {object} model.SearchResponse "成功"
|
||||
// @Failure 400 {object} model.ErrorResponse "请求错误"
|
||||
// @Failure 500 {object} model.ErrorResponse "内部错误"
|
||||
// @Router /api/search [get]
|
||||
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.service.SearchNodes(query)
|
||||
|
||||
c.JSON(http.StatusOK, results)
|
||||
}
|
||||
Reference in New Issue
Block a user