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)
| 62 | // @Success 200 {object} handler.RespBody{data=schema.SearchResp} |
| 63 | // @Router /answer/api/v1/search [get] |
| 64 | func (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 |
no test coverage detected