using Oqtane.Models;
using System.Net.Http;
using System.Threading.Tasks;
using Oqtane.Documentation;
using Oqtane.Shared;
namespace Oqtane.Services
{
///
/// Service to store and retrieve a
///
public interface IPageModuleService
{
///
/// Returns a specific page module
///
///
///
Task GetPageModuleAsync(int pageModuleId);
///
/// Return a specific page module
///
///
///
///
Task GetPageModuleAsync(int pageId, int moduleId);
///
/// Creates a new page module
///
///
///
Task AddPageModuleAsync(PageModule pageModule);
///
/// Updates a existing page module
///
///
///
Task UpdatePageModuleAsync(PageModule pageModule);
///
/// Updates order of all page modules in the given pane
///
///
///
///
Task UpdatePageModuleOrderAsync(int pageId, string pane);
///
/// Deletes a page module
///
///
///
Task DeletePageModuleAsync(int pageModuleId);
}
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
public class PageModuleService : ServiceBase, IPageModuleService
{
public PageModuleService(HttpClient http, SiteState siteState) : base(http, siteState) { }
private string Apiurl => CreateApiUrl("PageModule");
public async Task GetPageModuleAsync(int pageModuleId)
{
return await GetJsonAsync($"{Apiurl}/{pageModuleId}");
}
public async Task GetPageModuleAsync(int pageId, int moduleId)
{
return await GetJsonAsync($"{Apiurl}/{pageId}/{moduleId}");
}
public async Task AddPageModuleAsync(PageModule pageModule)
{
return await PostJsonAsync(Apiurl, pageModule);
}
public async Task UpdatePageModuleAsync(PageModule pageModule)
{
return await PutJsonAsync($"{Apiurl}/{pageModule.PageModuleId}", pageModule);
}
public async Task UpdatePageModuleOrderAsync(int pageId, string pane)
{
await PutAsync($"{Apiurl}/?pageid={pageId}&pane={pane}");
}
public async Task DeletePageModuleAsync(int pageModuleId)
{
await DeleteAsync($"{Apiurl}/{pageModuleId}");
}
}
}