Skip to content

Commit

Permalink
Merge pull request #210 from digipost/share_document
Browse files Browse the repository at this point in the history
Share document
  • Loading branch information
eivinhb authored Nov 10, 2023
2 parents 94ac9b1 + 63c900d commit 60bf502
Show file tree
Hide file tree
Showing 21 changed files with 964 additions and 17 deletions.
53 changes: 47 additions & 6 deletions Digipost.Api.Client.Common/DataTransferObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Digipost.Api.Client.Common.Entrypoint;
using Digipost.Api.Client.Common.Enums;
using Digipost.Api.Client.Common.Extensions;
using Digipost.Api.Client.Common.Identify;
using Digipost.Api.Client.Common.Print;
using Digipost.Api.Client.Common.Recipient;
using Digipost.Api.Client.Common.Search;
using Digipost.Api.Client.Common.SenderInfo;
using Digipost.Api.Client.Common.Extensions;
using Digipost.Api.Client.Common.Share;
using Digipost.Api.Client.Send;
using V8;
using Identification = V8.Identification;
using Link = Digipost.Api.Client.Common.Entrypoint.Link;
using Root = Digipost.Api.Client.Common.Entrypoint.Root;

namespace Digipost.Api.Client.Common
{
Expand Down Expand Up @@ -182,15 +182,15 @@ internal static Print_Details ToDataTransferObject(this IPrintDetails printDetai
return printDetailsDataTransferObject;
}

internal static List<Print_Instruction> ToDataTransferObject(this IPrintInstructions printInstructions)
private static List<Print_Instruction> ToDataTransferObject(this IPrintInstructions printInstructions)
{
if (printInstructions == null || printInstructions.PrintInstruction.Count == 0)
return new List<Print_Instruction>();

return printInstructions.PrintInstruction.Select(ToDataTransferObject).ToList();
}

internal static Print_Instruction ToDataTransferObject(IPrintInstruction printInstruction)
private static Print_Instruction ToDataTransferObject(IPrintInstruction printInstruction)
{
if (printInstruction == null)
return null;
Expand Down Expand Up @@ -273,7 +273,8 @@ internal static Foreign_Address ToDataTransferObject(this IForeignAddress foreig
if (foreignAddress.CountryIdentifier == CountryIdentifier.Country)
{
result.Country = foreignAddress.CountryIdentifierValue;
} else if (foreignAddress.CountryIdentifier == CountryIdentifier.Countrycode)
}
else if (foreignAddress.CountryIdentifier == CountryIdentifier.Countrycode)
{
result.Country_Code = foreignAddress.CountryIdentifierValue;
}
Expand Down Expand Up @@ -361,6 +362,7 @@ internal static IIdentificationResult FromDataTransferObject(this Identification
{
return new IdentificationResult(IdentificationResultType.InvalidReason, identificationResultDto.Invalid_Reason.ToString());
}

if (identificationResultDto.Unidentified_ReasonSpecified)
{
return new IdentificationResult(IdentificationResultType.UnidentifiedReason, identificationResultDto.Unidentified_Reason.ToString());
Expand All @@ -384,6 +386,7 @@ private static IdentificationResult IdentificationResultForDigipostOrPersonalIde
default:
throw new ArgumentOutOfRangeException();
}

return identificationResult;
}

Expand All @@ -397,7 +400,7 @@ internal static Error FromDataTransferObject(this V8.Error error)
};
}

internal static SearchDetailsResult FromDataTransferObject(this V8.Recipients recipients)
internal static SearchDetailsResult FromDataTransferObject(this Recipients recipients)
{
return new SearchDetailsResult
{
Expand All @@ -424,5 +427,43 @@ internal static SearchDetailsResult FromDataTransferObject(this V8.Recipients re
};
}


internal static ShareDocumentsRequestState FromDataTransferObject(this Share_Documents_Request_State dto)
{
return new ShareDocumentsRequestState(
dto.Shared_At_TimeSpecified ? dto.Shared_At_Time : (DateTime?) null,
dto.Expiry_TimeSpecified ? dto.Expiry_Time : (DateTime?) null,
dto.Withdrawn_TimeSpecified ? dto.Withdrawn_Time : (DateTime?) null,
dto.Shared_Documents.FromDataTransferObject(),
dto.Link.FromDataTransferObject()
);
}

private static IEnumerable<SharedDocument> FromDataTransferObject(this Collection<Shared_Document> dto)
{
return dto.Select(document => new SharedDocument(
document.Delivery_Time,
document.Subject,
document.File_Type,
Convert.ToInt32(document.File_Size_Bytes),
document.Origin.FromDataTransferObject(),
document.Link.FromDataTransferObject()
)).ToList();
}

private static IOrigin FromDataTransferObject(this Shared_Document_Origin dto)
{
if (dto.Organisation != null)
{
return new OrganisationOrigin(dto.Organisation.Name, dto.Organisation.Organisation_Number);
}

return new PrivatePersonOrigin(dto.Private_Person.Name);
}

internal static SharedDocumentContent FromDataTransferObject(this Shared_Document_Content dto)
{
return new SharedDocumentContent(dto.Content_Type, new Uri(dto.Uri, UriKind.Absolute));
}
}
}
5 changes: 5 additions & 0 deletions Digipost.Api.Client.Common/Entrypoint/Entrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public DocumentStatusUri GetDocumentStatusUri(Guid guid)
{
return new DocumentStatusUri(Links["DOCUMENT_STATUS"], guid);
}

public ShareDocumentsRequestStateUri GetShareDocumentsRequestStateUri(Guid guid)
{
return new ShareDocumentsRequestStateUri(Links["GET_SHARE_DOCUMENTS_REQUEST_STATE"], guid);
}
}

public class Link
Expand Down
Loading

0 comments on commit 60bf502

Please sign in to comment.