< Summary

Information
Class: Chronicis.Client.Services.ExternalLinkApiService
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/ExternalLinkApiService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 28
Coverable lines: 28
Total lines: 78
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetSuggestionsAsync()0%7280%
GetContentAsync()0%2040%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/ExternalLinkApiService.cs

#LineLine coverage
 1using System.Net.Http.Json;
 2using Chronicis.Shared.DTOs;
 3
 4namespace Chronicis.Client.Services;
 5
 6public class ExternalLinkApiService : IExternalLinkApiService
 7{
 8    private readonly HttpClient _http;
 9    private readonly ILogger<ExternalLinkApiService> _logger;
 10
 011    public ExternalLinkApiService(HttpClient http, ILogger<ExternalLinkApiService> logger)
 12    {
 013        _http = http;
 014        _logger = logger;
 015    }
 16
 17    public async Task<List<ExternalLinkSuggestionDto>> GetSuggestionsAsync(
 18        Guid? worldId,
 19        string source,
 20        string query,
 21        CancellationToken ct)
 22    {
 023        if (string.IsNullOrWhiteSpace(source))
 24        {
 025            return new List<ExternalLinkSuggestionDto>();
 26        }
 27
 028        var url = $"external-links/suggestions?source={Uri.EscapeDataString(source)}&query={Uri.EscapeDataString(query ?
 29
 030        if (worldId.HasValue)
 31        {
 032            url += $"&worldId={worldId.Value}";
 33        }
 34
 35        try
 36        {
 037            var results = await _http.GetFromJsonAsync<List<ExternalLinkSuggestionDto>>(url, ct);
 038            return results ?? new List<ExternalLinkSuggestionDto>();
 39        }
 040        catch (OperationCanceledException)
 41        {
 042            return new List<ExternalLinkSuggestionDto>();
 43        }
 044        catch (Exception ex)
 45        {
 046            _logger.LogWarning(ex, "Failed to fetch external link suggestions for source {Source}", source);
 047            return new List<ExternalLinkSuggestionDto>();
 48        }
 049    }
 50
 51    public async Task<ExternalLinkContentDto?> GetContentAsync(
 52        string source,
 53        string id,
 54        CancellationToken ct)
 55    {
 056        if (string.IsNullOrWhiteSpace(source) || string.IsNullOrWhiteSpace(id))
 57        {
 058            return null;
 59        }
 60
 061        var url =
 062            $"external-links/content?source={Uri.EscapeDataString(source)}&id={Uri.EscapeDataString(id)}";
 63
 64        try
 65        {
 066            return await _http.GetFromJsonAsync<ExternalLinkContentDto>(url, ct);
 67        }
 068        catch (OperationCanceledException)
 69        {
 070            return null;
 71        }
 072        catch (Exception ex)
 73        {
 074            _logger.LogWarning(ex, "Failed to fetch external link content for source {Source} and id {Id}", source, id);
 075            return null;
 76        }
 077    }
 78}