< Summary

Information
Class: Chronicis.Client.Services.PathApiService
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/PathApiService.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 45
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

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

#LineLine coverage
 1using System.Net.Http.Json;
 2using Chronicis.Shared.Routing;
 3
 4namespace Chronicis.Client.Services;
 5
 6/// <summary>
 7/// Client service for the unified path-resolution endpoint.
 8/// </summary>
 9public class PathApiService : IPathApiService
 10{
 11    private readonly HttpClient _http;
 12    private readonly ILogger<PathApiService> _logger;
 13
 14    public PathApiService(HttpClient http, ILogger<PathApiService> logger)
 15    {
 816        _http = http;
 817        _logger = logger;
 818    }
 19
 20    public async Task<SlugPathResolution?> ResolveAsync(string path, CancellationToken cancellationToken = default)
 21    {
 22        var encodedPath = string.Join("/", path.Trim('/').Split('/').Select(Uri.EscapeDataString));
 23
 24        try
 25        {
 26            var response = await _http.GetAsync($"paths/resolve/{encodedPath}", cancellationToken);
 27
 28            if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
 29                return null;
 30
 31            if (!response.IsSuccessStatusCode)
 32            {
 33                _logger.LogWarning("Path resolution failed for '{Path}': {StatusCode}", path, response.StatusCode);
 34                return null;
 35            }
 36
 37            return await response.Content.ReadFromJsonAsync<SlugPathResolution>(cancellationToken: cancellationToken);
 38        }
 39        catch (HttpRequestException ex)
 40        {
 41            _logger.LogError(ex, "Error resolving path '{Path}'", path);
 42            return null;
 43        }
 44    }
 45}