| | |
| | | package controller |
| | | |
| | | import ( |
| | | "net/http" |
| | | "strings" |
| | | "time" |
| | | |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/repository" |
| | | "gat1400Exchange/vo" |
| | | "net/http" |
| | | "strings" |
| | | "time" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | |
| | | |
| | | c.JSON(http.StatusOK, gin.H{"msg": "ok"}) |
| | | } |
| | | |
| | | func (s SubscribeController) CancelSubscribes(c *gin.Context) { |
| | | var req vo.Subscribe |
| | | if err := c.BindJSON(&req); err != nil { |
| | | c.JSON(http.StatusBadRequest, gin.H{"msg": err.Error()}) |
| | | return |
| | | } |
| | | |
| | | if c.Param("id") == "" { |
| | | c.JSON(http.StatusBadRequest, gin.H{"msg": "下级id为空"}) |
| | | } |
| | | |
| | | if err := s.Repository.CancelSubscribe(c.Param("id"), &req); err != nil { |
| | | c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()}) |
| | | return |
| | | } |
| | | |
| | | c.JSON(http.StatusOK, gin.H{"msg": "ok"}) |
| | | } |
| | |
| | | |
| | | return err |
| | | } |
| | | |
| | | func (s *SubscribeRepository) CancelSubscribe(sid string, req *vo.Subscribe) error { |
| | | var subscribeMsg vo.RequestCancelSubscribe |
| | | subscribeMsg.SubscribeObject = *req |
| | | |
| | | if req.SubscribeID == "" { |
| | | return errors.New("订阅消息主题为空") |
| | | } |
| | | |
| | | // 查找下级 |
| | | var platform models.SubPlatform |
| | | err := platform.FindById(sid) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | uri := fmt.Sprintf("http://%s:%d/VIID/Subscribes/%s", platform.RemoteIP, platform.RemotePort, req.SubscribeID) |
| | | body, _ := json.Marshal(subscribeMsg) |
| | | if client.UpdateSubscribe(uri, body) != vo.StatusSuccess { |
| | | return errors.New("发送订阅消息失败") |
| | | } |
| | | |
| | | var sub = models.Subscribe{ |
| | | Id: req.SubscribeID, |
| | | Status: req.SubscribeStatus, |
| | | FromId: sid, |
| | | Ext: *req, |
| | | } |
| | | |
| | | err = sub.Save() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | return err |
| | | } |
| | | |
| | | func (s *SubscribeRepository) UpdateSubscribe(sid string, req *vo.Subscribe) error { |
| | | var subscribeMsg vo.RequestSubscribe |
| | | subscribeMsg.SubscribeListObject.SubscribeObject = []vo.Subscribe{*req} |
| | |
| | | { |
| | | router.POST("/:id", subCtl.CreateSubscribes) |
| | | router.PUT("/:id", subCtl.UpdateSubscribes) |
| | | router.PUT("/cancel/:id", subCtl.UpdateSubscribes) |
| | | //router.GET("/:id", subCtl.Faces) |
| | | //router.DELETE("/:id", subCtl.Faces) |
| | | } |
| | |
| | | } `json:"SubscribeListObject"` |
| | | } |
| | | |
| | | type RequestCancelSubscribe struct { |
| | | SubscribeObject Subscribe `json:"SubscribeObject"` |
| | | } |
| | | |
| | | type RequestSubscribeNotification struct { |
| | | SubscribeNotificationListObject struct { |
| | | SubscribeNotificationObject []interface{} `json:"SubscribeNotificationObject"` |