< Summary

Information
Class: Chronicis.Client.Services.SessionApiService
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/SessionApiService.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 105
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/SessionApiService.cs

#LineLine coverage
 1using System.Net.Http.Json;
 2using Chronicis.Shared.DTOs;
 3using Chronicis.Shared.DTOs.Sessions;
 4
 5namespace Chronicis.Client.Services;
 6
 7/// <summary>
 8/// Service for Session API operations used by tree/navigation.
 9/// </summary>
 10public class SessionApiService : ISessionApiService
 11{
 12    private readonly HttpClient _http;
 13    private readonly ILogger<SessionApiService> _logger;
 14
 15    public SessionApiService(HttpClient http, ILogger<SessionApiService> logger)
 16    {
 717        _http = http;
 718        _logger = logger;
 719    }
 20
 21    public async Task<List<SessionTreeDto>> GetSessionsByArcAsync(Guid arcId)
 22    {
 23        return await _http.GetListAsync<SessionTreeDto>(
 24            $"arcs/{arcId}/sessions",
 25            _logger,
 26            $"sessions for arc {arcId}");
 27    }
 28
 29    public async Task<SessionDto?> CreateSessionAsync(Guid arcId, SessionCreateDto dto)
 30    {
 31        return await _http.PostEntityAsync<SessionDto>(
 32            $"arcs/{arcId}/sessions",
 33            dto,
 34            _logger,
 35            $"session in arc {arcId}");
 36    }
 37
 38    public async Task<SessionDto?> GetSessionAsync(Guid sessionId)
 39    {
 40        return await _http.GetEntityAsync<SessionDto>(
 41            $"sessions/{sessionId}",
 42            _logger,
 43            $"session {sessionId}");
 44    }
 45
 46    public async Task<SessionDto?> UpdateSessionNotesAsync(Guid sessionId, SessionUpdateDto dto)
 47    {
 48        try
 49        {
 50            var response = await _http.PatchAsJsonAsync($"sessions/{sessionId}", dto);
 51            if (response.IsSuccessStatusCode)
 52            {
 53                return await response.Content.ReadFromJsonAsync<SessionDto>();
 54            }
 55
 56            var errorContent = await response.Content.ReadAsStringAsync();
 57            _logger.LogWarning("Failed to update session for {SessionId}: {StatusCode} - {Error}",
 58                sessionId, response.StatusCode, errorContent);
 59            return null;
 60        }
 61        catch (Exception ex)
 62        {
 63            _logger.LogError(ex, "Error updating session for {SessionId}", sessionId);
 64            return null;
 65        }
 66    }
 67
 68    public async Task<bool> DeleteSessionAsync(Guid sessionId)
 69    {
 70        return await _http.DeleteEntityAsync(
 71            $"sessions/{sessionId}",
 72            _logger,
 73            $"session {sessionId}");
 74    }
 75
 76    public async Task<SummaryGenerationDto?> GenerateAiSummaryAsync(Guid sessionId)
 77    {
 78        try
 79        {
 80            var response = await _http.PostAsJsonAsync($"sessions/{sessionId}/ai-summary/generate", new { });
 81            if (response.IsSuccessStatusCode)
 82            {
 83                return await response.Content.ReadFromJsonAsync<SummaryGenerationDto>();
 84            }
 85
 86            var errorContent = await response.Content.ReadAsStringAsync();
 87            _logger.LogWarning("Failed to generate session AI summary for {SessionId}: {StatusCode} - {Error}",
 88                sessionId, response.StatusCode, errorContent);
 89            return null;
 90        }
 91        catch (Exception ex)
 92        {
 93            _logger.LogError(ex, "Error generating session AI summary for {SessionId}", sessionId);
 94            return null;
 95        }
 96    }
 97
 98    public async Task<bool> ClearAiSummaryAsync(Guid sessionId)
 99    {
 100        return await _http.DeleteEntityAsync(
 101            $"sessions/{sessionId}/ai-summary",
 102            _logger,
 103            $"session AI summary for {sessionId}");
 104    }
 105}