Skip to content

Commit c494d03

Browse files
committed
Content Controller - get content types
1 parent c26d823 commit c494d03

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

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

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
using System.Linq;
45

@@ -24,14 +25,14 @@ public class ContentController : UmbracoApiController
2425
{
2526
private readonly ZapierSettings Options;
2627

27-
private IContentService _contentService;
28+
private IContentTypeService _contentTypeService;
2829

2930
private readonly IUserValidationService _userValidationService;
3031

3132
#if NETCOREAPP
32-
public ContentController(IOptions<ZapierSettings> options, IContentService contentService, IUserValidationService userValidationService)
33+
public ContentController(IOptions<ZapierSettings> options, IContentTypeService contentTypeService, IUserValidationService userValidationService)
3334
#else
34-
public ContentController(IContentService contentService, IUserValidationService userValidationService)
35+
public ContentController(IContentTypeService contentTypeService, IUserValidationService userValidationService)
3536
#endif
3637
{
3738
#if NETCOREAPP
@@ -40,44 +41,45 @@ public ContentController(IContentService contentService, IUserValidationService
4041
Options = new ZapierSettings(ConfigurationManager.AppSettings);
4142
#endif
4243

43-
_contentService = contentService;
44+
_contentTypeService = contentTypeService;
4445

4546
_userValidationService = userValidationService;
4647
}
4748

48-
public List<ContentTypeDto> Get()
49+
public IEnumerable<ContentTypeDto> GetContentTypes()
4950
{
50-
// string username = string.Empty;
51-
// string password = string.Empty;
52-
53-
//#if NETCOREAPP
54-
// if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey,
55-
// out var usernameValues))
56-
// username = usernameValues.First();
57-
// if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.PasswordHeaderKey,
58-
// out var passwordValues))
59-
// password = passwordValues.First();
60-
//#else
61-
// if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.UsernameHeaderKey,
62-
// out var usernameValues))
63-
// username = usernameValues.First();
64-
// if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.PasswordHeaderKey,
65-
// out var passwordValues))
66-
// password = passwordValues.First();
67-
//#endif
68-
69-
// if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return null;
70-
71-
// var isAuthorized = _userValidationService.Validate(username, password, Options.UserGroup).GetAwaiter().GetResult();
72-
// if (!isAuthorized) return null;
73-
74-
var root = _contentService.GetRootContent().Where(p => p.Published)
75-
.OrderByDescending(p => p.PublishDate).FirstOrDefault();
76-
77-
return new List<ContentTypeDto>
51+
string username = string.Empty;
52+
string password = string.Empty;
53+
54+
#if NETCOREAPP
55+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey,
56+
out var usernameValues))
57+
username = usernameValues.First();
58+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.PasswordHeaderKey,
59+
out var passwordValues))
60+
password = passwordValues.First();
61+
#else
62+
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.UsernameHeaderKey,
63+
out var usernameValues))
64+
username = usernameValues.First();
65+
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.PasswordHeaderKey,
66+
out var passwordValues))
67+
password = passwordValues.First();
68+
#endif
69+
70+
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return Enumerable.Empty<ContentTypeDto>();
71+
72+
var isAuthorized = _userValidationService.Validate(username, password, Options.UserGroup).GetAwaiter().GetResult();
73+
if (!isAuthorized) return Enumerable.Empty<ContentTypeDto>();
74+
75+
var contentTypes = _contentTypeService.GetAll();
76+
77+
return contentTypes.Select(p => new ContentTypeDto
7878
{
79-
new ContentTypeDto { Id = root.Id, Name = root.Name}
80-
};
79+
Id = p.Id,
80+
Alias = p.Alias,
81+
Name = p.Name
82+
});
8183
}
8284

8385
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ public class ContentTypeDto
77
[JsonProperty("id")]
88
public int Id { get; set; }
99

10+
[JsonProperty("alias")]
11+
public string Alias { get; set; }
12+
1013
[JsonProperty("name")]
1114
public string Name { get; set; }
1215
}

0 commit comments

Comments
 (0)