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
37
FreeTubeSync/EndPoints/SettingEndpoint.cs
Normal file
37
FreeTubeSync/EndPoints/SettingEndpoint.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using FreeTubeSync.Model;
|
||||
using FreeTubeSync.SpecialResponses;
|
||||
|
||||
namespace FreeTubeSync.EndPoints;
|
||||
|
||||
public static class SettingEndpoint
|
||||
{
|
||||
public static void MapSettingEndpoints(this WebApplication app)
|
||||
{
|
||||
var group = app.MapGroup("settings");
|
||||
|
||||
group.MapGet("/", async (IRepository<Setting> repository, CancellationToken ct) =>
|
||||
{
|
||||
var settings = await repository.GetAllAsync(ct);
|
||||
var response = settings.MapToResponse();
|
||||
return Results.Ok(response);
|
||||
});
|
||||
|
||||
group.MapPost("/", async (IRepository<Setting> repository, CancellationToken ct, Setting setting) =>
|
||||
{
|
||||
var res = await repository.GetByIdAsync(setting._id, ct);
|
||||
if (res == null)
|
||||
await repository.AddAsync(setting, ct);
|
||||
else
|
||||
await repository.UpdateAsync(setting, ct);
|
||||
return Results.Ok();
|
||||
});
|
||||
|
||||
group.MapDelete("/{id}", async (IRepository<Setting> 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