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

Method Index

internal/controller/template_controller.go:138–176  ·  view source on GitHub ↗

Index question list

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

136
137// Index question list
138func (tc *TemplateController) Index(ctx *gin.Context) {
139 req := &schema.QuestionPageReq{
140 OrderCond: "newest",
141 }
142 if handler.BindAndCheck(ctx, req) {
143 return
144 }
145
146 var page = req.Page
147
148 data, count, err := tc.templateRenderController.Index(ctx, req)
149 if err != nil || (len(data) == 0 && pager.ValPageOutOfRange(count, page, req.PageSize)) {
150 tc.Page404(ctx)
151 return
152 }
153
154 hotQuestionReq := &schema.QuestionPageReq{
155 Page: 1,
156 PageSize: 6,
157 OrderCond: "hot",
158 InDays: 7,
159 }
160 hotQuestion, _, _ := tc.templateRenderController.Index(ctx, hotQuestionReq)
161
162 siteInfo := tc.SiteInfo(ctx)
163 siteInfo.Canonical = siteInfo.General.SiteUrl
164
165 UrlUseTitle := siteInfo.SiteSeo.Permalink == constant.PermalinkQuestionIDAndTitle ||
166 siteInfo.SiteSeo.Permalink == constant.PermalinkQuestionIDAndTitleByShortID
167
168 siteInfo.Title = ""
169 tc.html(ctx, http.StatusOK, "question.html", siteInfo, gin.H{
170 "data": data,
171 "useTitle": UrlUseTitle,
172 "page": templaterender.Paginator(page, req.PageSize, count),
173 "path": "questions",
174 "hotQuestion": hotQuestion,
175 })
176}
177
178func (tc *TemplateController) QuestionList(ctx *gin.Context) {
179 req := &schema.QuestionPageReq{

Callers 5

findFirstMatchedWordFunction · 0.45
QuestionListMethod · 0.45
ListPagedMethod · 0.45
GetExcerptMethod · 0.45
GetExcerptMethod · 0.45

Calls 5

Page404Method · 0.95
SiteInfoMethod · 0.95
htmlMethod · 0.95
BindAndCheckFunction · 0.92
ValPageOutOfRangeFunction · 0.92

Tested by

no test coverage detected