mirror of https://gitee.com/answerdev/answer.git
feat(search): add description api for search
This commit is contained in:
parent
8aa58bc182
commit
51c86449e6
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/internal/service"
|
||||
"github.com/answerdev/answer/internal/service/action"
|
||||
"github.com/answerdev/answer/plugin"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
)
|
||||
|
@ -71,3 +72,24 @@ func (sc *SearchController) Search(ctx *gin.Context) {
|
|||
resp, err := sc.searchService.Search(ctx, &dto)
|
||||
handler.HandleResponse(ctx, err, resp)
|
||||
}
|
||||
|
||||
// SearchDesc get search description
|
||||
// @Summary get search description
|
||||
// @Description get search description
|
||||
// @Tags Search
|
||||
// @Produce json
|
||||
// @Success 200 {object} handler.RespBody{data=schema.SearchResp}
|
||||
// @Router /answer/api/v1/search/desc [get]
|
||||
func (sc *SearchController) SearchDesc(ctx *gin.Context) {
|
||||
var finder plugin.Search
|
||||
_ = plugin.CallSearch(func(search plugin.Search) error {
|
||||
finder = search
|
||||
return nil
|
||||
})
|
||||
resp := &schema.SearchDescResp{}
|
||||
if finder != nil {
|
||||
resp.Name = finder.Info().Name.Translate(ctx)
|
||||
resp.Icon = finder.Description().Icon
|
||||
}
|
||||
handler.HandleResponse(ctx, nil, resp)
|
||||
}
|
||||
|
|
|
@ -155,6 +155,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
|
||||
//search
|
||||
r.GET("/search", a.searchController.Search)
|
||||
r.GET("/search/desc", a.searchController.SearchDesc)
|
||||
|
||||
//rank
|
||||
r.GET("/personal/rank/page", a.rankController.GetRankPersonalWithPage)
|
||||
|
|
|
@ -118,6 +118,9 @@ type SearchResp struct {
|
|||
Total int64 `json:"count"`
|
||||
// search response
|
||||
SearchResults []SearchResult `json:"list"`
|
||||
// search plugin desc
|
||||
SearchPluginIcon string `json:"search_icon,omitempty"`
|
||||
}
|
||||
|
||||
type SearchDescResp struct {
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
|
|
|
@ -59,9 +59,7 @@ func (ss *SearchService) Search(ctx context.Context, dto *schema.SearchDTO) (res
|
|||
|
||||
func (ss *SearchService) searchByPlugin(ctx context.Context, finder plugin.Search, cond *schema.SearchCondition, dto *schema.SearchDTO) (resp *schema.SearchResp, err error) {
|
||||
var res []plugin.SearchResult
|
||||
resp = &schema.SearchResp{
|
||||
SearchPluginIcon: finder.Description().Icon,
|
||||
}
|
||||
resp = &schema.SearchResp{}
|
||||
if cond.SearchAll() {
|
||||
res, resp.Total, err = finder.SearchContents(ctx, cond.Convert2PluginSearchCond(dto.Page, dto.Size, dto.Order))
|
||||
} else if cond.SearchQuestion() {
|
||||
|
|
Loading…
Reference in New Issue