Some updates to Endpoint Logic

Ensure that we are adding videos to the playlist database object when we insert them.
Updated logic to follow profiles for playlist.
Do not search for existing subs when inserting a new sub, the sub's belongs to id will be different.
Formatted linq statement to be multi-line, instead of single line, to make it easier to read.
Removed check for subscription if we are adding a new one, the profile id is going to be different.
Ensure we are deleting subs from the database when they are no longer associated with a profile.
This commit is contained in:
Mario Steele 2025-08-04 19:13:17 -05:00
parent f34ad94ea6
commit 8187a03419
2 changed files with 39 additions and 27 deletions

View file

@ -33,6 +33,8 @@ public static class PlaylistEndpoint
var vid = new Video();
vid.MapFrom(video);
await vidRepo.AddAsync(vid, ct, false);
results.videos.Add(vid);
}
await repository.AddAsync(results, ct);
}
@ -40,24 +42,37 @@ public static class PlaylistEndpoint
{
results.MapFrom(playlistJson);
var remove = results.videos.Where(video => playlistJson.videos.All(x => x.playlistItemId != video.playlistItemId)).ToList();
var add = playlistJson.videos.Where(video => results.videos.All(x => x.playlistItemId != video.playlistItemId)).ToList();
var vids = new List<Video>();
foreach (var video in remove)
var notFound = new List<Video>();
foreach (var video in results.videos)
{
await vidRepo.DeleteAsync(video, ct, false);
var f = playlistJson.videos.FirstOrDefault(v => video.playlistItemId == v.playlistItemId);
if (f == null)
notFound.Add(video);
else
{
video.MapFrom(f);
await vidRepo.UpdateAsync(video, ct, false);
}
}
foreach (var video in add)
var newVids = (from video in playlistJson.videos
let f = results.videos.FirstOrDefault(v => v.playlistItemId == video.playlistItemId)
where f == null
select video).ToList();
foreach (var newVid in newVids)
{
var vid = new Video();
vid.MapFrom(video);
await vidRepo.AddAsync(vid, ct, false);
vids.Add(vid);
var vres = new Video();
vres.MapFrom(newVid);
await vidRepo.AddAsync(vres, ct, false);
results.videos.Add(vres);
}
results.videos.RemoveAll(x => remove.Contains(x));
results.videos.AddRange(vids);
foreach (var nfVid in notFound)
{
await vidRepo.DeleteAsync(nfVid, ct, false);
results.videos.Remove(nfVid);
}
await repository.UpdateAsync(results, ct);
}