MCPcopy
hub / github.com/apache/answer / Search

Method Search

internal/controller/search_controller.go:64–93  ·  view source on GitHub ↗

Search godoc @Summary search object @Description search object @Tags Search @Produce json @Security ApiKeyAuth @Param q query string true "query string" @Param order query string true "order" Enums(newest,active,score,relevance) @Success 200 {object} handler.RespBody{data=schema.SearchResp} @Router

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

62// @Success 200 {object} handler.RespBody{data=schema.SearchResp}
63// @Router /answer/api/v1/search [get]
64func (sc *SearchController) Search(ctx *gin.Context) {
65 dto := schema.SearchDTO{}
66
67 if handler.BindAndCheck(ctx, &dto) {
68 return
69 }
70 dto.UserID = middleware.GetLoginUserIDFromContext(ctx)
71 unit := ctx.ClientIP()
72 if dto.UserID != "" {
73 unit = dto.UserID
74 }
75 isAdmin := middleware.GetUserIsAdminModerator(ctx)
76 if !isAdmin {
77 captchaPass := sc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionSearch, unit, dto.CaptchaID, dto.CaptchaCode)
78 if !captchaPass {
79 errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{
80 ErrorField: "captcha_code",
81 ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.CaptchaVerificationFailed),
82 })
83 handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields)
84 return
85 }
86 }
87
88 if !isAdmin {
89 sc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionSearch, unit)
90 }
91 resp, err := sc.searchService.Search(ctx, &dto)
92 handler.HandleResponse(ctx, err, resp)
93}
94
95// SearchDesc get search description
96// @Summary get search description

Callers 1

MCPQuestionsHandlerMethod · 0.45

Calls 8

BindAndCheckFunction · 0.92
GetUserIsAdminModeratorFunction · 0.92
TrFunction · 0.92
GetLangByCtxFunction · 0.92
HandleResponseFunction · 0.92
ActionRecordAddMethod · 0.80

Tested by

no test coverage detected