app.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/open/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. // addApp.
  10. func addApp(c *bm.Context) {
  11. appname := c.Request.Form.Get("app_name")
  12. if appname == "" {
  13. c.JSON(nil, ecode.RequestErr)
  14. log.Error("appname is Empty")
  15. return
  16. }
  17. c.JSON(nil, mngSvc.AddApp(c, appname))
  18. }
  19. // deleteApp.
  20. func delApp(c *bm.Context) {
  21. form := c.Request.Form
  22. appid, _ := strconv.ParseInt(form.Get("appid"), 10, 64)
  23. if appid <= 0 {
  24. c.JSON(nil, ecode.RequestErr)
  25. log.Error("appid (%d) is not exit", appid)
  26. return
  27. }
  28. c.JSON(nil, mngSvc.DelApp(c, appid))
  29. }
  30. // updateApp.
  31. func updateApp(c *bm.Context) {
  32. arg := new(model.AppParams)
  33. if err := c.Bind(arg); err != nil {
  34. return
  35. }
  36. c.JSON(nil, mngSvc.UpdateApp(c, arg))
  37. }
  38. // listApp.
  39. func listApp(c *bm.Context) {
  40. t := &model.AppListParams{}
  41. if err := c.Bind(t); err != nil {
  42. return
  43. }
  44. data, total, err := mngSvc.ListApp(c, t)
  45. if err != nil {
  46. c.JSON(nil, err)
  47. return
  48. }
  49. page := map[string]int64{
  50. "num": t.PN,
  51. "size": t.PS,
  52. "total": total,
  53. }
  54. c.JSON(map[string]interface{}{
  55. "page": page,
  56. "data": data,
  57. }, err)
  58. }