using Oqtane.Models; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Oqtane.Documentation; using Oqtane.Shared; using Oqtane.Modules.Controls; namespace Oqtane.Services { /// /// Service to retrieve and store modules () /// public interface IModuleService { /// /// Returns a list of modules for the given site /// /// /// Task> GetModulesAsync(int siteId); /// /// Returns a specific module /// /// /// Task GetModuleAsync(int moduleId); /// /// Adds a new module /// /// /// Task AddModuleAsync(Module module); /// /// Updates an existing module /// /// /// Task UpdateModuleAsync(Module module); /// /// Deletes a module /// /// /// Task DeleteModuleAsync(int moduleId); /// /// Imports a module /// /// /// module in JSON format /// Task ImportModuleAsync(int moduleId, int pageId, string content); /// /// Exports a given module /// /// /// /// module content in JSON format Task ExportModuleAsync(int moduleId, int pageId); /// /// Exports a given module /// /// /// /// /// /// file id Task ExportModuleAsync(int moduleId, int pageId, int folderId, string filename); } [PrivateApi("Don't show in the documentation, as everything should use the Interface")] public class ModuleService : ServiceBase, IModuleService { public ModuleService(HttpClient http, SiteState siteState) : base(http, siteState) { } private string Apiurl => CreateApiUrl("Module"); public async Task> GetModulesAsync(int siteId) { return await GetJsonAsync>($"{Apiurl}?siteid={siteId}"); } public async Task GetModuleAsync(int moduleId) { return await GetJsonAsync($"{Apiurl}/{moduleId}"); } public async Task AddModuleAsync(Module module) { return await PostJsonAsync(Apiurl, module); } public async Task UpdateModuleAsync(Module module) { return await PutJsonAsync($"{Apiurl}/{module.ModuleId}", module); } public async Task DeleteModuleAsync(int moduleId) { await DeleteAsync($"{Apiurl}/{moduleId.ToString()}"); } public async Task ImportModuleAsync(int moduleId, int pageId, string content) { return await PostJsonAsync($"{Apiurl}/import?moduleid={moduleId}&pageid={pageId}", content); } public async Task ExportModuleAsync(int moduleId, int pageId) { return await GetStringAsync($"{Apiurl}/export?moduleid={moduleId}&pageid={pageId}"); } public async Task ExportModuleAsync(int moduleId, int pageId, int folderId, string filename) { return await PostJsonAsync($"{Apiurl}/export?moduleid={moduleId}&pageid={pageId}&folderid={folderId}&filename={filename}", null); } } }