From d8f87176c1f95cc850f8de79db1e6669c93d448f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20M=C3=A1t=C3=A9?= Date: Tue, 16 Jul 2024 22:46:30 +0200 Subject: [PATCH] Extending the Tester app with new API call examples --- Lombiq.OrchardCoreApiClient.Tester/Program.cs | 32 ++++++++++++++++--- ...ardCoreApiClient.Tester.OpenId.recipe.json | 3 ++ Readme.md | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Lombiq.OrchardCoreApiClient.Tester/Program.cs b/Lombiq.OrchardCoreApiClient.Tester/Program.cs index eaad95a..0707c1b 100644 --- a/Lombiq.OrchardCoreApiClient.Tester/Program.cs +++ b/Lombiq.OrchardCoreApiClient.Tester/Program.cs @@ -1,7 +1,9 @@ using Lombiq.OrchardCoreApiClient.Models; +using OrchardCore.ContentManagement; using System; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Text.Json; using System.Threading.Tasks; namespace Lombiq.OrchardCoreApiClient.Tester; @@ -18,18 +20,20 @@ public static class Program public static async Task Main(string[] arguments) { var port = int.TryParse(arguments.FirstOrDefault(), out var customPort) ? customPort : 44335; - using var apiClient = new ApiClient(new ApiClientSettings + var apiClientSettings = new ApiClientSettings { ClientId = ClientId, ClientSecret = ClientSecret, DefaultTenantUri = new Uri("https://localhost:" + port.ToTechnicalString()), - }); + }; + + using var tenantsApiClient = new TenantsApiClient(apiClientSettings); // A suffix is used to avoid name clashes on an existing site, as this test doesn't delete tenants. var suffix = DateTime.Now.Ticks.ToTechnicalString(); var name = "ApiClientTenant" + suffix; - await apiClient.CreateAndSetupTenantAsync( + await tenantsApiClient.CreateAndSetupTenantAsync( new TenantApiModel { Description = "Tenant created by API Client", @@ -69,8 +73,28 @@ await apiClient.CreateAndSetupTenantAsync( }; // Requires Orchard Core 1.6.0 or newer, on a 1.5.0 server this returns a 404 error. - await apiClient.OrchardCoreApi.EditAsync(editModel); + await tenantsApiClient.OrchardCoreApi.EditAsync(editModel); Console.WriteLine("Editing the tenant succeeded."); + + using var contentsApiClient = new ContentsApiClient(apiClientSettings); + + var taxonomy = new ContentItem + { + ContentType = "Taxonomy", + DisplayText = "Taxonomy created by API Client", + }; + + var response = await contentsApiClient.OrchardCoreApi.CreateOrUpdateAsync(taxonomy); + var contentItemIdFromApi = JsonSerializer.Deserialize(response.Content).ContentItemId; + + Console.WriteLine("Creating the taxonomy succeeded."); + + taxonomy.ContentItemId = contentItemIdFromApi; + taxonomy.DisplayText = "Taxonomy edited by API Client"; + + await contentsApiClient.OrchardCoreApi.CreateOrUpdateAsync(taxonomy); + + Console.WriteLine("Editing the taxonomy succeeded."); } } diff --git a/Lombiq.OrchardCoreApiClient.Tester/Recipes/Lombiq.OrchardCoreApiClient.Tester.OpenId.recipe.json b/Lombiq.OrchardCoreApiClient.Tester/Recipes/Lombiq.OrchardCoreApiClient.Tester.OpenId.recipe.json index 3dc336b..966bcfe 100644 --- a/Lombiq.OrchardCoreApiClient.Tester/Recipes/Lombiq.OrchardCoreApiClient.Tester.OpenId.recipe.json +++ b/Lombiq.OrchardCoreApiClient.Tester/Recipes/Lombiq.OrchardCoreApiClient.Tester.OpenId.recipe.json @@ -12,10 +12,13 @@ { "name": "feature", "enable": [ + "OrchardCore.Contents", + "OrchardCore.ContentTypes", "OrchardCore.OpenId", "OrchardCore.OpenId.Management", "OrchardCore.OpenId.Server", "OrchardCore.OpenId.Validation", + "OrchardCore.Taxonomies", "OrchardCore.Tenants" ] }, diff --git a/Readme.md b/Readme.md index 011afd8..9dbd451 100644 --- a/Readme.md +++ b/Readme.md @@ -40,7 +40,7 @@ public interface IOrchardCoreApiExtended : IOrchardCoreApi ## Recipes -Lombiq OrchardCore API Client OpenId - Recipe for enabling the Tenants and OpenId features and setting it up for the console tester application. To use this recipe, enable the Deployment feature and import this as a deployment package. +Lombiq OrchardCore API Client OpenId - Recipe for enabling the Content Types, Tenants and OpenId features and setting it up for the console tester application. To use this recipe, enable the Deployment feature and import this as a deployment package. ## Contributing and support