| | |
| | | package controller |
| | | |
| | | import ( |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/repository" |
| | | "gat1400Exchange/vo" |
| | |
| | | return controller |
| | | } |
| | | |
| | | func (s SubscribeController) SubscribesList(c *gin.Context) { |
| | | subList, _ := s.Repository.List() |
| | | func (s SubscribeController) VIIDSubscribesList(c *gin.Context) { |
| | | fromId := c.GetHeader("User-Identify") |
| | | subList, _ := s.Repository.ListByFromId(fromId) |
| | | |
| | | c.Header("Content-Type", "application/VIID+json;charset=UTF-8") |
| | | c.JSON(http.StatusOK, gin.H{"SubscribeList": subList}) |
| | | } |
| | | |
| | | func (s SubscribeController) Subscribes(c *gin.Context) { |
| | | func (s SubscribeController) VIIDSubscribes(c *gin.Context) { |
| | | var req vo.RequestSubscribe |
| | | if err := c.BindJSON(&req); err != nil { |
| | | c.AbortWithStatus(http.StatusBadRequest) |
| | |
| | | |
| | | var rsp vo.ResponseStatusList |
| | | for idx, sub := range req.SubscribeListObject.SubscribeObject { |
| | | if err := s.Repository.CreateSubscribe(fromId, &req.SubscribeListObject.SubscribeObject[idx]); err == nil { |
| | | if err := s.Repository.SaveReceiveSubscribe(fromId, &req.SubscribeListObject.SubscribeObject[idx]); err == nil { |
| | | rsp.ResponseStatusObject = append(rsp.ResponseStatusObject, vo.ResponseStatus{ |
| | | RequestURL: c.FullPath(), |
| | | StatusCode: vo.StatusSuccess, |
| | |
| | | c.JSON(http.StatusOK, gin.H{"ResponseStatusListObject": rsp}) |
| | | } |
| | | |
| | | func (s SubscribeController) UpdateSubscribes(c *gin.Context) { |
| | | func (s SubscribeController) VIIDUpdateSubscribes(c *gin.Context) { |
| | | var req vo.RequestSubscribe |
| | | if err := c.BindJSON(&req); err != nil { |
| | | c.AbortWithStatus(http.StatusBadRequest) |
| | |
| | | |
| | | var rsp vo.ResponseStatusList |
| | | for idx, sub := range req.SubscribeListObject.SubscribeObject { |
| | | if err := s.Repository.UpdateSubscribe(&req.SubscribeListObject.SubscribeObject[idx]); err == nil { |
| | | if err := s.Repository.UpdateReceiveSubscribe(&req.SubscribeListObject.SubscribeObject[idx]); err == nil { |
| | | rsp.ResponseStatusObject = append(rsp.ResponseStatusObject, vo.ResponseStatus{ |
| | | RequestURL: c.FullPath(), |
| | | StatusCode: vo.StatusSuccess, |
| | |
| | | c.JSON(http.StatusOK, gin.H{"ResponseStatusListObject": rsp}) |
| | | } |
| | | |
| | | func (s SubscribeController) DeleteSubscribe(c *gin.Context) { |
| | | func (s SubscribeController) VIIDDeleteSubscribe(c *gin.Context) { |
| | | idList := c.Query("IDList") |
| | | var rsp vo.ResponseStatusList |
| | | |
| | | for _, id := range strings.Split(idList, ",") { |
| | | if err := s.Repository.DeleteSubscribe(id); err == nil { |
| | | if err := s.Repository.DeleteReceiveSubscribe(id); err == nil { |
| | | rsp.ResponseStatusObject = append(rsp.ResponseStatusObject, vo.ResponseStatus{ |
| | | RequestURL: c.FullPath(), |
| | | StatusCode: vo.StatusSuccess, |
| | |
| | | }) |
| | | |
| | | // 转发 |
| | | go s.Srv.FaceForward(msg.FaceObjectList.FaceObject) |
| | | if config.ForwardConf.SyncServer != "" { |
| | | go s.Srv.FaceForward(msg.FaceObjectList.FaceObject) |
| | | } |
| | | } |
| | | |
| | | c.Header("Content-Type", "application/VIID+json;charset=UTF-8") |
| | | c.JSON(http.StatusOK, gin.H{"ResponseStatusListObject": rsp}) |
| | | } |
| | | |
| | | // CreateSubscribes 添加下级平台的订阅消息 |
| | | func (s SubscribeController) CreateSubscribes(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.CreateSubscribe(c.Param("id"), &req); err != nil { |
| | | c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()}) |
| | | return |
| | | } |
| | | |
| | | c.JSON(http.StatusOK, gin.H{"msg": "ok"}) |
| | | } |