< Summary

Information
Class: Pomodoro.Web.Services.Repositories.ActivityRepository
Assembly: Pomodoro.Web
File(s): /home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/Repositories/ActivityRepository.cs
Line coverage
100%
Covered lines: 51
Uncovered lines: 0
Coverable lines: 51
Total lines: 85
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetAllAsync()100%44100%
GetByDateRangeAsync()100%88100%
GetPagedAsync()100%11100%
GetByIdAsync()100%11100%
SaveAsync()100%22100%
DeleteAsync()100%11100%
GetCountAsync()100%44100%
ClearAllAsync()100%11100%

File(s)

/home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/Repositories/ActivityRepository.cs

#LineLine coverage
 1using Microsoft.Extensions.Logging;
 2using Pomodoro.Web.Models;
 3
 4namespace Pomodoro.Web.Services.Repositories;
 5
 6/// <summary>
 7/// Repository implementation for activity record persistence using IndexedDB
 8/// </summary>
 9public class ActivityRepository : IActivityRepository
 10{
 11    private readonly IIndexedDbService _indexedDb;
 12    private readonly ILogger<ActivityRepository> _logger;
 13
 3314    public ActivityRepository(IIndexedDbService indexedDb, ILogger<ActivityRepository> logger)
 3315    {
 3316        _indexedDb = indexedDb;
 3317        _logger = logger;
 3318    }
 19
 20    public async Task<List<ActivityRecord>> GetAllAsync()
 921    {
 922        var all = await _indexedDb.GetAllAsync<ActivityRecord>(Constants.Storage.ActivitiesStore);
 2523        return all?.OrderByDescending(a => a.CompletedAt).ToList() ?? new List<ActivityRecord>();
 924    }
 25
 26    public async Task<List<ActivityRecord>> GetByDateRangeAsync(DateTime start, DateTime end)
 1227    {
 1228        var fromUtc = start.Kind != DateTimeKind.Utc ? DateTime.SpecifyKind(start, DateTimeKind.Local).ToUniversalTime()
 1229        var toUtc = end.Kind != DateTimeKind.Utc ? DateTime.SpecifyKind(end, DateTimeKind.Local).ToUniversalTime() : end
 1230        var fromDate = fromUtc.ToString(Constants.DateFormats.IsoFormat);
 1231        var toDate = toUtc.ToString(Constants.DateFormats.IsoFormat);
 32
 1233        var activities = await _indexedDb.QueryByDateRangeAsync<ActivityRecord>(
 1234            Constants.Storage.ActivitiesStore,
 1235            Constants.Storage.CompletedAtIndex,
 1236            fromDate,
 1237            toDate);
 38
 4939        return activities?.OrderByDescending(a => a.CompletedAt).ToList() ?? new List<ActivityRecord>();
 1240    }
 41
 42    public async Task<List<ActivityRecord>> GetPagedAsync(DateTime start, DateTime end, int skip, int take)
 443    {
 444        var all = await GetByDateRangeAsync(start, end);
 445        return all.Skip(skip).Take(take).ToList();
 446    }
 47
 48    public async Task<ActivityRecord?> GetByIdAsync(Guid id)
 349    {
 350        return await _indexedDb.GetAsync<ActivityRecord>(Constants.Storage.ActivitiesStore, id.ToString());
 351    }
 52
 53    public async Task<bool> SaveAsync(ActivityRecord activity)
 454    {
 455        var success = await _indexedDb.PutAsync(Constants.Storage.ActivitiesStore, activity);
 456        if (!success)
 257        {
 258            _logger.LogWarning(Constants.Messages.LogFailedToSaveActivity, activity.Id);
 259        }
 460        return success;
 461    }
 62
 63    public async Task<bool> DeleteAsync(Guid id)
 364    {
 365        return await _indexedDb.DeleteAsync(Constants.Storage.ActivitiesStore, id.ToString());
 366    }
 67
 68    public async Task<int> GetCountAsync(DateTime? start = null, DateTime? end = null)
 769    {
 770        if (start.HasValue && end.HasValue)
 271        {
 272            var activities = await GetByDateRangeAsync(start.Value, end.Value);
 273            return activities.Count;
 74        }
 75
 576        var all = await GetAllAsync();
 577        return all.Count;
 778    }
 79
 80    public async Task<bool> ClearAllAsync()
 281    {
 282        await _indexedDb.ClearAsync(Constants.Storage.ActivitiesStore);
 283        return true;
 284    }
 85}