Skip to content

Commit 4629123

Browse files
committed
Update polling api to return content nodes with properties for a specific content type.
1 parent f9602cc commit 4629123

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

src/Umbraco.Cms.Integrations.Automation.Zapier/Components/NewContentPublishedComponent.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#if NETFRAMEWORK
22
using System;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Threading.Tasks;
4+
65
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
76
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
87
using Umbraco.Core;

src/Umbraco.Cms.Integrations.Automation.Zapier/Controllers/PollingController.cs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32

43
using System.Linq;
5-
4+
using System.Runtime.CompilerServices;
65
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
76
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
87
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
98

109
#if NETCOREAPP
1110
using Microsoft.Extensions.Options;
1211

12+
using Umbraco.Cms.Core.Web;
1313
using Umbraco.Cms.Web.Common.Controllers;
1414
using Umbraco.Cms.Core.Services;
15+
using Umbraco.Cms.Core.Models.PublishedContent;
16+
using Umbraco.Extensions;
1517
#else
1618
using System.Configuration;
1719

20+
using Umbraco.Web;
1821
using Umbraco.Web.WebApi;
1922
using Umbraco.Core.Services;
23+
using Umbraco.Core.Models.PublishedContent;
24+
2025
#endif
2126

2227
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
2328
{
2429
public class PollingController : UmbracoApiController
2530
{
26-
private readonly ZapierSettings Options;
31+
private IUmbracoContextFactory _umbracoContextFactory;
2732

2833
private IContentService _contentService;
2934

35+
private readonly ZapierSettings Options;
36+
3037
private ZapierFormService _zapierFormService;
3138

3239
private readonly IUserValidationService _userValidationService;
3340

3441
#if NETCOREAPP
35-
public PollingController(IOptions<ZapierSettings> options, IContentService contentService, ZapierFormService zapierFormService, IUserValidationService userValidationService)
42+
public PollingController(IOptions<ZapierSettings> options, IUmbracoContextFactory umbracoContextFactory, IContentService contentService, ZapierFormService zapierFormService, IUserValidationService userValidationService)
3643
#else
37-
public PollingController(IContentService contentService, ZapierFormService zapierFormService, IUserValidationService userValidationService)
44+
public PollingController(IUmbracoContextFactory umbracoContextFactory, IContentService contentService, ZapierFormService zapierFormService, IUserValidationService userValidationService)
3845
#endif
3946
{
4047
#if NETCOREAPP
@@ -43,6 +50,8 @@ public PollingController(IContentService contentService, ZapierFormService zapie
4350
Options = new ZapierSettings(ConfigurationManager.AppSettings);
4451
#endif
4552

53+
_umbracoContextFactory = umbracoContextFactory;
54+
4655
_contentService = contentService;
4756

4857
_zapierFormService = zapierFormService;
@@ -88,6 +97,40 @@ public IEnumerable<PublishedContentDto> GetSampleContent()
8897
});
8998
}
9099

100+
public List<Dictionary<string, string>> GetContentByAlias(string contentTypeAlias)
101+
{
102+
var list = new List<Dictionary<string, string>>();
103+
104+
using (var cref = _umbracoContextFactory.EnsureUmbracoContext())
105+
{
106+
var cache = cref.UmbracoContext.Content;
107+
108+
var nodes = cache.GetByXPath($"//{contentTypeAlias}")
109+
.Where(p => p.IsPublished())
110+
.OrderByDescending(p => p.UpdateDate);
111+
112+
foreach (var node in nodes)
113+
{
114+
var content = new Dictionary<string, string>
115+
{
116+
{Constants.Content.Id, node.Id.ToString() },
117+
{Constants.Content.Name, node.Name },
118+
{Constants.Content.PublishDate, node.UpdateDate.ToString("s") }
119+
};
120+
121+
foreach (var prop in node.Properties)
122+
{
123+
content.Add(prop.Alias, prop.GetValue().ToString());
124+
}
125+
126+
127+
list.Add(content);
128+
}
129+
130+
return list;
131+
}
132+
}
133+
91134
public IEnumerable<FormDto> GetSampleForm()
92135
{
93136
return _zapierFormService.GetAll();

0 commit comments

Comments
 (0)