Compare commits
6 commits
977b40c403
...
157d46ee2e
| Author | SHA1 | Date | |
|---|---|---|---|
| 157d46ee2e | |||
| 21af6f4300 | |||
| 77c95a9525 | |||
| e1ad30da0c | |||
| b08c22e77b | |||
| 561ba4f34a |
10 changed files with 77 additions and 9 deletions
|
|
@ -20,7 +20,10 @@ public static class HistoryEndpoint
|
||||||
if (results == null)
|
if (results == null)
|
||||||
await repository.AddAsync(history, ct);
|
await repository.AddAsync(history, ct);
|
||||||
else
|
else
|
||||||
await repository.UpdateAsync(history, ct);
|
{
|
||||||
|
results.Update(history);
|
||||||
|
await repository.UpdateAsync(results, ct);
|
||||||
|
}
|
||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,11 @@ public static class PlaylistEndpoint
|
||||||
if (results == null)
|
if (results == null)
|
||||||
await repository.AddAsync(playlist, ct);
|
await repository.AddAsync(playlist, ct);
|
||||||
else
|
else
|
||||||
await repository.UpdateAsync(playlist, ct);
|
{
|
||||||
|
results.Update(playlist);
|
||||||
|
await repository.UpdateAsync(results, ct);
|
||||||
|
}
|
||||||
|
|
||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,11 @@ public static class ProfileEndpoint
|
||||||
if (res == null)
|
if (res == null)
|
||||||
await repository.AddAsync(profile, ct);
|
await repository.AddAsync(profile, ct);
|
||||||
else
|
else
|
||||||
await repository.UpdateAsync(profile, ct);
|
{
|
||||||
|
res.Update(profile);
|
||||||
|
await repository.UpdateAsync(res, ct);
|
||||||
|
}
|
||||||
|
|
||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,14 @@ public static class SearchHistoryEndpoint
|
||||||
group.MapPost("/", async (IRepository<SearchHistory> repository, CancellationToken ct, SearchHistory history) =>
|
group.MapPost("/", async (IRepository<SearchHistory> repository, CancellationToken ct, SearchHistory history) =>
|
||||||
{
|
{
|
||||||
var result = await repository.GetByIdAsync(history._id, ct);
|
var result = await repository.GetByIdAsync(history._id, ct);
|
||||||
if (result != null)
|
if (result == null)
|
||||||
await repository.UpdateAsync(history, ct);
|
|
||||||
else
|
|
||||||
await repository.AddAsync(history, ct);
|
await repository.AddAsync(history, ct);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.Update(history);
|
||||||
|
await repository.UpdateAsync(result, ct);
|
||||||
|
}
|
||||||
|
|
||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,10 @@ public static class SettingEndpoint
|
||||||
if (res == null)
|
if (res == null)
|
||||||
await repository.AddAsync(setting, ct);
|
await repository.AddAsync(setting, ct);
|
||||||
else
|
else
|
||||||
await repository.UpdateAsync(setting, ct);
|
{
|
||||||
|
res.Update(setting);
|
||||||
|
await repository.UpdateAsync(res, ct);
|
||||||
|
}
|
||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query.Internal;
|
||||||
|
|
||||||
namespace FreeTubeSync.Model;
|
namespace FreeTubeSync.Model;
|
||||||
|
|
||||||
|
|
@ -18,7 +19,20 @@ public class Playlist
|
||||||
{
|
{
|
||||||
if (other.playlistName != playlistName) playlistName = other.playlistName;
|
if (other.playlistName != playlistName) playlistName = other.playlistName;
|
||||||
if (other.@protected != @protected) @protected = other.@protected;
|
if (other.@protected != @protected) @protected = other.@protected;
|
||||||
if (other.videos.Count != videos.Count) videos = other.videos;
|
var remove = new List<Video>();
|
||||||
|
foreach (var vid in videos)
|
||||||
|
{
|
||||||
|
if (other.videos.Any(x => x.playlistItemId == vid.playlistItemId)) continue;
|
||||||
|
remove.Add(vid);
|
||||||
|
}
|
||||||
|
videos.RemoveAll(x => remove.Contains(x));
|
||||||
|
remove.Clear();
|
||||||
|
foreach (var vid in other.videos)
|
||||||
|
{
|
||||||
|
if (videos.Any(x => x.playlistItemId == vid.playlistItemId)) continue;
|
||||||
|
remove.Add(vid);
|
||||||
|
}
|
||||||
|
videos.AddRange(remove);
|
||||||
if (other.createdAt != createdAt) createdAt = other.createdAt;
|
if (other.createdAt != createdAt) createdAt = other.createdAt;
|
||||||
if (other.lastUpdatedAt != lastUpdatedAt) lastUpdatedAt = other.lastUpdatedAt;
|
if (other.lastUpdatedAt != lastUpdatedAt) lastUpdatedAt = other.lastUpdatedAt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,19 @@ public class Profile
|
||||||
if (other.name != name) name = other.name;
|
if (other.name != name) name = other.name;
|
||||||
if (other.bgColor != bgColor) bgColor = other.bgColor;
|
if (other.bgColor != bgColor) bgColor = other.bgColor;
|
||||||
if (other.textColor != textColor) textColor = other.textColor;
|
if (other.textColor != textColor) textColor = other.textColor;
|
||||||
if (other.subscriptions.Count != subscriptions.Count) subscriptions = other.subscriptions;
|
var remove = new List<Subscription>();
|
||||||
|
foreach (var sub in subscriptions)
|
||||||
|
{
|
||||||
|
if (other.subscriptions.Any(x => x.id == sub.id)) continue;
|
||||||
|
remove.Add(sub);
|
||||||
|
}
|
||||||
|
subscriptions.RemoveAll(x => remove.Contains(x));
|
||||||
|
remove.Clear();
|
||||||
|
foreach (var sub in other.subscriptions)
|
||||||
|
{
|
||||||
|
if (subscriptions.Any(x => x.id == sub.id)) continue;
|
||||||
|
remove.Add(sub);
|
||||||
|
}
|
||||||
|
subscriptions.AddRange(remove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,4 +22,9 @@ public class Setting
|
||||||
#pragma warning restore CS8603
|
#pragma warning restore CS8603
|
||||||
set => ValueJson = JsonSerializer.Serialize(value);
|
set => ValueJson = JsonSerializer.Serialize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update(Setting other)
|
||||||
|
{
|
||||||
|
Value = other.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,4 +10,10 @@ public class Subscription
|
||||||
public required string id { get; set; }
|
public required string id { get; set; }
|
||||||
public required string name { get; set; }
|
public required string name { get; set; }
|
||||||
public string? thumbnail { get; set; }
|
public string? thumbnail { get; set; }
|
||||||
|
|
||||||
|
public void Update(Subscription other)
|
||||||
|
{
|
||||||
|
name = other.name;
|
||||||
|
thumbnail = other.thumbnail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,4 +16,16 @@ public class Video
|
||||||
public long timeAdded { get; set; }
|
public long timeAdded { get; set; }
|
||||||
[Key] public string playlistItemId { get; set; } = string.Empty;
|
[Key] public string playlistItemId { get; set; } = string.Empty;
|
||||||
public string type { get; set; } = string.Empty;
|
public string type { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public void Update(Video other)
|
||||||
|
{
|
||||||
|
videoId = other.videoId;
|
||||||
|
title = other.title;
|
||||||
|
author = other.author;
|
||||||
|
authorId = other.authorId;
|
||||||
|
lengthSeconds = other.lengthSeconds;
|
||||||
|
pubished = other.pubished;
|
||||||
|
timeAdded = other.timeAdded;
|
||||||
|
type = other.type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue