using Oqtane.Models;
using System.Threading.Tasks;
using System.Net.Http;
using System.Collections.Generic;
using Oqtane.Shared;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using Oqtane.Documentation;
namespace Oqtane.Services
{
///
/// Service to get / create / modify objects.
///
public interface IFolderService
{
///
/// Retrieve root folders of a
///
///
///
Task> GetFoldersAsync(int siteId);
///
/// Retrieve the information of one
///
///
///
Task GetFolderAsync(int folderId);
///
/// Create one Folder using a object.
///
///
///
Task AddFolderAsync(Folder folder);
///
/// Update the information about a
/// Use this to rename the folder etc.
///
///
///
Task UpdateFolderAsync(Folder folder);
///
/// Delete a
///
/// Reference to a
///
Task DeleteFolderAsync(int folderId);
///
/// Get a of a based on the path.
///
/// Reference to the
/// Path of the folder
/// TODO: todoc verify exactly from where the folder path must start
///
///
Task GetFolderAsync(int siteId, [NotNull] string folderPath);
}
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
public class FolderService : ServiceBase, IFolderService
{
public FolderService(HttpClient http, SiteState siteState) : base(http, siteState) { }
private string ApiUrl => CreateApiUrl("Folder");
public async Task> GetFoldersAsync(int siteId)
{
return await GetJsonAsync>($"{ApiUrl}?siteid={siteId}");
}
public async Task GetFolderAsync(int folderId)
{
return await GetJsonAsync($"{ApiUrl}/{folderId}");
}
public async Task GetFolderAsync(int siteId, [NotNull] string folderPath)
{
var path = WebUtility.UrlEncode(folderPath);
return await GetJsonAsync($"{ApiUrl}/path/{siteId}/?path={path}");
}
public async Task AddFolderAsync(Folder folder)
{
return await PostJsonAsync(ApiUrl, folder);
}
public async Task UpdateFolderAsync(Folder folder)
{
return await PutJsonAsync($"{ApiUrl}/{folder.FolderId}", folder);
}
public async Task DeleteFolderAsync(int folderId)
{
await DeleteAsync($"{ApiUrl}/{folderId}");
}
}
}