Migrate services to use EF Core repositories #64

Closed
opened 2026-01-18 22:31:01 +00:00 by joezombie · 1 comment
joezombie commented 2026-01-18 22:31:01 +00:00 (Migrated from github.com)

Parent Epic

Part of #58 - Migrate to Entity Framework Core

Description

Update all existing services to use the new EF Core repositories instead of raw SQL database services.

Services to Update

1. PodcastFeedService

Current: Uses IPodcastDatabaseService for episode ordering
Change to: Use IEpisodeRepository

// Before
private readonly IPodcastDatabaseService _database;
var dbEpisodes = await _database.GetEpisodesAsync(feedName);

// After
private readonly IEpisodeRepository _episodeRepository;
private readonly IFeedRepository _feedRepository;
var feed = await _feedRepository.GetByNameAsync(feedName);
var dbEpisodes = await _episodeRepository.GetByFeedIdAsync(feed.Id);

2. PlaylistWatcherService

Current: Uses both IPodcastDatabaseService and ICentralDatabaseService
Change to: Use repositories via IUnitOfWork

// Before
await _database.MarkVideoDownloadedAsync(feedName, videoId, filename);
await _database.SyncPlaylistInfoAsync(feedName, videos, directory);

// After
await _unitOfWork.DownloadedVideos.AddAsync(new DownloadedVideo { ... });
await _unitOfWork.Episodes.AddRangeAsync(episodes);
await _unitOfWork.SaveChangesAsync();

3. YouTubeDownloadService

Current: May reference database services
Change to: Use download queue repository

4. Dashboard Blazor Components

Current: Inject ICentralDatabaseService
Change to: Inject repositories or a dashboard-specific service

// Before
@inject ICentralDatabaseService Database
var feeds = await Database.GetAllFeedsAsync();
var episodes = await Database.GetEpisodesAsync(feed.Id);

// After
@inject IFeedRepository FeedRepository
@inject IEpisodeRepository EpisodeRepository
var feeds = await FeedRepository.GetAllAsync();
var episodes = await EpisodeRepository.GetByFeedIdAsync(feed.Id);

Mapping Between Old and New

Old Method New Repository Method
GetAllFeedsAsync() _feedRepository.GetAllAsync()
GetFeedByNameAsync(name) _feedRepository.GetByNameAsync(name)
GetEpisodesAsync(feedId) _episodeRepository.GetByFeedIdAsync(feedId)
IsVideoDownloadedAsync(feedId, videoId) _downloadedVideoRepository.ExistsAsync(feedId, videoId)
MarkVideoDownloadedAsync(...) _downloadedVideoRepository.AddAsync(...)
LogActivityAsync(...) _activityLogRepository.LogAsync(...)
AddToDownloadQueueAsync(...) _downloadQueueRepository.AddAsync(...)

Files to Update

  1. Services/PodcastFeedService.cs
  2. Services/PlaylistWatcherService.cs
  3. Services/YouTubeDownloadService.cs
  4. Components/Pages/Dashboard.razor
  5. Components/Pages/Feeds/FeedList.razor
  6. Components/Pages/Feeds/FeedDetails.razor
  7. Components/Pages/Feeds/FeedEdit.razor
  8. Components/Pages/Episodes/EpisodeList.razor
  9. Components/Pages/Downloads.razor
  10. Program.cs (DI registration)

Tasks

  • Update PodcastFeedService to use repositories
  • Update PlaylistWatcherService to use repositories
  • Update YouTubeDownloadService if needed
  • Update Dashboard.razor
  • Update FeedList.razor
  • Update FeedDetails.razor
  • Update FeedEdit.razor
  • Update EpisodeList.razor
  • Update Downloads.razor
  • Update Program.cs DI registration
  • Remove old service injections
  • Add proper error handling for repository operations
  • Ensure all async operations use cancellation tokens

Acceptance Criteria

  • All services use new repositories
  • No direct references to old database services
  • All functionality preserved
  • Performance equivalent or better
  • Unit tests pass (if applicable)
## Parent Epic Part of #58 - Migrate to Entity Framework Core ## Description Update all existing services to use the new EF Core repositories instead of raw SQL database services. ## Services to Update ### 1. PodcastFeedService **Current:** Uses `IPodcastDatabaseService` for episode ordering **Change to:** Use `IEpisodeRepository` ```csharp // Before private readonly IPodcastDatabaseService _database; var dbEpisodes = await _database.GetEpisodesAsync(feedName); // After private readonly IEpisodeRepository _episodeRepository; private readonly IFeedRepository _feedRepository; var feed = await _feedRepository.GetByNameAsync(feedName); var dbEpisodes = await _episodeRepository.GetByFeedIdAsync(feed.Id); ``` ### 2. PlaylistWatcherService **Current:** Uses both `IPodcastDatabaseService` and `ICentralDatabaseService` **Change to:** Use repositories via `IUnitOfWork` ```csharp // Before await _database.MarkVideoDownloadedAsync(feedName, videoId, filename); await _database.SyncPlaylistInfoAsync(feedName, videos, directory); // After await _unitOfWork.DownloadedVideos.AddAsync(new DownloadedVideo { ... }); await _unitOfWork.Episodes.AddRangeAsync(episodes); await _unitOfWork.SaveChangesAsync(); ``` ### 3. YouTubeDownloadService **Current:** May reference database services **Change to:** Use download queue repository ### 4. Dashboard Blazor Components **Current:** Inject `ICentralDatabaseService` **Change to:** Inject repositories or a dashboard-specific service ```csharp // Before @inject ICentralDatabaseService Database var feeds = await Database.GetAllFeedsAsync(); var episodes = await Database.GetEpisodesAsync(feed.Id); // After @inject IFeedRepository FeedRepository @inject IEpisodeRepository EpisodeRepository var feeds = await FeedRepository.GetAllAsync(); var episodes = await EpisodeRepository.GetByFeedIdAsync(feed.Id); ``` ## Mapping Between Old and New | Old Method | New Repository Method | |------------|----------------------| | `GetAllFeedsAsync()` | `_feedRepository.GetAllAsync()` | | `GetFeedByNameAsync(name)` | `_feedRepository.GetByNameAsync(name)` | | `GetEpisodesAsync(feedId)` | `_episodeRepository.GetByFeedIdAsync(feedId)` | | `IsVideoDownloadedAsync(feedId, videoId)` | `_downloadedVideoRepository.ExistsAsync(feedId, videoId)` | | `MarkVideoDownloadedAsync(...)` | `_downloadedVideoRepository.AddAsync(...)` | | `LogActivityAsync(...)` | `_activityLogRepository.LogAsync(...)` | | `AddToDownloadQueueAsync(...)` | `_downloadQueueRepository.AddAsync(...)` | ## Files to Update 1. `Services/PodcastFeedService.cs` 2. `Services/PlaylistWatcherService.cs` 3. `Services/YouTubeDownloadService.cs` 4. `Components/Pages/Dashboard.razor` 5. `Components/Pages/Feeds/FeedList.razor` 6. `Components/Pages/Feeds/FeedDetails.razor` 7. `Components/Pages/Feeds/FeedEdit.razor` 8. `Components/Pages/Episodes/EpisodeList.razor` 9. `Components/Pages/Downloads.razor` 10. `Program.cs` (DI registration) ## Tasks - [ ] Update PodcastFeedService to use repositories - [ ] Update PlaylistWatcherService to use repositories - [ ] Update YouTubeDownloadService if needed - [ ] Update Dashboard.razor - [ ] Update FeedList.razor - [ ] Update FeedDetails.razor - [ ] Update FeedEdit.razor - [ ] Update EpisodeList.razor - [ ] Update Downloads.razor - [ ] Update Program.cs DI registration - [ ] Remove old service injections - [ ] Add proper error handling for repository operations - [ ] Ensure all async operations use cancellation tokens ## Acceptance Criteria - [ ] All services use new repositories - [ ] No direct references to old database services - [ ] All functionality preserved - [ ] Performance equivalent or better - [ ] Unit tests pass (if applicable)
joezombie commented 2026-01-27 08:37:36 +00:00 (Migrated from github.com)

Completed: All services now use EF Core repositories through IPodcastDataService.

Services Migrated:

  • PodcastFeedService - Uses IPodcastDataService for episode data
  • PlaylistWatcherService - Uses IPodcastDataService for all database operations
  • All Blazor Components - Use IPodcastDataService instead of ICentralDatabaseService

Architecture:

  • IPodcastDataService - High-level facade providing business logic
  • IFeedRepository - Feed CRUD operations
  • IEpisodeRepository - Episode CRUD operations
  • IDownloadRepository - Download tracking and queue management
  • IActivityRepository - Activity logging

All legacy services (PodcastDatabaseService, CentralDatabaseService) have been removed.

Completed: All services now use EF Core repositories through IPodcastDataService. ## Services Migrated: - **PodcastFeedService** - Uses IPodcastDataService for episode data - **PlaylistWatcherService** - Uses IPodcastDataService for all database operations - **All Blazor Components** - Use IPodcastDataService instead of ICentralDatabaseService ## Architecture: - **IPodcastDataService** - High-level facade providing business logic - **IFeedRepository** - Feed CRUD operations - **IEpisodeRepository** - Episode CRUD operations - **IDownloadRepository** - Download tracking and queue management - **IActivityRepository** - Activity logging All legacy services (PodcastDatabaseService, CentralDatabaseService) have been removed.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
joezombie/castr#64
No description provided.