Use new response model for create call

This commit is contained in:
anomny
2025-10-06 21:05:58 +02:00
parent 89d7cb6315
commit ba96fe0b22

View File

@@ -37,12 +37,16 @@ public class AssetsController : Controller
} }
[HttpPost("Create")] [HttpPost("Create")]
public async Task<bool> Create(AssetsCreateRequestModel assetModel) public async Task<AssetsResponseModel> Create(AssetsCreateRequestModel assetModel)
{ {
AssetsResponseModel result;
if (assetModel is null) if (assetModel is null)
{ {
_logger.LogError("Unable to create an asset because the AssetModel is null."); result = new AssetsResponseModel(
return false; successful: false,
exception: "Unable to create an asset because the AssetsCreateRequestModel is null.");
return result;
} }
try try
@@ -63,7 +67,7 @@ public class AssetsController : Controller
if (assetModel.Location != null) if (assetModel.Location != null)
{ {
attributeSet.Add(new LdapAttribute("l", assetModel.Location)); attributeSet.Add(new LdapAttribute("l", assetModel.Location));
} }
if (assetModel.Owner != null) if (assetModel.Owner != null)
{ {
var ownerDn = $"uid={assetModel.Owner}"; var ownerDn = $"uid={assetModel.Owner}";
@@ -108,14 +112,14 @@ public class AssetsController : Controller
} }
await _ldap.CreateAsset(attributeSet); await _ldap.CreateAsset(attributeSet);
result = new AssetsResponseModel(successful: true);
return true;
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogError($"Unable to create an asset because of the exception: {e.Message}", e); result = new AssetsResponseModel(successful: false, exception: e.Message);
return false; }
}
return result;
} }
[HttpDelete("Delete")] [HttpDelete("Delete")]