Skip to content

Commit 33f0ea3

Browse files
committed
updated subscription and polling controllers
1 parent c494d03 commit 33f0ea3

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44

55
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
6+
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
67
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
78

89
#if NETCOREAPP
@@ -44,7 +45,7 @@ public PollingController(IContentService contentService, IUserValidationService
4445
_userValidationService = userValidationService;
4546
}
4647

47-
public List<Dictionary<string, string>> GetContent()
48+
public IEnumerable<PublishedContentDto> GetSampleContent()
4849
{
4950
string username = string.Empty;
5051
string password = string.Empty;
@@ -70,18 +71,15 @@ public List<Dictionary<string, string>> GetContent()
7071
var isAuthorized = _userValidationService.Validate(username, password, Options.UserGroup).GetAwaiter().GetResult();
7172
if (!isAuthorized) return null;
7273

73-
var root = _contentService.GetRootContent().Where(p => p.Published)
74-
.OrderByDescending(p => p.PublishDate).FirstOrDefault();
74+
var rootNodes = _contentService.GetRootContent().Where(p => p.Published)
75+
.OrderByDescending(p => p.PublishDate);
7576

76-
return new List<Dictionary<string, string>>
77+
return rootNodes.Select(p => new PublishedContentDto
7778
{
78-
new Dictionary<string, string>
79-
{
80-
{Constants.Content.Id, root?.Id.ToString()},
81-
{Constants.Content.Name, root?.Name},
82-
{Constants.Content.PublishDate, root?.PublishDate.ToString()}
83-
}
84-
};
79+
Id = p.Id,
80+
Name = p.Name,
81+
PublishDate = p.PublishDate.Value.ToString()
82+
});
8583
}
8684

8785
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public bool UpdatePreferences([FromBody] SubscriptionDto dto)
7171

7272
if (dto == null) return false;
7373

74-
var result = _zapConfigService.UpdatePreferences(dto.HookUrl, dto.Enable);
74+
var result = _zapConfigService.Subscribe(dto.HookUrl, dto.ContentType);
7575

7676
return string.IsNullOrEmpty(result);
7777
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Models/Dtos/SubscriptionDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class SubscriptionDto
77
[JsonProperty("hookUrl")]
88
public string HookUrl { get; set; }
99

10-
[JsonProperty("enable")]
11-
public bool Enable { get; set; }
10+
[JsonProperty("content_type")]
11+
public string ContentType { get; set; }
1212
}
1313
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Services/ZapConfigService.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public string UpdatePreferences(string hookUrl, bool enabled)
132132
if (entity != null)
133133
{
134134
entity.IsEnabled = enabled;
135+
135136
scope.Database.Update(entity);
136137
}
137138

@@ -144,6 +145,39 @@ public string UpdatePreferences(string hookUrl, bool enabled)
144145
{
145146
var message = $"An error has occurred while updating a hook: {e.Message}";
146147

148+
#if NETCOREAPP
149+
_logger.LogError(message);
150+
#else
151+
_logger.Error<ZapConfigService>(message);
152+
#endif
153+
154+
return message;
155+
}
156+
}
157+
158+
public string Subscribe(string hookUrl, string contentType)
159+
{
160+
try
161+
{
162+
using (var scope = _scopeProvider.CreateScope())
163+
{
164+
var zapContentConfig = new ZapContentConfigTable.ZapContentConfig
165+
{
166+
ContentTypeName = contentType,
167+
WebHookUrl = hookUrl,
168+
IsEnabled = true
169+
};
170+
171+
scope.Database.Insert(zapContentConfig);
172+
scope.Complete();
173+
}
174+
175+
return string.Empty;
176+
}
177+
catch (Exception e)
178+
{
179+
var message = $"An error has occurred while updating a hook: {e.Message}";
180+
147181
#if NETCOREAPP
148182
_logger.LogError(message);
149183
#else

0 commit comments

Comments
 (0)