123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- package http
- import (
- "time"
- "go-common/app/interface/main/esports/model"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- )
- func addFav(c *bm.Context) {
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- v := new(struct {
- Cid int64 `form:"cid" validate:"min=1"`
- })
- if err := c.Bind(v); err != nil {
- return
- }
- c.JSON(nil, switchCode(eSvc.AddFav(c, mid, v.Cid)))
- }
- func delFav(c *bm.Context) {
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- v := new(struct {
- Cid int64 `form:"cid" validate:"min=1"`
- })
- if err := c.Bind(v); err != nil {
- return
- }
- c.JSON(nil, switchCode(eSvc.DelFav(c, mid, v.Cid)))
- }
- func listFav(c *bm.Context) {
- var (
- mid int64
- total int
- contest []*model.Contest
- err error
- )
- if midStr, ok := c.Get("mid"); ok {
- mid = midStr.(int64)
- }
- v := new(struct {
- VMID int64 `form:"vmid"`
- Pn int `form:"pn" default:"1" validate:"min=1"`
- Ps int `form:"ps" default:"5" validate:"min=1"`
- })
- if err = c.Bind(v); err != nil {
- return
- }
- if contest, total, err = eSvc.ListFav(c, mid, v.VMID, v.Pn, v.Ps); err != nil {
- c.JSON(nil, err)
- return
- }
- data := make(map[string]interface{}, 2)
- page := map[string]int{
- "num": v.Pn,
- "size": v.Ps,
- "total": total,
- }
- data["page"] = page
- data["list"] = contest
- c.JSON(data, nil)
- }
- func appListFav(c *bm.Context) {
- var (
- mid int64
- total int
- contest []*model.Contest
- err error
- )
- if midStr, ok := c.Get("mid"); ok {
- mid = midStr.(int64)
- }
- v := new(model.ParamFav)
- if err = c.Bind(v); err != nil {
- return
- }
- if mid == 0 && v.VMID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if v.Stime != "" {
- if _, err = time.Parse("2006-01-02", v.Stime); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- if v.Etime != "" {
- if _, err = time.Parse("2006-01-02", v.Etime); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- if contest, total, err = eSvc.ListAppFav(c, mid, v); err != nil {
- c.JSON(nil, err)
- return
- }
- data := make(map[string]interface{}, 2)
- page := map[string]int{
- "num": v.Pn,
- "size": v.Ps,
- "total": total,
- }
- data["page"] = page
- data["list"] = contest
- c.JSON(data, nil)
- }
- func seasonFav(c *bm.Context) {
- var (
- mid int64
- total int
- seasons []*model.Season
- err error
- )
- if midStr, ok := c.Get("mid"); ok {
- mid = midStr.(int64)
- }
- v := new(model.ParamSeason)
- if err = c.Bind(v); err != nil {
- return
- }
- if mid == 0 && v.VMID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if seasons, total, err = eSvc.SeasonFav(c, mid, v); err != nil {
- c.JSON(nil, err)
- return
- }
- data := make(map[string]interface{}, 2)
- page := map[string]int{
- "num": v.Pn,
- "size": v.Ps,
- "total": total,
- }
- data["page"] = page
- data["list"] = seasons
- c.JSON(data, nil)
- }
- func stimeFav(c *bm.Context) {
- var (
- mid int64
- total int
- stimes []string
- err error
- )
- if midStr, ok := c.Get("mid"); ok {
- mid = midStr.(int64)
- }
- v := new(model.ParamSeason)
- if err = c.Bind(v); err != nil {
- return
- }
- if mid == 0 && v.VMID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if stimes, total, err = eSvc.StimeFav(c, mid, v); err != nil {
- c.JSON(nil, err)
- return
- }
- data := make(map[string]interface{}, 2)
- page := map[string]int{
- "num": v.Pn,
- "size": v.Ps,
- "total": total,
- }
- data["page"] = page
- data["list"] = stimes
- c.JSON(data, nil)
- }
- func switchCode(err error) error {
- if err == nil {
- return err
- }
- switch ecode.Cause(err) {
- case ecode.FavResourceOverflow:
- err = ecode.EsportsContestMaxCount
- case ecode.FavResourceAlreadyDel:
- err = ecode.EsportsContestFavDel
- case ecode.FavResourceExist:
- err = ecode.EsportsContestFavExist
- case ecode.FavFolderNotExist:
- err = ecode.EsportsContestNotExist
- }
- return err
- }
|