public async Task <Result <UserQueue> > RegisterUserEvent(long userId)
        {
            var result = new Result <UserQueue>();

            if (userId < 1)
            {
                throw new ArgumentException("invalid userId");
            }
            var id = _identityFactory.NextId();

            var userQueue = new UserQueue
            {
                Id        = id,
                QueueName = GenerateEventsQueueName(id),
                UserId    = userId
            };

            await _userQueueRepository.Create(userQueue);

            // TODO: need to think about the logic to kill this queue.
            _rabbitMqClient.DeclareQueue(userQueue.QueueName);

            result.SuccessResult = userQueue;
            return(result);
        }
Exemple #2
0
 private notificationModels.Notification GetNotificationFromCreateNotificationRequest(CreateNotificationRequest createNotificationRequest) => new notificationModels.Notification
 {
     Id      = _identityFactory.NextId(),
     Content = createNotificationRequest.Content,
     Type    = createNotificationRequest.Type,
     Url     = createNotificationRequest.Url,
     UserId  = createNotificationRequest.UserId
 };
Exemple #3
0
 private tweetModels.Tweet CreateTweetFromCreateTweetRequest(CreateTweetRequest createTweetRequest) =>
 new tweetModels.Tweet
 {
     Id               = _identityFactory.NextId(),
     AuthorId         = createTweetRequest.AuthorId,
     Content          = createTweetRequest.Content,
     ParentTweetId    = createTweetRequest.ParentTweetId,
     QuotedTweetId    = createTweetRequest.QuotedTweetId,
     RetweetedTweetId = createTweetRequest.RetweetedTweetId
 };
        private Follow GetFollow(FollowRequest createFollowRequest)
        {
            var id     = _identityFactory.NextId();
            var follow = new Follow
            {
                Id         = id,
                FolloweeId = createFollowRequest.FolloweeId,
                FollowerId = createFollowRequest.FollowerId,
                Status     = FollowStatus.Pending
            };

            return(follow);
        }
        public async Task <Result <userModels.User> > CreateUser(CreateUserRequest createUserRequest)
        {
            if (createUserRequest == null)
            {
                throw new ArgumentNullException("createUserRequest");
            }
            var result           = new Result <userModels.User>();
            var userByEmailTask  = _userRepository.GetByEmail(createUserRequest.Email);
            var userByHandleTask = _userRepository.GetByHandle(createUserRequest.Handle);

            var   usersAllTaks = Task.WhenAll(userByEmailTask, userByHandleTask);
            await usersAllTaks;

            if (usersAllTaks.Status != TaskStatus.RanToCompletion)
            {
                throw usersAllTaks.Exception;
            }

            if (userByEmailTask.Result != null && userByEmailTask.Result.Id > 0)
            {
                result.ErrorMessages.Add("Email Already in use");
                return(result);
            }

            if (userByHandleTask.Result != null && userByHandleTask.Result.Id > 0)
            {
                result.ErrorMessages.Add("Handle Already in use");
                return(result);
            }

            var user = NewUser(createUserRequest, _idFactory.NextId());
            await _userRepository.Create(user);

            result.SuccessResult = user;
            return(result);
        }