public async Task <UserRelationReadDto> CreateUserRelationAsync(UserRelationCreateDto userRelation)
        {
            if (userRelation == null)
            {
                throw new InstagramException("parameters_are_null",
                                             $"UserId and FollowedUserId is required, can't be null.");
            }

            var userRelationModelCheck = await _userRepository.CheckRelationshipAsync(userRelation.UserId, userRelation.FollowedUserId);

            if (userRelationModelCheck == null)
            {
                var userRelationModel = _mapper.Map <UserRelation>(userRelation);
                await _userRepository.CreateUserRelationAsync(userRelationModel);

                var userRelationDto = _mapper.Map <UserRelationReadDto>(userRelationModel);
                userRelationDto.Relation = 1;

                await _busClient.PublishAsync(new UserFollowed(userRelation.UserId, userRelation.FollowedUserId));

                return(userRelationDto);
            }
            else
            {
                var userRelationDto = _mapper.Map <UserRelationReadDto>(userRelationModelCheck);
                userRelationDto.Relation = 1;

                return(userRelationDto);
            }
        }
Пример #2
0
        public async Task <ActionResult <IEnumerable <UserRelationReadDto> > > CreateUserRelation([FromBody] UserRelationCreateDto userRelation)
        {
            var userRelationReadDto = await _userService.CreateUserRelationAsync(userRelation);

            return(Ok(userRelationReadDto));
        }