Skip to content

Commit ab78cf7

Browse files
martinothamarolamathiesenBlueTree
authored andcommitted
DTO/response object for party information on 'InstanceResponse' (Altinn#1230)
1 parent 4dfc823 commit ab78cf7

File tree

4 files changed

+101
-186
lines changed

4 files changed

+101
-186
lines changed

src/Altinn.App.Api/Models/InstanceResponse.cs

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#nullable disable
2+
using Altinn.Platform.Register.Enums;
23
using Altinn.Platform.Register.Models;
34
using Altinn.Platform.Storage.Interface.Models;
45
using Newtonsoft.Json;
@@ -112,7 +113,7 @@ internal static InstanceResponse From(Instance instance, Party instanceOwnerPart
112113
PersonNumber = instance.InstanceOwner.PersonNumber,
113114
OrganisationNumber = instance.InstanceOwner.OrganisationNumber,
114115
Username = instance.InstanceOwner.Username,
115-
Party = instanceOwnerParty,
116+
Party = PartyResponse.From(instanceOwnerParty),
116117
},
117118
AppId = instance.AppId,
118119
Org = instance.Org,
@@ -136,7 +137,7 @@ internal static InstanceResponse From(Instance instance, Party instanceOwnerPart
136137
/// <summary>
137138
/// Represents information to identify the owner of an instance.
138139
/// </summary>
139-
public class InstanceOwnerResponse
140+
public sealed class InstanceOwnerResponse
140141
{
141142
/// <summary>
142143
/// Gets or sets the party id of the instance owner (also called instance owner party id).
@@ -161,5 +162,72 @@ public class InstanceOwnerResponse
161162
/// <summary>
162163
/// Party information for the instance owner.
163164
/// </summary>
164-
public required Party Party { get; init; }
165+
public required PartyResponse Party { get; init; }
166+
}
167+
168+
/// <summary>
169+
/// Class representing a party
170+
/// </summary>
171+
public sealed class PartyResponse
172+
{
173+
/// <summary>
174+
/// Gets or sets the ID of the party
175+
/// </summary>
176+
public required int PartyId { get; init; }
177+
178+
/// <summary>
179+
/// Gets or sets the UUID of the party
180+
/// </summary>
181+
public required Guid? PartyUuid { get; init; }
182+
183+
/// <summary>
184+
/// Gets or sets the type of party
185+
/// </summary>
186+
public required PartyType PartyTypeName { get; init; }
187+
188+
/// <summary>
189+
/// Gets the parties ssn
190+
/// </summary>
191+
public required string SSN { get; init; }
192+
193+
/// <summary>
194+
/// Gets the parties org number
195+
/// </summary>
196+
public required string OrgNumber { get; init; }
197+
198+
/// <summary>
199+
/// Gets or sets the UnitType
200+
/// </summary>
201+
public required string UnitType { get; init; }
202+
203+
/// <summary>
204+
/// Gets or sets the Name
205+
/// </summary>
206+
public required string Name { get; init; }
207+
208+
/// <summary>
209+
/// Gets or sets the IsDeleted
210+
/// </summary>
211+
public required bool IsDeleted { get; init; }
212+
213+
/// <summary>
214+
/// Returns a PartyResponse dto from a Party object.
215+
/// </summary>
216+
/// <param name="party">The party object to convert.</param>
217+
/// <returns>A PartyResponse object.</returns>
218+
/// <remarks>Normalizes strings to null if they are empty or null.</remarks>
219+
internal static PartyResponse From(Party party)
220+
{
221+
return new PartyResponse
222+
{
223+
PartyId = party.PartyId,
224+
PartyUuid = party.PartyUuid,
225+
PartyTypeName = party.PartyTypeName,
226+
SSN = string.IsNullOrEmpty(party.SSN) ? null : party.SSN,
227+
OrgNumber = string.IsNullOrEmpty(party.OrgNumber) ? null : party.OrgNumber,
228+
UnitType = string.IsNullOrEmpty(party.UnitType) ? null : party.UnitType,
229+
Name = string.IsNullOrEmpty(party.Name) ? null : party.Name,
230+
IsDeleted = party.IsDeleted,
231+
};
232+
}
165233
}

test/Altinn.App.Api.Tests/Controllers/InstancesController_GetTests.ReturnsOkResult_Deserialized.verified.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
PartyTypeName: Person,
1010
SSN: 01039012345,
1111
Name: Sophie Salt,
12-
IsDeleted: false,
13-
OnlyHierarchyElementWithNoAccess: false
12+
IsDeleted: false
1413
}
1514
},
1615
AppId: tdd/contributer-restriction,
@@ -60,8 +59,7 @@
6059
PartyTypeName: Person,
6160
SSN: 01039012345,
6261
Name: Sophie Salt,
63-
IsDeleted: false,
64-
OnlyHierarchyElementWithNoAccess: false
62+
IsDeleted: false
6563
}
6664
},
6765
AppId: tdd/contributer-restriction,

test/Altinn.App.Api.Tests/Controllers/InstancesController_GetTests.ReturnsOkResult_Raw.verified.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
partyId: 501337,
1111
partyUuid: null,
1212
partyTypeName: 1,
13-
orgNumber: null,
1413
ssn: 01039012345,
14+
orgNumber: null,
1515
unitType: null,
1616
name: Sophie Salt,
17-
isDeleted: false,
18-
onlyHierarchyElementWithNoAccess: false,
19-
person: null,
20-
organization: null,
21-
childParties: null
17+
isDeleted: false
2218
}
2319
},
2420
appId: tdd/contributer-restriction,
@@ -102,15 +98,11 @@
10298
partyId: 501337,
10399
partyUuid: null,
104100
partyTypeName: 1,
105-
orgNumber: null,
106101
ssn: 01039012345,
102+
orgNumber: null,
107103
unitType: null,
108104
name: Sophie Salt,
109-
isDeleted: false,
110-
onlyHierarchyElementWithNoAccess: false,
111-
person: null,
112-
organization: null,
113-
childParties: null
105+
isDeleted: false
114106
}
115107
},
116108
appId: tdd/contributer-restriction,

test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveJsonSwagger.verified.json

Lines changed: 24 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -7008,7 +7008,7 @@
70087008
"nullable": true
70097009
},
70107010
"party": {
7011-
"$ref": "#/components/schemas/Party"
7011+
"$ref": "#/components/schemas/PartyResponse"
70127012
}
70137013
},
70147014
"additionalProperties": false,
@@ -7486,124 +7486,60 @@
74867486
"additionalProperties": false,
74877487
"description": "Contains details about an organisation"
74887488
},
7489-
"Organization": {
7490-
"type": "object",
7491-
"properties": {
7492-
"orgNumber": {
7493-
"type": "string",
7494-
"nullable": true
7495-
},
7496-
"name": {
7497-
"type": "string",
7498-
"nullable": true
7499-
},
7500-
"unitType": {
7501-
"type": "string",
7502-
"nullable": true
7503-
},
7504-
"telephoneNumber": {
7505-
"type": "string",
7506-
"nullable": true
7507-
},
7508-
"mobileNumber": {
7509-
"type": "string",
7510-
"nullable": true
7511-
},
7512-
"faxNumber": {
7513-
"type": "string",
7514-
"nullable": true
7515-
},
7516-
"eMailAddress": {
7517-
"type": "string",
7518-
"nullable": true
7519-
},
7520-
"internetAddress": {
7521-
"type": "string",
7522-
"nullable": true
7523-
},
7524-
"mailingAddress": {
7525-
"type": "string",
7526-
"nullable": true
7527-
},
7528-
"mailingPostalCode": {
7529-
"type": "string",
7530-
"nullable": true
7531-
},
7532-
"mailingPostalCity": {
7533-
"type": "string",
7534-
"nullable": true
7535-
},
7536-
"businessAddress": {
7537-
"type": "string",
7538-
"nullable": true
7539-
},
7540-
"businessPostalCode": {
7541-
"type": "string",
7542-
"nullable": true
7543-
},
7544-
"businessPostalCity": {
7545-
"type": "string",
7546-
"nullable": true
7547-
},
7548-
"unitStatus": {
7549-
"type": "string",
7550-
"nullable": true
7551-
}
7552-
},
7553-
"additionalProperties": false
7554-
},
7555-
"Party": {
7489+
"PartyResponse": {
7490+
"required": [
7491+
"isDeleted",
7492+
"name",
7493+
"orgNumber",
7494+
"partyId",
7495+
"partyTypeName",
7496+
"partyUuid",
7497+
"ssn",
7498+
"unitType"
7499+
],
75567500
"type": "object",
75577501
"properties": {
75587502
"partyId": {
75597503
"type": "integer",
7504+
"description": "Gets or sets the ID of the party",
75607505
"format": "int32"
75617506
},
75627507
"partyUuid": {
75637508
"type": "string",
7509+
"description": "Gets or sets the UUID of the party",
75647510
"format": "uuid",
75657511
"nullable": true
75667512
},
75677513
"partyTypeName": {
75687514
"$ref": "#/components/schemas/PartyType"
75697515
},
7570-
"orgNumber": {
7516+
"ssn": {
75717517
"type": "string",
7518+
"description": "Gets the parties ssn",
75727519
"nullable": true
75737520
},
7574-
"ssn": {
7521+
"orgNumber": {
75757522
"type": "string",
7523+
"description": "Gets the parties org number",
75767524
"nullable": true
75777525
},
75787526
"unitType": {
75797527
"type": "string",
7528+
"description": "Gets or sets the UnitType",
75807529
"nullable": true
75817530
},
75827531
"name": {
75837532
"type": "string",
7533+
"description": "Gets or sets the Name",
75847534
"nullable": true
75857535
},
75867536
"isDeleted": {
7587-
"type": "boolean"
7588-
},
7589-
"onlyHierarchyElementWithNoAccess": {
7590-
"type": "boolean"
7591-
},
7592-
"person": {
7593-
"$ref": "#/components/schemas/Person"
7594-
},
7595-
"organization": {
7596-
"$ref": "#/components/schemas/Organization"
7597-
},
7598-
"childParties": {
7599-
"type": "array",
7600-
"items": {
7601-
"$ref": "#/components/schemas/Party"
7602-
},
7603-
"nullable": true
7537+
"type": "boolean",
7538+
"description": "Gets or sets the IsDeleted"
76047539
}
76057540
},
7606-
"additionalProperties": false
7541+
"additionalProperties": false,
7542+
"description": "Class representing a party"
76077543
},
76087544
"PartyType": {
76097545
"enum": [
@@ -7885,85 +7821,6 @@
78857821
],
78867822
"type": "string"
78877823
},
7888-
"Person": {
7889-
"type": "object",
7890-
"properties": {
7891-
"ssn": {
7892-
"type": "string",
7893-
"nullable": true
7894-
},
7895-
"name": {
7896-
"type": "string",
7897-
"nullable": true
7898-
},
7899-
"firstName": {
7900-
"type": "string",
7901-
"nullable": true
7902-
},
7903-
"middleName": {
7904-
"type": "string",
7905-
"nullable": true
7906-
},
7907-
"lastName": {
7908-
"type": "string",
7909-
"nullable": true
7910-
},
7911-
"telephoneNumber": {
7912-
"type": "string",
7913-
"nullable": true
7914-
},
7915-
"mobileNumber": {
7916-
"type": "string",
7917-
"nullable": true
7918-
},
7919-
"mailingAddress": {
7920-
"type": "string",
7921-
"nullable": true
7922-
},
7923-
"mailingPostalCode": {
7924-
"type": "string",
7925-
"nullable": true
7926-
},
7927-
"mailingPostalCity": {
7928-
"type": "string",
7929-
"nullable": true
7930-
},
7931-
"addressMunicipalNumber": {
7932-
"type": "string",
7933-
"nullable": true
7934-
},
7935-
"addressMunicipalName": {
7936-
"type": "string",
7937-
"nullable": true
7938-
},
7939-
"addressStreetName": {
7940-
"type": "string",
7941-
"nullable": true
7942-
},
7943-
"addressHouseNumber": {
7944-
"type": "string",
7945-
"nullable": true
7946-
},
7947-
"addressHouseLetter": {
7948-
"type": "string",
7949-
"nullable": true
7950-
},
7951-
"addressPostalCode": {
7952-
"type": "string",
7953-
"nullable": true
7954-
},
7955-
"addressCity": {
7956-
"type": "string",
7957-
"nullable": true
7958-
},
7959-
"dateOfDeath": {
7960-
"type": "string",
7961-
"format": "date-time",
7962-
"nullable": true
7963-
}
7964-
},
7965-
"additionalProperties": false
7966-
},
79677824
"PersonDetails": {
79687825
"required": [
79697826
"lastName",

0 commit comments

Comments
 (0)