repo.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2014 The Gogs 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. "fmt"
  7. "net/http"
  8. "strconv"
  9. "github.com/martini-contrib/render"
  10. "github.com/gogits/gogs/models"
  11. )
  12. func Create(req *http.Request, r render.Render) {
  13. if req.Method == "GET" {
  14. r.HTML(200, "repo/create", map[string]interface{}{
  15. "Title": "Create repository",
  16. })
  17. return
  18. }
  19. // TODO: access check
  20. //fmt.Println(req.FormValue("userId"), req.FormValue("name"))
  21. id, err := strconv.ParseInt(req.FormValue("userId"), 10, 64)
  22. if err == nil {
  23. var user *models.User
  24. user, err = models.GetUserById(id)
  25. if user == nil {
  26. err = models.ErrUserNotExist
  27. }
  28. if err == nil {
  29. _, err = models.CreateRepository(user, req.FormValue("name"))
  30. }
  31. if err == nil {
  32. r.HTML(200, "repo/created", map[string]interface{}{
  33. "RepoName": user.Name + "/" + req.FormValue("name"),
  34. })
  35. return
  36. }
  37. }
  38. if err != nil {
  39. r.HTML(200, "base/error", map[string]interface{}{
  40. "Error": fmt.Sprintf("%v", err),
  41. })
  42. }
  43. }
  44. func Delete(req *http.Request, r render.Render) {
  45. if req.Method == "GET" {
  46. r.HTML(200, "repo/delete", map[string]interface{}{
  47. "Title": "Delete repository",
  48. })
  49. return
  50. }
  51. u := &models.User{}
  52. err := models.DeleteRepository(u, "")
  53. if err != nil {
  54. r.HTML(200, "base/error", map[string]interface{}{
  55. "Error": fmt.Sprintf("%v", err),
  56. })
  57. }
  58. }