media.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/tv/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func atoi(param string) int {
  9. if param == "" {
  10. return 0
  11. }
  12. res, err := strconv.Atoi(param)
  13. if err != nil {
  14. return 0
  15. }
  16. return res
  17. }
  18. func mDetailParam(c *bm.Context, param *model.MediaParam) (err error) {
  19. var msg string
  20. if err = c.Bind(param); err != nil {
  21. return
  22. }
  23. if param.EpID == 0 && param.SeasonID == 0 {
  24. err = ecode.RequestErr
  25. c.JSON(nil, err)
  26. return
  27. }
  28. if param.EpID > 0 {
  29. if param.SeasonID, msg, err = pgcSvc.EpControl(c, param.EpID); err != nil {
  30. c.JSONMap(map[string]interface{}{"message": msg}, err)
  31. return
  32. }
  33. }
  34. return
  35. }
  36. // get ep/season detail
  37. func mediaDetail(c *bm.Context) {
  38. var param = new(model.MediaParam)
  39. if err := mDetailParam(c, param); err != nil {
  40. return
  41. }
  42. detail, msg, err := pgcSvc.SnDetail(c, param)
  43. if err != nil {
  44. c.JSONMap(map[string]interface{}{"message": msg}, err)
  45. return
  46. }
  47. c.JSONMap(map[string]interface{}{"result": detail, "message": "success"}, nil)
  48. }
  49. func mDetailV2(c *bm.Context) {
  50. var param = new(model.MediaParam)
  51. if err := mDetailParam(c, param); err != nil {
  52. return
  53. }
  54. detail, msg, err := pgcSvc.SnDetailV2(c, param)
  55. if err != nil {
  56. c.JSONMap(map[string]interface{}{"message": msg}, err)
  57. return
  58. }
  59. c.JSONMap(map[string]interface{}{"result": detail, "message": "success"}, nil)
  60. }