Skip to content

Commit

Permalink
Add [ApiController] and set ID convention correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieJKendall committed Feb 22, 2020
1 parent 632bce8 commit f0022db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/Snoozle/Abstractions/BaseResourceConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,21 @@ protected virtual void SetPropertyConfigurationDefaults()
/// </summary>
protected virtual void SetConventionsForProperties()
{
TPropertyConfiguration config;
var resourceIdName = typeof(TResource).Name.ToLowerInvariant() + "id";
var resourceIdPropertyConfig = _propertyConfigurations.FirstOrDefault(prop => prop.Key.ToLower() == resourceIdName).Value;
var idPropertyConfig = _propertyConfigurations.FirstOrDefault(prop => prop.Key.ToLower() == "id").Value;

// Set column called [resource_type_name]Id to primary identifier (i.e. Person -> PersonId)
var idPropName = typeof(TResource).Name.ToLowerInvariant() + "id";
config = _propertyConfigurations.FirstOrDefault(prop => prop.Key.ToLower() == idPropName).Value;

if (config != null)
if (idPropertyConfig != null)
{
config.IsPrimaryResourceIdentifier = true;
// Set column called Id to primary identifier
idPropertyConfig.IsPrimaryResourceIdentifier = true;
idPropertyConfig.IsReadOnly = true;
}

// Set column called Id to primary identifier
config = _propertyConfigurations.FirstOrDefault(prop => prop.Key.ToLower() == "id").Value;

if (config != null)
else if (resourceIdPropertyConfig != null)
{
_propertyConfigurations.Values.ToList().ForEach(prop => prop.IsPrimaryResourceIdentifier = false);
config.IsPrimaryResourceIdentifier = true;
// Set column called [resource_type_name]Id to primary identifier (i.e. Person -> PersonId)
resourceIdPropertyConfig.IsPrimaryResourceIdentifier = true;
resourceIdPropertyConfig.IsReadOnly = true;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Snoozle/Core/RestResourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Snoozle.Core
{
[Route("api/[controller]")]
[ApiController]
public sealed class RestResourceController<TResource> : ControllerBase
where TResource : class, IRestResource
{
Expand Down

0 comments on commit f0022db

Please sign in to comment.