using Oqtane.Models; using System.Threading.Tasks; using System.Net.Http; using System.Collections.Generic; using Oqtane.Shared; using System; using Oqtane.Documentation; namespace Oqtane.Services { /// /// Service to store and retrieve entries /// public interface ISiteService { /// /// Returns a list of sites /// /// Task> GetSitesAsync(); /// /// Returns a specific site /// /// /// Task GetSiteAsync(int siteId); /// /// Creates a new site /// /// /// Task AddSiteAsync(Site site); /// /// Updates an existing site /// /// /// Task UpdateSiteAsync(Site site); /// /// Deletes a site /// /// /// Task DeleteSiteAsync(int siteId); /// /// Returns a list of modules /// /// /// /// Task> GetModulesAsync(int siteId, int pageId); [PrivateApi] [Obsolete("This method is deprecated.", false)] void SetAlias(Alias alias); } [PrivateApi("Don't show in the documentation, as everything should use the Interface")] public class SiteService : ServiceBase, ISiteService { public SiteService(HttpClient http, SiteState siteState) : base(http, siteState) { } private string Apiurl => CreateApiUrl("Site"); public async Task> GetSitesAsync() { return await GetJsonAsync>(Apiurl); } public async Task GetSiteAsync(int siteId) { return await GetJsonAsync($"{Apiurl}/{siteId}"); } public async Task AddSiteAsync(Site site) { return await PostJsonAsync(Apiurl, site); } public async Task UpdateSiteAsync(Site site) { return await PutJsonAsync($"{Apiurl}/{site.SiteId}", site); } public async Task DeleteSiteAsync(int siteId) { await DeleteAsync($"{Apiurl}/{siteId}"); } public async Task> GetModulesAsync(int siteId, int pageId) { return await GetJsonAsync>($"{Apiurl}/modules/{siteId}/{pageId}"); } [Obsolete("This method is deprecated.", false)] public void SetAlias(Alias alias) { base.Alias = alias; } } }