Skip to content

Commit 1b5f8ea

Browse files
committed
merge two to one, fix up client build
1 parent 6322b4e commit 1b5f8ea

File tree

88 files changed

+5833
-19863
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+5833
-19863
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Umbraco.Cms.Api.Management.OpenApi;
2+
3+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Configuration;
4+
5+
public class BackOfficeSecurityRequirementsOperationFilter : BackOfficeSecurityRequirementsOperationFilterBase
6+
{
7+
protected override string ApiName => Constants.ManagementApi.ApiName;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Options;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models.Dtos;
14+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
15+
16+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
17+
{
18+
[ApiVersion("1.0")]
19+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
20+
public class CheckConfigurationController : ShopifyControllerBase
21+
{
22+
public CheckConfigurationController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
23+
{
24+
}
25+
26+
[HttpGet("check-configuration")]
27+
[ProducesResponseType(typeof(EditorSettings), StatusCodes.Status200OK)]
28+
public ActionResult CheckConfiguration()
29+
{
30+
var setting = ShopifyService.GetApiConfiguration();
31+
return Ok(setting);
32+
}
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Options;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
16+
{
17+
[ApiVersion("1.0")]
18+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
19+
public class GetAccessTokenController : ShopifyControllerBase
20+
{
21+
public GetAccessTokenController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
22+
{
23+
}
24+
25+
[HttpPost("get-access-token")]
26+
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
27+
public async Task<IActionResult> GetAccessToken([FromBody]OAuthRequestDto authRequestDto)
28+
{
29+
var setting = await ShopifyAuthorizationService.GetAccessTokenAsync(authRequestDto.Code);
30+
return Ok(setting);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.Extensions.Options;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models.Dtos;
14+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
15+
16+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
17+
{
18+
[ApiVersion("1.0")]
19+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
20+
public class GetAuthorizationUrlController : ShopifyControllerBase
21+
{
22+
public GetAuthorizationUrlController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
23+
{
24+
}
25+
26+
[HttpGet("get-authorization-url")]
27+
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
28+
public ActionResult GetAuthorizationUrl()
29+
{
30+
var authUrl = ShopifyAuthorizationService.GetAuthorizationUrl();
31+
return Ok(authUrl);
32+
}
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Options;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
16+
{
17+
[ApiVersion("1.0")]
18+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
19+
public class GetListByIdsController : ShopifyControllerBase
20+
{
21+
public GetListByIdsController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
22+
{
23+
}
24+
25+
[HttpGet("get-list-by-ids")]
26+
[ProducesResponseType(typeof(ResponseDto<ProductsListDto>), StatusCodes.Status200OK)]
27+
public async Task<IActionResult> GetListByIds([FromBody] RequestDto dto)
28+
{
29+
var result = await ShopifyService.GetProductsByIds(dto.Ids.Select(p => (long.Parse(p))).ToArray());
30+
return Ok(result);
31+
}
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Options;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
16+
{
17+
[ApiVersion("1.0")]
18+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
19+
public class GetListController : ShopifyControllerBase
20+
{
21+
protected GetListController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
22+
{
23+
}
24+
25+
[HttpGet("get-list")]
26+
[ProducesResponseType(typeof(ResponseDto<ProductsListDto>), StatusCodes.Status200OK)]
27+
public async Task<IActionResult> GetList(string pageInfo)
28+
{
29+
var result = await ShopifyService.GetResults(pageInfo);
30+
return Ok(result);
31+
}
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Options;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
16+
{
17+
[ApiVersion("1.0")]
18+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
19+
public class GetTotalPagesController : ShopifyControllerBase
20+
{
21+
public GetTotalPagesController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
22+
{
23+
}
24+
25+
[HttpGet("total-pages")]
26+
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
27+
public async Task<IActionResult> GetTotalPages()
28+
{
29+
var productsCount = await ShopifyService.GetCount();
30+
return Ok(productsCount / Constants.DEFAULT_PAGE_SIZE + 1);
31+
}
32+
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Options;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
16+
{
17+
[ApiVersion("1.0")]
18+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
19+
public class RevokeAccessTokenController : ShopifyControllerBase
20+
{
21+
public RevokeAccessTokenController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
22+
{
23+
}
24+
25+
[HttpPost("revoke-access-token")]
26+
[ProducesResponseType(StatusCodes.Status200OK)]
27+
public ActionResult RevokeAccessToken()
28+
{
29+
ShopifyService.RevokeAccessToken();
30+
return Ok();
31+
}
32+
}
33+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Options;
4+
using System.Collections.Generic;
5+
using System.Net.Http.Headers;
6+
using System.Net.Http;
7+
using System;
8+
using Umbraco.Cms.Api.Common.Attributes;
9+
using Umbraco.Cms.Web.Common.Authorization;
10+
using Umbraco.Cms.Web.Common.Routing;
11+
using System.Linq;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
14+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models;
15+
16+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
17+
{
18+
[ApiController]
19+
[BackOfficeRoute($"{Constants.ManagementApi.RootPath}/v{{version:apiVersion}}")]
20+
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
21+
[MapToApi(Constants.ManagementApi.ApiName)]
22+
public abstract class ShopifyControllerBase : Controller
23+
{
24+
protected const string ShopifyApiEndpoint = "https://admin.shopify.com";
25+
protected ShopifySettings ShopifySettings;
26+
protected IShopifyService ShopifyService;
27+
protected IShopifyAuthorizationService ShopifyAuthorizationService;
28+
29+
protected ShopifyControllerBase(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService)
30+
{
31+
ShopifySettings = shopifySettings.Value;
32+
ShopifyService = shopifyService;
33+
ShopifyAuthorizationService = shopifyAuthorizationService;
34+
}
35+
36+
protected HttpRequestMessage CreateRequest(string accessToken)
37+
{
38+
var requestMessage = new HttpRequestMessage
39+
{
40+
Method = HttpMethod.Get,
41+
RequestUri = new Uri(ShopifyApiEndpoint)
42+
};
43+
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
44+
return requestMessage;
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Options;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
16+
{
17+
[ApiVersion("1.0")]
18+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
19+
public class ValidateAccessTokenController : ShopifyControllerBase
20+
{
21+
public ValidateAccessTokenController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
22+
{
23+
}
24+
25+
[HttpGet("validate-access-token")]
26+
[ProducesResponseType(typeof(ResponseDto<ProductsListDto>), StatusCodes.Status200OK)]
27+
public async Task<IActionResult> ValidateAccessToken()
28+
{
29+
var accessToken = await ShopifyService.ValidateAccessToken();
30+
return Ok(accessToken);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)