Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a few convenience implementations for UpdateDataValues on IInstance interface #102

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Altinn.App.Core/Interface/IInstance.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Altinn.App.Core.Models;
using Altinn.Platform.Storage.Interface.Models;
using Microsoft.Extensions.Primitives;

Expand Down Expand Up @@ -92,6 +93,36 @@ public interface IInstance
/// <returns>Returns the updated instance.</returns>
Task<Instance> UpdateDataValues(int instanceOwnerPartyId, Guid instanceGuid, DataValues dataValues);

/// <summary>
/// Update data data values.
/// </summary>
/// <remarks>
/// The provided data value will be added with the existing collection of data values on the instance.
/// </remarks>
/// <param name="instance">The instance</param>
/// <param name="dataValues">The data value (null unsets the value)</param>
/// <returns>Returns the updated instance.</returns>
async Task<Instance> UpdateDataValues(Instance instance, Dictionary<string, string?> dataValues)
{
var id = new InstanceIdentifier(instance);
return await UpdateDataValues(id.InstanceOwnerPartyId, id.InstanceGuid, new DataValues{Values = dataValues});
}

/// <summary>
/// Update single data value.
/// </summary>
/// <remarks>
/// The provided data value will be added with the existing collection of data values on the instance.
/// </remarks>
/// <param name="instance">The instance</param>
/// <param name="key">The key of the DataValues collection to be updated.</param>
/// <param name="value">The data value (null unsets the value)</param>
/// <returns>Returns the updated instance.</returns>
async Task<Instance> UpdateDataValue(Instance instance, string key, string? value)
{
return await UpdateDataValues(instance, new Dictionary<string, string?>{{key, value}});
}

/// <summary>
/// Delete instance.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Altinn.App.Core/Models/InstanceIdentifier.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Altinn.Platform.Storage.Interface.Models;

namespace Altinn.App.Core.Models
{
/// <summary>
Expand Down Expand Up @@ -27,6 +29,12 @@ public InstanceIdentifier(string instanceId)
IsNoInstance = false;
}

/// <summary>
/// Initializes a new instance of the <see cref="InstanceIdentifier"/> class.
/// </summary>
/// <param name="instance">Is the instance you want to get an idenifier from</param>
public InstanceIdentifier(Instance instance) : this(instance.Id) {}

/// <summary>
/// Initializes a new instance of the <see cref="InstanceIdentifier"/> class. For instances without OwnerPartyId and InstanceId, ex: Stateless applications.
/// </summary>
Expand Down