Skip to content

Commit

Permalink
Add DueBefore to /active instances endpoint (#179)
Browse files Browse the repository at this point in the history
* Add DueBefore to /active instances endpoint

This is the same as #177,
but to add DueBefore in addition to PresentationValues

* Added test that dueBefore is mapped
  • Loading branch information
ivarne authored Feb 1, 2023
1 parent 7475a1b commit 86c7e3d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Altinn.App.Api/Controllers/InstancesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -698,15 +698,15 @@ public async Task<ActionResult<List<SimpleInstance>>> GetActiveInstances([FromRo
if (lastChangedBy?.Length == 9)
{
Organization? organization = await _registerClient.ER.GetOrganization(lastChangedBy);
if(organization is not null && !string.IsNullOrEmpty(organization.Name))
if (organization is not null && !string.IsNullOrEmpty(organization.Name))
{
userAndOrgLookup.Add(lastChangedBy, organization.Name);
}
}
else if (int.TryParse(lastChangedBy, out int lastChangedByInt))
{
UserProfile? user = await _profileClientClient.GetUserProfile(lastChangedByInt);
if(user is not null && user.Party is not null && !string.IsNullOrEmpty(user.Party.Name))
if (user is not null && user.Party is not null && !string.IsNullOrEmpty(user.Party.Name))
{
userAndOrgLookup.Add(lastChangedBy, user.Party.Name);
}
Expand Down
1 change: 1 addition & 0 deletions src/Altinn.App.Api/Mappers/SimpleInstanceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static SimpleInstance MapInstanceToSimpleInstance(Instance instance, stri
return new SimpleInstance
{
Id = instance.Id,
DueBefore = instance.DueBefore,
PresentationTexts = instance.PresentationTexts,
LastChanged = instance.LastChanged,
LastChangedBy = lastChangedByName
Expand Down
5 changes: 5 additions & 0 deletions src/Altinn.App.Api/Models/SimpleInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class SimpleInstance
/// </summary>
public Dictionary<string, string>? PresentationTexts { get; set; }

/// <summary>
/// Gets or sets the due date to submit the instance to application owner.
/// </summary>
public DateTime? DueBefore { get; set; }

/// <summary>
/// Last changed date time in UTC format.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public async Task UnknownUser_ReturnsEmptyString()
new()
{
Id = $"{1234}/{Guid.NewGuid()}",
DueBefore = DateTime.Today.AddDays(20),
LastChanged = DateTime.Now,
LastChangedBy = "12345",
PresentationTexts = new()
Expand All @@ -117,6 +118,7 @@ public async Task UnknownUser_ReturnsEmptyString()
var expected = instances.Select(i => new SimpleInstance()
{
Id = i.Id,
DueBefore = i.DueBefore,
PresentationTexts = i.PresentationTexts,
LastChanged = i.LastChanged,
LastChangedBy = i.LastChangedBy switch
Expand Down Expand Up @@ -169,6 +171,7 @@ public async Task UserProfilePartyIsNull_ReturnsEmptyString()
var expected = instances.Select(i => new SimpleInstance()
{
Id = i.Id,
DueBefore = i.DueBefore,
PresentationTexts = i.PresentationTexts,
LastChanged = i.LastChanged,
LastChangedBy = i.LastChangedBy switch
Expand Down Expand Up @@ -216,6 +219,7 @@ public async Task KnownUser_ReturnsUserName()
var expected = instances.Select(i => new SimpleInstance()
{
Id = i.Id,
DueBefore = i.DueBefore,
PresentationTexts = i.PresentationTexts,
LastChanged = i.LastChanged,
LastChangedBy = i.LastChangedBy switch
Expand Down Expand Up @@ -268,6 +272,7 @@ public async Task LastChangedBy9digits_LooksForOrg()
var expected = instances.Select(i => new SimpleInstance()
{
Id = i.Id,
DueBefore = i.DueBefore,
PresentationTexts = i.PresentationTexts,
LastChanged = i.LastChanged,
LastChangedBy = i.LastChangedBy switch
Expand Down Expand Up @@ -315,6 +320,7 @@ public async Task LastChangedBy9digits_FindsOrg()
var expected = instances.Select(i => new SimpleInstance()
{
Id = i.Id,
DueBefore = i.DueBefore,
PresentationTexts = i.PresentationTexts,
LastChanged = i.LastChanged,
LastChangedBy = i.LastChangedBy switch
Expand Down

0 comments on commit 86c7e3d

Please sign in to comment.