Skip to content

V16/activecampaign #261

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

Open
wants to merge 2 commits into
base: v16/dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using Umbraco.Cms.Api.Common.OpenApi;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Api.Configuration;
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Configuration;

namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign
Expand Down Expand Up @@ -34,8 +36,9 @@ public void Compose(IUmbracoBuilder builder)
Description = $"Describes the {Constants.ManagementApi.ApiTitle} available for handling Active Campaign product(s) and configuration."
});

options.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["action"]}");
});
options.OperationFilter<BackOfficeSecurityRequirementsOperationFilter>();
})
.AddSingleton<IOperationIdHandler, ActiveCampaignOperationIdHandler>();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Common.OpenApi;

namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign.Api.Configuration
{
internal class ActiveCampaignOperationIdHandler : OperationIdHandler
{
public ActiveCampaignOperationIdHandler(IOptions<ApiVersioningOptions> apiVersioningOptions) : base(apiVersioningOptions)
{
}

protected override bool CanHandle(ApiDescription apiDescription, ControllerActionDescriptor controllerActionDescriptor)
=> controllerActionDescriptor.ControllerTypeInfo.Namespace?.StartsWith("Umbraco.Cms.Integrations.Crm.ActiveCampaign") is true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Umbraco.Cms.Api.Management.OpenApi;

namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign.Api.Configuration
{
internal class BackOfficeSecurityRequirementsOperationFilter : BackOfficeSecurityRequirementsOperationFilterBase
{
protected override string ApiName => Constants.ManagementApi.ApiName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using Umbraco.Cms.Api.Common.Attributes;
using Umbraco.Cms.Api.Common.Builders;
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Configuration;
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Models.Dtos;
using Umbraco.Cms.Web.Common.Authorization;
using Umbraco.Cms.Web.Common.Routing;

namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign.Api.Management.Controllers
{
[ApiController]
[BackOfficeRoute($"{Constants.ManagementApi.RootPath}/v{{version:apiVersion}}")]
//[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
[MapToApi(Constants.ManagementApi.ApiName)]
public class ActiveCampaignControllerBase : Controller
{
Expand Down Expand Up @@ -55,7 +55,9 @@ protected async Task<IActionResult> HandleResponseAsync<T>(HttpResponseMessage?
? Constants.Resources.ApiAccessFailed
: responseMessage;

return StatusCode((int)httpResponse.StatusCode, message);
return StatusCode((int)httpResponse.StatusCode, new ProblemDetailsBuilder()
.WithTitle(message)
.Build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Common.Builders;
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Configuration;
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Models.Dtos;

Expand All @@ -22,16 +23,25 @@ public GetFormByIdController(IOptions<ActiveCampaignSettings> options, IHttpClie
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetForm(string id)
{
var client = HttpClientFactory.CreateClient(Constants.FormsHttpClient);
try
{
var client = HttpClientFactory.CreateClient(Constants.FormsHttpClient);

var response = await client.SendAsync(
new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri($"{client.BaseAddress}{ApiPath}/{id}")
});
var response = await client.SendAsync(
new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri($"{client.BaseAddress}{ApiPath}/{id}")
});

return await HandleResponseAsync<FormResponseDto>(response);
return await HandleResponseAsync<FormResponseDto>(response);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, new ProblemDetailsBuilder()
.WithTitle(ex.Message)
.Build());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Common.Builders;
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Configuration;
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Models.Dtos;

Expand All @@ -20,23 +21,32 @@ public GetFormsByPageController(IOptions<ActiveCampaignSettings> options, IHttpC
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetForms([FromQuery]int? page = 1)
public async Task<IActionResult> GetForms([FromQuery] int? page = 1)
{
var client = HttpClientFactory.CreateClient(Constants.FormsHttpClient);
try
{
var client = HttpClientFactory.CreateClient(Constants.FormsHttpClient);

var requestUriString = page == 1
? $"{client.BaseAddress}{ApiPath}&limit={Constants.DefaultPageSize}"
: $"{client.BaseAddress}{ApiPath}&limit={Constants.DefaultPageSize}&offset={(page - 1) * Constants.DefaultPageSize}";
var requestUriString = page == 1
? $"{client.BaseAddress}{ApiPath}&limit={Constants.DefaultPageSize}"
: $"{client.BaseAddress}{ApiPath}&limit={Constants.DefaultPageSize}&offset={(page - 1) * Constants.DefaultPageSize}";

var requestMessage = new HttpRequestMessage
{
RequestUri = new Uri(requestUriString),
Method = HttpMethod.Get
};
var requestMessage = new HttpRequestMessage
{
RequestUri = new Uri(requestUriString),
Method = HttpMethod.Get
};

var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage);

return await HandleResponseAsync<FormCollectionResponseDto>(response);
return await HandleResponseAsync<FormCollectionResponseDto>(response);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, new ProblemDetailsBuilder()
.WithTitle(ex.Message)
.Build());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { ClientOptions } from './types.gen';
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';

/**
* The `createClientConfig()` function will be called on client initialization
* and the returned object will become the client's initial configuration.
*
* You may want to initialize your client this way instead of calling
* `setConfig()`. This is useful for example if you're using Next.js
* to ensure your client always has the correct values.
*/
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;

export const client = createClient(createConfig<ClientOptions>({
baseUrl: 'http://localhost:30450',
throwOnError: true
}));

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading