You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

topic.go 1021B

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