code.gitea.io/gitea@v1.21.7/routers/web/explore/topic.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package explore 5 6 import ( 7 "net/http" 8 9 "code.gitea.io/gitea/models/db" 10 repo_model "code.gitea.io/gitea/models/repo" 11 "code.gitea.io/gitea/modules/context" 12 api "code.gitea.io/gitea/modules/structs" 13 "code.gitea.io/gitea/services/convert" 14 ) 15 16 // TopicSearch search for creating topic 17 func TopicSearch(ctx *context.Context) { 18 opts := &repo_model.FindTopicOptions{ 19 Keyword: ctx.FormString("q"), 20 ListOptions: db.ListOptions{ 21 Page: ctx.FormInt("page"), 22 PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), 23 }, 24 } 25 26 topics, total, err := repo_model.FindTopics(ctx, opts) 27 if err != nil { 28 ctx.Error(http.StatusInternalServerError) 29 return 30 } 31 32 topicResponses := make([]*api.TopicResponse, len(topics)) 33 for i, topic := range topics { 34 topicResponses[i] = convert.ToTopicResponse(topic) 35 } 36 37 ctx.SetTotalCountHeader(total) 38 ctx.JSON(http.StatusOK, map[string]any{ 39 "topics": topicResponses, 40 }) 41 }