public async Task <IActionResult> Subscribe(Guid id, [FromBody] SubscribeUser model)
        {
            var userId = Guid.Parse(User.FindFirst("sub").Value);

            if (userId != id)
            {
                return(Forbid());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _userService.GetUserById(id);

            if (user == null)
            {
                return(NotFound());
            }

            var subscription = await _userService.GetSubscriptionById(model.SubscriptionId);

            if (subscription == null)
            {
                return(BadRequest("Invalid subscription"));
            }

            var userSubscription = await _userService.Subscribe(user, subscription);

            return(Ok(_mapper.Map <UserSubscription>(userSubscription)));
        }
Esempio n. 2
0
        /// <summary>
        /// 購読登録処理
        /// </summary>
        /// <param name="subscribeUser">登録ユーザー情報</param>
        public void Register(SubscribeUser subscribeUser)
        {
            var tags = new List <string>()
            {
                Constant.Push.Tags.UserNamePrefix + subscribeUser.Name
            };
            var pnsHandle = this.authHelper.GetToken(Constant.TokenKey);

            this.notificationHubManager.Register(pnsHandle, tags);
        }
        public void 購読登録処理_タグあり_ユーザ名()
        {
            // 設定
            var pnsHandle     = "pnsHandle";
            var subscribeUser = new SubscribeUser()
            {
                Name = "fujitsu"
            };
            var tag = Constant.Push.Tags.UserNamePrefix + subscribeUser.Name;

            this.notificationHub = new Mock <INotificationHub>();
            this.notificationHub.Setup(m => m.RegisterTemplate(pnsHandle, It.IsAny <List <string> >()));
            this.notificationHubManager.SetNotificationHub(this.notificationHub.Object);
            this.authHelper.Setup(m => m.GetToken(It.Is <string>(p => p == Constant.TokenKey))).Returns(pnsHandle);
            this.subscribeManager = new SubscribeManager(this.authHelper.Object);

            // 実行
            this.subscribeManager.Register(subscribeUser);

            // 検証
            this.authHelper.Verify(m => m.GetToken(Constant.TokenKey));
            this.notificationHub.Verify(m => m.RegisterTemplate(pnsHandle, It.Is <List <string> >(a => a[0] == tag)));
        }
Esempio n. 4
0
 public void TearDown()
 {
     this.subscribeUser = new SubscribeUser();
 }
Esempio n. 5
0
 public void SetUp()
 {
     this.subscribeUser = new SubscribeUser();
 }