Skip to content

Commit

Permalink
Added option to get all entries as read only.
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix-CodingClimber committed Mar 24, 2024
1 parent 113dada commit d37a92e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/DotNetElements.Web.Blazor/CrudService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public interface ICrudService<TKey, TModel, TDetails, TEditModel>
Task<Result<TModel>> CreateEntryAsync(TEditModel editModel);
Task<Result> DeleteEntryAsync(TModel model);
Task<Result<TModel>> GetEntryByIdAsync(TKey id);
Task<Result<IReadOnlyList<TModel>>> GetAllEntriesReadOnlyAsync();
Task<Result<List<TModel>>> GetAllEntriesAsync();
Task<Result<IReadOnlyList<ModelWithDetails<TModel, TDetails>>>> GetAllEntriesWithDetailsReadOnlyAsync();
Task<Result<List<ModelWithDetails<TModel, TDetails>>>> GetAllEntriesWithDetailsAsync();
Task<Result> GetEntryDetailsAsync(ModelWithDetails<TModel, TDetails> modelWithDetails);
Task<Result<TModel>> UpdateEntryAsync(TEditModel editModel);
Expand Down Expand Up @@ -121,6 +123,21 @@ public virtual async Task<Result> GetEntryDetailsAsync(ModelWithDetails<TModel,
return detailsResult;
}

public virtual async Task<Result<IReadOnlyList<TModel>>> GetAllEntriesReadOnlyAsync()
{
Result<IReadOnlyList<TModel>> result = await HttpClient.GetFromJsonWithResultAsync<IReadOnlyList<TModel>>(Options.GetAllEndpoint);

// todo add logging
// todo wrap Snackbar call in bool option NotifyUser
// todo add function OnDeleteSuccess
if (result.IsFail)
{
Snackbar.Add("Failed to fetch entries from server", Severity.Error);
}

return result;
}

public virtual async Task<Result<List<TModel>>> GetAllEntriesAsync()
{
Result<List<TModel>> result = await HttpClient.GetFromJsonWithResultAsync<List<TModel>>(Options.GetAllEndpoint);
Expand All @@ -136,6 +153,21 @@ public virtual async Task<Result<List<TModel>>> GetAllEntriesAsync()
return result;
}

public virtual async Task<Result<IReadOnlyList<ModelWithDetails<TModel, TDetails>>>> GetAllEntriesWithDetailsReadOnlyAsync()
{
Result<List<ModelWithDetails<TModel, TDetails>>> result = await HttpClient.GetModelWithDetailsListFromJsonAsync<TModel, TDetails>(Options.GetAllEndpoint);

// todo add logging
// todo wrap Snackbar call in bool option NotifyUser
// todo add function OnDeleteSuccess
if (result.IsFail)
{
Snackbar.Add("Failed to fetch entries from server", Severity.Error);
}

return Result.Ok(result.Value as IReadOnlyList<ModelWithDetails<TModel, TDetails>>);
}

public virtual async Task<Result<List<ModelWithDetails<TModel, TDetails>>>> GetAllEntriesWithDetailsAsync()
{
Result<List<ModelWithDetails<TModel, TDetails>>> result = await HttpClient.GetModelWithDetailsListFromJsonAsync<TModel, TDetails>(Options.GetAllEndpoint);
Expand Down

0 comments on commit d37a92e

Please sign in to comment.