コード例 #1
0
        internal async Task <bool> AddLike(string currentUsername, string targetUsername, CancellationToken cancellationToken = default)
        {
            _logger.LogInformation("Adding like to {TargetUserId} from {CurrentUserId}", targetUsername, currentUsername);

            var targetUserDb = await _developerRepository.GetByUsername(targetUsername, cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            if (targetUserDb.Likes == null)
            {
                targetUserDb.Likes = new List <string>();
            }
            targetUserDb.Likes.Add(currentUsername);

            _ = await _developerRepository.Update(targetUserDb, cancellationToken);

            var currentUserDb = await _developerRepository.GetByUsername(currentUsername, cancellationToken);

            return(currentUserDb.Likes != null && currentUserDb.Likes.Contains(targetUsername));
        }