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,4 +1,6 @@
|
|||
using FreeTubeSync.Model;
|
||||
using FreeTubeSync.Database;
|
||||
using FreeTubeSync.Model.Database;
|
||||
using FreeTubeSync.Model.Json;
|
||||
|
||||
namespace FreeTubeSync.EndPoints;
|
||||
|
||||
|
|
@ -11,17 +13,23 @@ public static class SearchHistoryEndpoint
|
|||
group.MapGet("/", async (IRepository<SearchHistory> repository, CancellationToken ct) =>
|
||||
{
|
||||
var result = await repository.GetAllAsync(ct);
|
||||
return Results.Ok(result);
|
||||
var jsonResults = new List<SearchHistoryJson>();
|
||||
result.MapTo(jsonResults);
|
||||
return Results.Ok(jsonResults);
|
||||
});
|
||||
|
||||
group.MapPost("/", async (IRepository<SearchHistory> repository, CancellationToken ct, SearchHistory history) =>
|
||||
group.MapPost("/", async (IRepository<SearchHistory> repository, CancellationToken ct, SearchHistoryJson historyJson) =>
|
||||
{
|
||||
var result = await repository.GetByIdAsync(history._id, ct);
|
||||
var result = await repository.GetByIdAsync(historyJson._id, ct);
|
||||
if (result == null)
|
||||
await repository.AddAsync(history, ct);
|
||||
{
|
||||
result = new SearchHistory();
|
||||
result.MapFrom(historyJson);
|
||||
await repository.AddAsync(result, ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Update(history);
|
||||
result.MapFrom(historyJson);
|
||||
await repository.UpdateAsync(result, ct);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue