(c *gin.Context)
| 23 | } |
| 24 | |
| 25 | func Push(c *gin.Context) { |
| 26 | var formPush FormPush |
| 27 | if err := c.ShouldBindBodyWith(&formPush, binding.JSON); err != nil { |
| 28 | tools.FailWithMsg(c, err.Error()) |
| 29 | return |
| 30 | } |
| 31 | authToken := formPush.AuthToken |
| 32 | msg := formPush.Msg |
| 33 | toUserId := formPush.ToUserId |
| 34 | toUserIdInt, _ := strconv.Atoi(toUserId) |
| 35 | getUserNameReq := &proto.GetUserInfoRequest{UserId: toUserIdInt} |
| 36 | code, toUserName := rpc.RpcLogicObj.GetUserNameByUserId(getUserNameReq) |
| 37 | if code == tools.CodeFail { |
| 38 | tools.FailWithMsg(c, "rpc fail get friend userName") |
| 39 | return |
| 40 | } |
| 41 | checkAuthReq := &proto.CheckAuthRequest{AuthToken: authToken} |
| 42 | code, fromUserId, fromUserName := rpc.RpcLogicObj.CheckAuth(checkAuthReq) |
| 43 | if code == tools.CodeFail { |
| 44 | tools.FailWithMsg(c, "rpc fail get self info") |
| 45 | return |
| 46 | } |
| 47 | roomId := formPush.RoomId |
| 48 | req := &proto.Send{ |
| 49 | Msg: msg, |
| 50 | FromUserId: fromUserId, |
| 51 | FromUserName: fromUserName, |
| 52 | ToUserId: toUserIdInt, |
| 53 | ToUserName: toUserName, |
| 54 | RoomId: roomId, |
| 55 | Op: config.OpSingleSend, |
| 56 | } |
| 57 | code, rpcMsg := rpc.RpcLogicObj.Push(req) |
| 58 | if code == tools.CodeFail { |
| 59 | tools.FailWithMsg(c, rpcMsg) |
| 60 | return |
| 61 | } |
| 62 | tools.SuccessWithMsg(c, "ok", nil) |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | type FormRoom struct { |
| 67 | AuthToken string `form:"authToken" json:"authToken" binding:"required"` |
nothing calls this directly
no test coverage detected