Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-646: Remove CustomEditAsync #42

Merged
merged 8 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Lombiq.OrchardCoreApiClient/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@

namespace Lombiq.OrchardCoreApiClient;

public class ApiClient : IDisposable
public class ApiClient : ApiClient<IOrchardCoreApi>
{
private readonly Lazy<IOrchardCoreApi> _lazyOrchardCoreApi;
public ApiClient(ApiClientSettings apiClientSettings)
: base(apiClientSettings)
{
}
}

public class ApiClient<TApi> : IDisposable
where TApi : IOrchardCoreApi
{
private readonly Lazy<TApi> _lazyOrchardCoreApi;

private HttpClient _httpClient;

public IOrchardCoreApi OrchardCoreApi => _lazyOrchardCoreApi.Value;
public TApi OrchardCoreApi => _lazyOrchardCoreApi.Value;

public ApiClient(ApiClientSettings apiClientSettings) =>
_lazyOrchardCoreApi = new(() =>
{
_httpClient = ConfigurableCertificateValidatingHttpClientHandler.CreateClient(apiClientSettings);

// We use Newtonsoft Json.NET because Orchard Core uses it too, so the models will behave the same.
return RefitHelper.WithNewtonsoftJson<IOrchardCoreApi>(_httpClient);
return RefitHelper.WithNewtonsoftJson<TApi>(_httpClient);
});

public async Task CreateAndSetupTenantAsync(
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
13 changes: 0 additions & 13 deletions Lombiq.OrchardCoreApiClient/Interfaces/IOrchardCoreApi.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lombiq.OrchardCoreApiClient.Models;
using Refit;
using System;
using System.Threading.Tasks;
using static Lombiq.OrchardCoreApiClient.Constants.CommonHeaders;

Expand Down Expand Up @@ -42,18 +41,6 @@ public interface IOrchardCoreApi
[Headers(AuthorizationBearer)]
Task<string> EditAsync([Body(buffered: true)] TenantApiModel editTenantParameters);

/// <summary>
/// Edit a previously created tenant in Orchard Core with additional settings inside
/// <see cref="TenantApiModel.CustomSettings"/>. This endpoint is not implemented, implement on your own.
/// </summary>
/// <param name="editTenantParameters">The <see cref="TenantApiModel.CustomSettings"/> property in the
/// <see cref="TenantApiModel"/> is the additional property that is not processed in <see cref="EditAsync"/>.</param>
/// <returns>The response of the custom tenant edit.</returns>
[Post("/api/tenants/custom-edit")]
[Headers(AuthorizationBearer)]
[Obsolete("This shouldn't be here and will be soon removed, see https://github.com/Lombiq/Orchard-Core-API-Client/issues/30.")]
Task<string> CustomEditAsync([Body(buffered: true)] TenantApiModel editTenantParameters);

/// <summary>
/// Remove a previously created tenant in Orchard Core.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion Lombiq.OrchardCoreApiClient/Models/TenantApiModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ public class TenantApiModel
public string RecipeName { get; set; }
public IEnumerable<string> FeatureProfiles { get; set; }
public string Category { get; set; }
public IDictionary<string, string> CustomSettings { get; } = new Dictionary<string, string>();
}
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ If you want to set up the OpenId features without the recipe, you need to enable

For testing, run your Orchard Core app first, then `Lombiq.OrchardCoreApiClient.Tester`. You may need to edit the [_Program.cs_](Lombiq.OrchardCoreApiClient.Tester/Program.cs) according to your OpenID Application's settings (`ClientId`, `ClientSecret`, and `DefaultTenantUri`) and then run the console application.

### Use your own API endpoints

You can add your own API endpoints by creating a new interface that's inherited from `IOrchardCoreApi` and add your own methods. For example, you can create a new interface called `IOrchardCoreApiExtended` and add a new method to it:
Piedone marked this conversation as resolved.
Show resolved Hide resolved

```csharp
public interface IOrchardCoreApiExtended : IOrchardCoreApi
{
[Post("/api/my-custom-endpoint")]
[Headers(AuthorizationBearer)]
Task<string> GetMyCustomEndpointAsync();
}
```

## 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.
Expand Down