Migration to using System.Net.Http.Json; part one - functional migration

This commit is contained in:
Pavel Vesely
2020-04-15 23:03:37 +02:00
parent fe2ad29b3b
commit 95e9bee4e2
29 changed files with 293 additions and 215 deletions

View File

@ -13,13 +13,11 @@ namespace Oqtane.Services
{
public class FolderService : ServiceBase, IFolderService
{
private readonly HttpClient _http;
private readonly SiteState _siteState;
private readonly NavigationManager _navigationManager;
public FolderService(HttpClient http, SiteState siteState, NavigationManager navigationManager)
public FolderService(HttpClient http, SiteState siteState, NavigationManager navigationManager):base(http)
{
_http = http;
_siteState = siteState;
_navigationManager = navigationManager;
}
@ -28,14 +26,14 @@ namespace Oqtane.Services
public async Task<List<Folder>> GetFoldersAsync(int siteId)
{
List<Folder> folders = await _http.GetJsonAsync<List<Folder>>($"{ApiUrl}?siteid={siteId.ToString()}");
List<Folder> folders = await GetJsonAsync<List<Folder>>($"{ApiUrl}?siteid={siteId.ToString()}");
folders = GetFoldersHierarchy(folders);
return folders;
}
public async Task<Folder> GetFolderAsync(int folderId)
{
return await _http.GetJsonAsync<Folder>($"{ApiUrl}/{folderId.ToString()}");
return await GetJsonAsync<Folder>($"{ApiUrl}/{folderId.ToString()}");
}
public async Task<Folder> GetFolderAsync(int siteId, [NotNull] string folderPath)
@ -47,17 +45,17 @@ namespace Oqtane.Services
var path = WebUtility.UrlEncode(folderPath);
return await _http.GetJsonAsync<Folder>($"{ApiUrl}/{siteId}/{path}");
return await GetJsonAsync<Folder>($"{ApiUrl}/{siteId}/{path}");
}
public async Task<Folder> AddFolderAsync(Folder folder)
{
return await _http.PostJsonAsync<Folder>(ApiUrl, folder);
return await PostJsonAsync<Folder>(ApiUrl, folder);
}
public async Task<Folder> UpdateFolderAsync(Folder folder)
{
return await _http.PutJsonAsync<Folder>($"{ApiUrl}/{folder.FolderId.ToString()}", folder);
return await PutJsonAsync<Folder>($"{ApiUrl}/{folder.FolderId.ToString()}", folder);
}
public async Task UpdateFolderOrderAsync(int siteId, int folderId, int? parentId)
@ -65,12 +63,12 @@ namespace Oqtane.Services
var parent = parentId == null
? string.Empty
: parentId.ToString();
await _http.PutJsonAsync($"{ApiUrl}/?siteid={siteId.ToString()}&folderid={folderId.ToString()}&parentid={parent}", null);
await PutAsync($"{ApiUrl}/?siteid={siteId.ToString()}&folderid={folderId.ToString()}&parentid={parent}");
}
public async Task DeleteFolderAsync(int folderId)
{
await _http.DeleteAsync($"{ApiUrl}/{folderId.ToString()}");
await DeleteAsync($"{ApiUrl}/{folderId.ToString()}");
}
private static List<Folder> GetFoldersHierarchy(List<Folder> folders)