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 963B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "strings"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/log"
  10. )
  11. // TopicPost response for creating repository
  12. func TopicPost(ctx *context.Context) {
  13. if ctx.User == nil {
  14. ctx.JSON(403, map[string]interface{}{
  15. "message": "Only owners could change the topics.",
  16. })
  17. return
  18. }
  19. var topics = make([]string, 0)
  20. var topicsStr = strings.TrimSpace(ctx.Query("topics"))
  21. if len(topicsStr) > 0 {
  22. topics = strings.Split(topicsStr, ",")
  23. }
  24. err := models.SaveTopics(ctx.Repo.Repository.ID, topics...)
  25. if err != nil {
  26. log.Error(2, "SaveTopics failed: %v", err)
  27. ctx.JSON(500, map[string]interface{}{
  28. "message": "Save topics failed.",
  29. })
  30. return
  31. }
  32. ctx.JSON(200, map[string]interface{}{
  33. "status": "ok",
  34. })
  35. }