35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
|
|
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
|
||
|
|
await repository.UpdateAsync(playlist, ct);
|
||
|
|
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();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|