Skip to content

Commit 723e980

Browse files
committed
Formatting etc
1 parent dbd86ab commit 723e980

File tree

3 files changed

+49
-51
lines changed

3 files changed

+49
-51
lines changed

src/Altinn.App.Core/Features/Correspondence/CorrespondenceClient.cs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public async Task<SendCorrespondenceResponse> Send(
5353
try
5454
{
5555
if (
56-
payload.CorrespondenceRequest.Content.Attachments.Count > 0
56+
payload.CorrespondenceRequest.Content.Attachments?.Count > 0
5757
&& payload.CorrespondenceRequest.Content.Attachments.All(a => a is CorrespondenceStreamedAttachment)
5858
)
5959
{
@@ -81,7 +81,17 @@ CorrespondenceStreamedAttachment attachment in payload.CorrespondenceRequest.Con
8181
initializeAttachmentRequest,
8282
cancellationToken
8383
);
84-
var attachmentId = await initializeAttachmentRequest.Content.ReadAsStringAsync(cancellationToken);
84+
var initializeAttachmentContent = initializeAttachmentRequest.Content;
85+
if (initializeAttachmentContent is null)
86+
{
87+
throw new CorrespondenceRequestException(
88+
"Attachment initialization request did not return content.",
89+
null,
90+
HttpStatusCode.InternalServerError,
91+
"No content returned from attachment initialization"
92+
);
93+
}
94+
var attachmentId = await initializeAttachmentContent.ReadAsStringAsync(cancellationToken);
8595
attachmentId = attachmentId.Trim('"');
8696
var attachmentDataContent = new StreamContent(attachment.Data);
8797
attachmentDataContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
@@ -155,39 +165,31 @@ CancellationToken cancellationToken
155165
{
156166
await Task.Delay(TimeSpan.FromSeconds(delaySeconds), cancellationToken);
157167

158-
try
159-
{
160-
var statusResponse = await AuthenticatedHttpRequestFactory(
161-
method: HttpMethod.Get,
162-
uri: GetUri($"attachment/{attachmentId}"),
163-
content: null,
164-
payload: payload
165-
);
168+
var statusResponse = await AuthenticatedHttpRequestFactory(
169+
method: HttpMethod.Get,
170+
uri: GetUri($"attachment/{attachmentId}"),
171+
content: null,
172+
payload: payload
173+
);
174+
var pollContent = statusResponse.Content;
166175

167-
var statusContent = await statusResponse.Content.ReadFromJsonAsync<AttachmentOverview>(
168-
cancellationToken
169-
);
170-
if (statusContent.Status == "Published")
171-
{
172-
break;
173-
}
176+
if (pollContent is null)
177+
{
178+
break;
174179
}
175-
catch (Exception ex)
180+
181+
var statusContent = await pollContent.ReadFromJsonAsync<AttachmentOverview>(cancellationToken);
182+
if (statusContent?.Status == "Published")
176183
{
177-
// Log the exception
178-
if (attempt == maxAttempts)
179-
{
180-
// Handle or rethrow the exception after all attempts failed
181-
throw;
182-
}
184+
return;
183185
}
184-
throw new CorrespondenceRequestException(
185-
$"Failure when uploading attachment. Attachment was not published in time. ",
186-
null,
187-
HttpStatusCode.InternalServerError,
188-
"Polling failed"
189-
);
190186
}
187+
throw new CorrespondenceRequestException(
188+
$"Failure when uploading attachment. Attachment was not published in time.",
189+
null,
190+
HttpStatusCode.InternalServerError,
191+
"Polling failed"
192+
);
191193
}
192194

193195
/// <inheritdoc/>
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
namespace Altinn.App.Core.Features.Correspondence.Models;
22

3-
public sealed record AttachmentPayload
3+
/// <summary>
4+
/// Represents the payload for sending an attachment.
5+
/// </summary>
6+
internal sealed record AttachmentPayload
47
{
58
/// <summary>
69
/// Gets or sets the Resource Id for the correspondence service.
710
/// </summary>
8-
internal string ResourceId { get; set; }
11+
internal required string ResourceId { get; set; }
912

1013
/// <summary>
1114
/// The name of the attachment file.
1215
/// </summary>
13-
public string? FileName { get; set; }
16+
internal string? FileName { get; set; }
1417

1518
/// <summary>
1619
/// A logical name for the file, which will be shown in Altinn Inbox.
1720
/// </summary>
18-
public string? DisplayName { get; set; }
21+
internal string? DisplayName { get; set; }
1922

2023
/// <summary>
2124
/// A value indicating whether the attachment is encrypted or not.
2225
/// </summary>
23-
public bool IsEncrypted { get; set; }
26+
internal required bool IsEncrypted { get; set; }
2427

2528
/// <summary>
2629
/// A reference value given to the attachment by the creator.
2730
/// </summary>
28-
public string SendersReference { get; set; }
31+
internal required string SendersReference { get; set; }
2932
}
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
namespace Altinn.App.Core.Features.Correspondence.Models.Response;
22

3-
public class AttachmentOverview
3+
/// <summary>
4+
/// Status of an attachment
5+
/// </summary>
6+
internal sealed record AttachmentOverview
47
{
58
/// <summary>
69
/// Unique Id for this attachment
710
/// </summary>
8-
public Guid AttachmentId { get; set; }
11+
internal required Guid AttachmentId { get; set; }
912

1013
/// <summary>
1114
/// Current attachment status
1215
/// </summary>
13-
public string Status { get; set; }
16+
internal required string Status { get; set; }
1417

1518
/// <summary>
1619
/// Current attachment status text description
1720
/// </summary>
18-
public string StatusText { get; set; }
21+
internal required string StatusText { get; set; }
1922

2023
/// <summary>
2124
/// Timestamp for when the Current Attachment Status was changed
2225
/// </summary>
23-
public DateTimeOffset StatusChanged { get; set; }
24-
25-
/// <summary>
26-
/// List of correspondences that are using this attachment
27-
/// </summary>
28-
public List<Guid> CorrespondenceIds { get; set; }
29-
30-
/// <summary>
31-
/// The attachment data type in MIME format
32-
/// </summary>
33-
public string DataType { get; set; }
26+
internal required DateTimeOffset StatusChanged { get; set; }
3427
}

0 commit comments

Comments
 (0)