예제 #1
0
        public async Task <Unit> Handle(AddReactionCommand request, CancellationToken cancellationToken)
        {
            var activity = await this.activityRepository.GetActivityAsync(request.ActivityId);

            var reactingUser = await this.userRepository.GetUserAsync(request.UserId);

            switch (request.Type)
            {
            case ReactionType.Cheers:
                activity.AddCheers(new Reaction(request.UserId, reactingUser.Name));
                break;

            case ReactionType.Like:
                activity.AddLike(new Reaction(request.UserId, reactingUser.Name));
                break;

            case ReactionType.Comment:
                activity.AddComment(new CommentReaction(request.UserId, reactingUser.Name, request.Comment));
                break;
            }

            await this.activityRepository.UpdateActivityAsync(request.UserId, activity.ToEntity());

            // add to queue
            var message = new ReactionAddedMessage(request.ActivityId, request.Type, request.UserId, request.Comment);
            await storageAccessService.AddQueueMessage(Constants.QueueNames.ReactionAdded, message);

            return(Unit.Value);
        }
예제 #2
0
        public async Task <Unit> Handle(DeleteActivityCommand request, CancellationToken cancellationToken)
        {
            await this.activityRepository.DeleteActivityAsync(request.UserId, request.ActivityId);

            // Delete activity in personalized feeds
            await storageAccessService.AddQueueMessage(QueueNames.DeleteActivity, new DeleteActivityMessage(request.ActivityId));

            return(Unit.Value);
        }
예제 #3
0
        public async Task <Unit> Handle(CreateOrUpdateUserCommand request, CancellationToken cancellationToken)
        {
            var result = await this.userRepository.CreateOrUpdateUserAsync(request);

            if (result.IsNewUser)
            {
                await this.drinkRepository.CreateDefaultDrinksForUserAsync(request.UserId);

                if (!string.IsNullOrEmpty(request.ProfileImageUrl))
                {
                    var httpClient = this.httpClientFactory.CreateClient();
                    using (var profileImageStream = await httpClient.GetStreamAsync(request.ProfileImageUrl))
                    {
                        await storageAccessService.SaveFileInBlobStorage(ContainerNames.ProfileImages, request.UserId, profileImageStream);
                    }
                }

                var activity = Activity.Domain.Activity.CreateRegistrationActivity(request.UserId, request.Name);

                await activityRepository.AddActivityAsync(activity.ToEntity());

                await activityRepository.AddToPersonalizedFeedAsync(request.UserId, activity.ToEntity());

                await activityRepository.AddToActivityAddedTopicAsync(activity.Id);
            }

            if (result.NameHasChanged)
            {
                var activity = Activity.Domain.Activity.CreateRenameActivity(request.UserId, request.Name, result.OriginalUserName);
                await activityRepository.AddActivityAsync(activity.ToEntity());

                var renameMessage = new UserRenamedMessage(request.UserId, result.OriginalUserName, request.Name);
                await storageAccessService.AddQueueMessage(QueueNames.UserRenamed, renameMessage);
            }

            return(Unit.Value);
        }