Skip to content

Commit c111277

Browse files
committed
42083-V14-Integrations-Shopify
- Remove secret - Update project and create new management API
1 parent 211a740 commit c111277

14 files changed

+283
-25
lines changed
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.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.New.Api.Management.Controllers
16+
{
17+
[ApiVersion("1.0")]
18+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
19+
public class CheckConfigurationController : ShopifyControllerBase
20+
{
21+
public CheckConfigurationController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
22+
{
23+
}
24+
25+
[HttpGet("check-configuration")]
26+
[ProducesResponseType(StatusCodes.Status200OK)]
27+
public ActionResult CheckConfiguration()
28+
{
29+
var setting = ShopifyService.GetApiConfiguration();
30+
return Ok(setting);
31+
}
32+
}
33+
}
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.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.New.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+
}

src/Umbraco.Cms.Integrations.Commerce.Shopify.Core.New/Api/Management/Controllers/GetAllOAuthController.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.
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.Configuration;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
14+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
15+
16+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.New.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(StatusCodes.Status200OK)]
28+
public ActionResult GetAuthorizationUrl()
29+
{
30+
var authUrl = ShopifyAuthorizationService.GetAuthorizationUrl();
31+
return Ok(authUrl);
32+
}
33+
}
34+
}
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.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.New.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+
[HttpPost("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.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.New.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+
}
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.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.New.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+
}

src/Umbraco.Cms.Integrations.Commerce.Shopify.Core.New/Api/Management/Controllers/GetAllController.cs renamed to src/Umbraco.Cms.Integrations.Commerce.Shopify.Core.New/Api/Management/Controllers/RevokeAccessTokenController.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010
using Umbraco.Cms.Integrations.Commerce.Shopify.Configuration;
1111
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
1212
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
1314

1415
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.New.Api.Management.Controllers
1516
{
1617
[ApiVersion("1.0")]
1718
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
18-
public class GetAllController : ShopifyControllerBase
19+
public class RevokeAccessTokenController : ShopifyControllerBase
1920
{
20-
protected GetAllController(IOptions<ShopifySettings> shopifySettings) : base(shopifySettings)
21+
public RevokeAccessTokenController(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService) : base(shopifySettings, shopifyService, shopifyAuthorizationService)
2122
{
2223
}
2324

24-
[HttpGet]
25-
[ProducesResponseType(typeof(ProductDto), StatusCodes.Status200OK)]
26-
public async Task GetAll()
25+
[HttpPost("revoke-access-token")]
26+
[ProducesResponseType(StatusCodes.Status200OK)]
27+
public ActionResult RevokeAccessToken()
2728
{
28-
29+
ShopifyService.RevokeAccessToken();
30+
return Ok();
2931
}
3032
}
3133
}

src/Umbraco.Cms.Integrations.Commerce.Shopify.Core.New/Api/Management/Controllers/ShopifyControllerBase.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using Umbraco.Cms.Web.Common.Routing;
1111
using System.Linq;
1212
using Umbraco.Cms.Integrations.Commerce.Shopify.Configuration;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
14+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models;
1315

1416
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers
1517
{
@@ -21,10 +23,14 @@ public abstract class ShopifyControllerBase : Controller
2123
{
2224
protected const string ShopifyApiEndpoint = "https://admin.shopify.com";
2325
protected ShopifySettings ShopifySettings;
26+
protected IShopifyService ShopifyService;
27+
protected IShopifyAuthorizationService ShopifyAuthorizationService;
2428

25-
protected ShopifyControllerBase(IOptions<ShopifySettings> shopifySettings)
29+
protected ShopifyControllerBase(IOptions<ShopifySettings> shopifySettings, IShopifyService shopifyService, IShopifyAuthorizationService shopifyAuthorizationService)
2630
{
2731
ShopifySettings = shopifySettings.Value;
32+
ShopifyService = shopifyService;
33+
ShopifyAuthorizationService = shopifyAuthorizationService;
2834
}
2935

3036
protected HttpRequestMessage CreateRequest(string accessToken)
@@ -37,5 +43,15 @@ protected HttpRequestMessage CreateRequest(string accessToken)
3743
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
3844
return requestMessage;
3945
}
46+
47+
protected HttpResponseMessage OAuth(string code)
48+
{
49+
var response = new HttpResponseMessage();
50+
response.Content = new StringContent(string.IsNullOrEmpty(code)
51+
? JavascriptResponse.Fail("Authorization process failed.")
52+
: JavascriptResponse.Ok(code));
53+
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
54+
return response;
55+
}
4056
}
4157
}
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.Configuration;
11+
using Umbraco.Cms.Integrations.Commerce.Shopify.Core.Api.Management.Controllers;
12+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
13+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
14+
15+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Core.New.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)