MCPcopy Index your code
hub / github.com/apache/answer / QuestionList

Method QuestionList

internal/controller/template_controller.go:178–216  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

176}
177
178func (tc *TemplateController) QuestionList(ctx *gin.Context) {
179 req := &schema.QuestionPageReq{
180 OrderCond: "newest",
181 }
182 if handler.BindAndCheck(ctx, req) {
183 return
184 }
185 var page = req.Page
186 data, count, err := tc.templateRenderController.Index(ctx, req)
187 if err != nil || (len(data) == 0 && pager.ValPageOutOfRange(count, page, req.PageSize)) {
188 tc.Page404(ctx)
189 return
190 }
191
192 hotQuestionReq := &schema.QuestionPageReq{
193 Page: 1,
194 PageSize: 6,
195 OrderCond: "hot",
196 InDays: 7,
197 }
198 hotQuestion, _, _ := tc.templateRenderController.Index(ctx, hotQuestionReq)
199
200 siteInfo := tc.SiteInfo(ctx)
201 siteInfo.Canonical = fmt.Sprintf("%s/questions", siteInfo.General.SiteUrl)
202 if page > 1 {
203 siteInfo.Canonical = fmt.Sprintf("%s/questions?page=%d", siteInfo.General.SiteUrl, page)
204 }
205
206 UrlUseTitle := siteInfo.SiteSeo.Permalink == constant.PermalinkQuestionIDAndTitle ||
207 siteInfo.SiteSeo.Permalink == constant.PermalinkQuestionIDAndTitleByShortID
208
209 siteInfo.Title = fmt.Sprintf("%s - %s", translator.Tr(handler.GetLangByCtx(ctx), constant.QuestionsTitleTrKey), siteInfo.General.Name)
210 tc.html(ctx, http.StatusOK, "question.html", siteInfo, gin.H{
211 "data": data,
212 "useTitle": UrlUseTitle,
213 "page": templaterender.Paginator(page, req.PageSize, count),
214 "hotQuestion": hotQuestion,
215 })
216}
217
218func (tc *TemplateController) QuestionInfoRedirect(ctx *gin.Context, siteInfo *schema.TemplateSiteInfoResp, correctTitle bool) (jump bool, url string) {
219 questionID := ctx.Param("id")

Callers

nothing calls this directly

Calls 8

Page404Method · 0.95
SiteInfoMethod · 0.95
htmlMethod · 0.95
BindAndCheckFunction · 0.92
ValPageOutOfRangeFunction · 0.92
TrFunction · 0.92
GetLangByCtxFunction · 0.92
IndexMethod · 0.45

Tested by

no test coverage detected