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,15 +13,13 @@ namespace Oqtane.Services
{
public class FileService : ServiceBase, IFileService
{
private readonly HttpClient _http;
private readonly SiteState _siteState;
private readonly NavigationManager _navigationManager;
private readonly IJSRuntime _jsRuntime;
public FileService(HttpClient http, SiteState siteState, NavigationManager navigationManager,
IJSRuntime jsRuntime)
IJSRuntime jsRuntime) : base(http)
{
_http = http;
_siteState = siteState;
_navigationManager = navigationManager;
_jsRuntime = jsRuntime;
@ -39,7 +37,7 @@ namespace Oqtane.Services
public async Task<List<File>> GetFilesAsync(string folder)
{
return await _http.GetJsonAsync<List<File>>($"{Apiurl}?folder={folder}");
return await GetJsonAsync<List<File>>($"{Apiurl}?folder={folder}");
}
public async Task<List<File>> GetFilesAsync(int siteId, string folderPath)
@ -51,39 +49,32 @@ namespace Oqtane.Services
var path = WebUtility.UrlEncode(folderPath);
return await _http.GetJsonAsync<List<File>>($"{Apiurl}/{siteId}/{path}");
return await GetJsonAsync<List<File>>($"{Apiurl}/{siteId}/{path}");
}
public async Task<File> GetFileAsync(int fileId)
{
try
{
return await _http.GetJsonAsync<File>($"{Apiurl}/{fileId.ToString()}");
}
catch
{
return null;
}
return await GetJsonAsync<File>($"{Apiurl}/{fileId.ToString()}");
}
public async Task<File> AddFileAsync(File file)
{
return await _http.PostJsonAsync<File>(Apiurl, file);
return await PostJsonAsync<File>(Apiurl, file);
}
public async Task<File> UpdateFileAsync(File file)
{
return await _http.PutJsonAsync<File>($"{Apiurl}/{file.FileId.ToString()}", file);
return await PutJsonAsync<File>($"{Apiurl}/{file.FileId.ToString()}", file);
}
public async Task DeleteFileAsync(int fileId)
{
await _http.DeleteAsync($"{Apiurl}/{fileId.ToString()}");
await DeleteAsync($"{Apiurl}/{fileId.ToString()}");
}
public async Task<File> UploadFileAsync(string url, int folderId)
{
return await _http.GetJsonAsync<File>($"{Apiurl}/upload?url={WebUtility.UrlEncode(url)}&folderid={folderId.ToString()}");
return await GetJsonAsync<File>($"{Apiurl}/upload?url={WebUtility.UrlEncode(url)}&folderid={folderId.ToString()}");
}
public async Task<string> UploadFilesAsync(int folderId, string[] files, string id)
@ -133,7 +124,7 @@ namespace Oqtane.Services
public async Task<byte[]> DownloadFileAsync(int fileId)
{
return await _http.GetByteArrayAsync($"{Apiurl}/download/{fileId.ToString()}");
return await GetByteArrayAsync($"{Apiurl}/download/{fileId.ToString()}");
}
}
}