Initial Commit
Inital Commit of Code base, nothing tested.
This commit is contained in:
commit
0144221712
31 changed files with 1304 additions and 0 deletions
35
FreeTubeSync/EndPoints/PlaylistEndpoint.cs
Normal file
35
FreeTubeSync/EndPoints/PlaylistEndpoint.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue