using Oqtane.Models; using System.Threading.Tasks; using System.Net.Http; using System.Linq; using System.Collections.Generic; using Oqtane.Documentation; using Oqtane.Shared; namespace Oqtane.Services { /// /// Service to retrieve and store information. /// public interface IAliasService { /// /// Get all aliases in the system /// /// Task> GetAliasesAsync(); /// /// Get a single alias /// /// The ID, not to be confused with a ID /// Task GetAliasAsync(int aliasId); /// /// Save another in the DB. It must already contain all the information incl. it belongs to. /// /// An to add. /// Task AddAliasAsync(Alias alias); /// /// Update an in the DB. Make sure the object is correctly filled, as it must update an existing record. /// /// The to update. /// Task UpdateAliasAsync(Alias alias); /// /// Remove an from the DB. /// /// The Alias ID, not to be confused with a Site ID. /// Task DeleteAliasAsync(int aliasId); } /// [PrivateApi("Don't show in the documentation, as everything should use the Interface")] public class AliasService : ServiceBase, IAliasService { /// /// Constructor - should only be used by Dependency Injection /// public AliasService(HttpClient http, SiteState siteState) : base(http, siteState) { } private string ApiUrl => CreateApiUrl("Alias"); /// public async Task> GetAliasesAsync() { List aliases = await GetJsonAsync>(ApiUrl, Enumerable.Empty().ToList()); return aliases.OrderBy(item => item.Name).ToList(); } /// public async Task GetAliasAsync(int aliasId) { return await GetJsonAsync($"{ApiUrl}/{aliasId}"); } /// public async Task AddAliasAsync(Alias alias) { return await PostJsonAsync(ApiUrl, alias); } /// public async Task UpdateAliasAsync(Alias alias) { return await PutJsonAsync($"{ApiUrl}/{alias.AliasId}", alias); } /// public async Task DeleteAliasAsync(int aliasId) { await DeleteAsync($"{ApiUrl}/{aliasId}"); } } }