Add deleted events

This commit is contained in:
Zoe Roux 2024-03-17 12:35:10 +01:00
parent c15dcb02ec
commit 3a5d6ed2cd
No known key found for this signature in database
2 changed files with 26 additions and 9 deletions

View File

@ -30,6 +30,7 @@ namespace Kyoo.Abstractions.Controllers;
public interface IWatchStatusRepository
{
public delegate Task ResourceEventHandler<T>(T resource);
public delegate Task WatchStatusDeletedEventHandler(Guid resourceId, Guid userId);
Task<ICollection<IWatchlist>> GetAll(
Filter<IWatchlist>? filter = default,
@ -47,24 +48,30 @@ public interface IWatchStatusRepository
int? percent
);
static event ResourceEventHandler<Movie> OnMovieStatusChangedHandler;
protected static Task OnMovieStatusChanged(Movie obj) =>
static event ResourceEventHandler<MovieWatchStatus> OnMovieStatusChangedHandler;
protected static Task OnMovieStatusChanged(MovieWatchStatus obj) =>
OnMovieStatusChangedHandler?.Invoke(obj) ?? Task.CompletedTask;
Task DeleteMovieStatus(Guid movieId, Guid userId);
static event WatchStatusDeletedEventHandler OnMovieStatusDeletedHandler;
protected static Task OnMovieStatusDeleted(Guid movieId, Guid userId) =>
OnMovieStatusDeletedHandler?.Invoke(movieId, userId) ?? Task.CompletedTask;
Task<ShowWatchStatus?> GetShowStatus(Guid showId, Guid userId);
Task<ShowWatchStatus?> SetShowStatus(Guid showId, Guid userId, WatchStatus status);
static event ResourceEventHandler<Show> OnShowStatusChangedHandler;
protected static Task OnShowStatusChanged(Show obj) =>
static event ResourceEventHandler<ShowWatchStatus> OnShowStatusChangedHandler;
protected static Task OnShowStatusChanged(ShowWatchStatus obj) =>
OnShowStatusChangedHandler?.Invoke(obj) ?? Task.CompletedTask;
Task DeleteShowStatus(Guid showId, Guid userId);
static event WatchStatusDeletedEventHandler OnShowStatusDeletedHandler;
protected static Task OnShowStatusDeleted(Guid showId, Guid userId) =>
OnShowStatusDeletedHandler?.Invoke(showId, userId) ?? Task.CompletedTask;
Task<EpisodeWatchStatus?> GetEpisodeStatus(Guid episodeId, Guid userId);
/// <param name="watchedTime">Where the user has stopped watching. Only usable if Status
@ -77,10 +84,14 @@ public interface IWatchStatusRepository
int? percent
);
static event ResourceEventHandler<Episode> OnEpisodeStatusChangedHandler;
protected static Task OnEpisodeStatusChanged(Episode obj) =>
static event ResourceEventHandler<EpisodeWatchStatus> OnEpisodeStatusChangedHandler;
protected static Task OnEpisodeStatusChanged(EpisodeWatchStatus obj) =>
OnEpisodeStatusChangedHandler?.Invoke(obj) ?? Task.CompletedTask;
Task DeleteEpisodeStatus(Guid episodeId, Guid userId);
static event WatchStatusDeletedEventHandler OnEpisodeStatusDeletedHandler;
protected static Task OnEpisodeStatusDeleted(Guid episodeId, Guid userId) =>
OnEpisodeStatusDeletedHandler?.Invoke(episodeId, userId) ?? Task.CompletedTask;
}

View File

@ -265,6 +265,7 @@ public class WatchStatusRepository(
.MovieWatchStatus.Upsert(ret)
.UpdateIf(x => status != Watching || x.Status != Completed)
.RunAsync();
await IWatchStatusRepository.OnMovieStatusChanged(ret);
return ret;
}
@ -274,6 +275,7 @@ public class WatchStatusRepository(
await database
.MovieWatchStatus.Where(x => x.MovieId == movieId && x.UserId == userId)
.ExecuteDeleteAsync();
await IWatchStatusRepository.OnMovieStatusDeleted(movieId, userId);
}
/// <inheritdoc />
@ -403,6 +405,7 @@ public class WatchStatusRepository(
.ShowWatchStatus.Upsert(ret)
.UpdateIf(x => status != Watching || x.Status != Completed || newEpisode)
.RunAsync();
await IWatchStatusRepository.OnShowStatusChanged(ret);
return ret;
}
@ -416,6 +419,7 @@ public class WatchStatusRepository(
await database
.EpisodeWatchStatus.Where(x => x.Episode.ShowId == showId && x.UserId == userId)
.ExecuteDeleteAsync();
await IWatchStatusRepository.OnShowStatusDeleted(showId, userId);
}
/// <inheritdoc />
@ -475,6 +479,7 @@ public class WatchStatusRepository(
.EpisodeWatchStatus.Upsert(ret)
.UpdateIf(x => status != Watching || x.Status != Completed)
.RunAsync();
await IWatchStatusRepository.OnEpisodeStatusChanged(ret);
await SetShowStatus(episode.ShowId, userId, WatchStatus.Watching);
return ret;
}
@ -485,5 +490,6 @@ public class WatchStatusRepository(
await database
.EpisodeWatchStatus.Where(x => x.EpisodeId == episodeId && x.UserId == userId)
.ExecuteDeleteAsync();
await IWatchStatusRepository.OnEpisodeStatusDeleted(episodeId, userId);
}
}