Started the Split
Split Json data models coming from REST Api, from the Database models storing them in a SQLite database. Work to re-engineer endpoints to use Database objects, and copy/update data from the json objects. More work is needed.
This commit is contained in:
parent
157d46ee2e
commit
4985dc4179
36 changed files with 684 additions and 323 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using FreeTubeSync.Model;
|
||||
using FreeTubeSync.SpecialResponses;
|
||||
using FreeTubeSync.Database;
|
||||
using FreeTubeSync.Model.Database;
|
||||
using FreeTubeSync.Model.Json;
|
||||
|
||||
namespace FreeTubeSync.EndPoints;
|
||||
|
||||
|
|
@ -12,18 +13,23 @@ public static class SettingEndpoint
|
|||
group.MapGet("/", async (IRepository<Setting> repository, CancellationToken ct) =>
|
||||
{
|
||||
var settings = await repository.GetAllAsync(ct);
|
||||
var response = settings.MapToResponse();
|
||||
return Results.Ok(response);
|
||||
var jsonSettings = new List<SettingJson>();
|
||||
settings.MapTo(jsonSettings);
|
||||
return Results.Ok(jsonSettings);
|
||||
});
|
||||
|
||||
group.MapPost("/", async (IRepository<Setting> repository, CancellationToken ct, Setting setting) =>
|
||||
group.MapPost("/", async (IRepository<Setting> repository, CancellationToken ct, SettingJson settingJson) =>
|
||||
{
|
||||
var res = await repository.GetByIdAsync(setting._id, ct);
|
||||
var res = await repository.GetByIdAsync(settingJson._id, ct);
|
||||
if (res == null)
|
||||
await repository.AddAsync(setting, ct);
|
||||
{
|
||||
res = new Setting();
|
||||
res.MapFrom(settingJson);
|
||||
await repository.AddAsync(res, ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Update(setting);
|
||||
res.MapFrom(settingJson);
|
||||
await repository.UpdateAsync(res, ct);
|
||||
}
|
||||
return Results.Ok();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue