2025-07-19 04:02:09 -05:00
|
|
|
using FreeTubeSync.Model;
|
|
|
|
|
|
|
|
|
|
namespace FreeTubeSync.EndPoints;
|
|
|
|
|
|
|
|
|
|
public static class PlaylistEndpoint
|
|
|
|
|
{
|
|
|
|
|
public static void MapPlaylistEndpoints(this WebApplication app)
|
|
|
|
|
{
|
|
|
|
|
var group = app.MapGroup("playlists");
|
|
|
|
|
|
|
|
|
|
group.MapGet("/", async (IRepository<Playlist> repository, CancellationToken ct) =>
|
|
|
|
|
{
|
|
|
|
|
var results = await repository.GetAllAsync(ct);
|
|
|
|
|
return Results.Ok(results);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group.MapPost("/", async (IRepository<Playlist> repository, CancellationToken ct, Playlist playlist) =>
|
|
|
|
|
{
|
|
|
|
|
var results = await repository.GetByIdAsync(playlist._id, ct);
|
|
|
|
|
if (results == null)
|
|
|
|
|
await repository.AddAsync(playlist, ct);
|
|
|
|
|
else
|
2025-07-21 17:10:42 -05:00
|
|
|
{
|
|
|
|
|
results.Update(playlist);
|
|
|
|
|
await repository.UpdateAsync(results, ct);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 04:02:09 -05:00
|
|
|
return Results.Ok();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group.MapDelete("/{id}", async (IRepository<Playlist> repository, CancellationToken ct, string id) =>
|
|
|
|
|
{
|
|
|
|
|
var result = await repository.GetByIdAsync(id, ct);
|
|
|
|
|
if (result == null) return Results.NotFound();
|
|
|
|
|
await repository.DeleteAsync(result, ct);
|
|
|
|
|
return Results.Ok();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|