Skip to content
Snippets Groups Projects
Commit 8af0ce2b authored by Klaus Fischer's avatar Klaus Fischer
Browse files

Implementing attachment upload

parent 10d98620
No related branches found
No related tags found
1 merge request!3Feature/440 mvp net sdk part 1
......@@ -2,8 +2,6 @@ using Microsoft.Extensions.Logging;
namespace FitConnect.Encryption;
// TODO: Throw useful error on macOS to add environment variable DYLD_LIBRARY_PATH to the path.
public record KeySet(string? PrivateKeyDecryption,
string? PrivateKeySigning, string? PublicKeyEncryption, string? PublicKeySignatureVerification
);
......
......@@ -136,57 +136,14 @@ public class FluentSender : Sender, IFluentSender, IFluentSenderWithDestination,
/// <summary>
/// Posts the <see cref="Attachment" />s to the FitConnect API. The attachment ids are sent with
/// creating the submission.
///
/// </summary>
/// <param name="attachments"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public FluentSender UploadAttachments() {
if (_nextStep != State.UploadAttachments)
throw new InvalidOperationException(
"Can only upload attachments after a submission has been created");
if (NewSubmission == null)
throw new InvalidOperationException("You must create a submission first.");
_nextStep = State.SendSubmission;
if (Submission.Attachments.Count == 0)
return this;
var encryptedAttachments = Encrypt(PublicKey, Submission.Attachments);
UploadAttachmentsAsync(encryptedAttachments).Wait();
return this;
}
/// <summary>
/// Sending the submission and finishing the process.
/// <para>
/// Finishing the submission by transmitting <see cref="Metadata" /> and <see cref="Data" />.
/// </para>
/// </summary>
/// <param name="metadata"></param>
/// <param name="data"></param>
/// <returns></returns>
/// <remarks>This call finishes the submission process</remarks>
/// <exception cref="InvalidOperationException"></exception>
// public FluentSender SendSubmission(Metadata? metadata, Data? data = null) {
// if (_nextStep != State.SendSubmission)
// throw new InvalidOperationException(
// "Can only send a submission after attachments have been uploaded");
//
// if (NewSubmission == null)
// throw new InvalidOperationException("You must create a submission first.");
//
// Submission.Metadata = metadata;
// Submission.Data = data;
// var submitSubmissionDto = CreateSubmitSubmissionDto(Submission);
// SubmissionService.SubmitSubmission(Submission.Id, submitSubmissionDto);
//
// _nextStep = State.Complete;
//
// return this;
// }
/// <exception cref="ArgumentException"></exception>
public IFluentSenderWithAttachments WithAttachments(IEnumerable<Attachment> attachments) {
Submission.Attachments = attachments.ToList();
Submission!.Attachments = attachments.ToList();
if (Submission.ServiceType == null)
throw new ArgumentException("Submission has no service type.");
......@@ -194,6 +151,9 @@ public class FluentSender : Sender, IFluentSender, IFluentSenderWithDestination,
Submission.Id = created.SubmissionId;
Submission.CaseId = created.CaseId;
var encryptedAttachments = Encrypt(PublicKey!, Submission.Attachments);
UploadAttachmentsAsync(Submission.Id!, encryptedAttachments).Wait();
return this;
}
......
using FitConnect.Models;
namespace FitConnect.Interfaces;
public interface IFluentSenderWithAttachments : IFluentSenderReady {
......@@ -7,4 +9,5 @@ public interface IFluentSenderWithAttachments : IFluentSenderReady {
/// <param name="data">json or xml as string</param>
/// <returns>next step to submit the data</returns>
public IFluentSenderWithData WithData(string data);
public Submission Submission { get; }
}
......@@ -11,7 +11,6 @@ using Newtonsoft.Json;
namespace FitConnect;
public class Sender : FunctionalBaseClass {
internal Sender(FitConnectEndpoints endpoints,
IOAuthService oAuthService,
ISubmissionService submissionService,
......@@ -114,9 +113,20 @@ public class Sender : FunctionalBaseClass {
/// </summary>
/// <param name="encryptedAttachments">Encrypted attachments with id and content</param>
/// <exception cref="NotImplementedException"></exception>
public async Task<bool> UploadAttachmentsAsync(
public async Task<bool> UploadAttachmentsAsync(string submissionId,
Dictionary<string, string> encryptedAttachments) {
throw new NotImplementedException();
// TODO: Upload encrypted attachments to server
try {
foreach (var (id, content) in encryptedAttachments) {
SubmissionService.UploadAttachment(submissionId, id, content);
}
return true;
}
catch (Exception e) {
Logger.LogError(e.Message);
return false;
}
}
public async Task SubmitSubmissionAsync(Submission submission) {
......
......@@ -3,7 +3,7 @@ using FitConnect.Services.Models.v1;
namespace FitConnect.Services;
public interface ISubmissionService: IAuthenticatedService {
public interface ISubmissionService : IAuthenticatedService {
/// <summary>
/// <para>@PostMapping("/submissions")</para>
/// </summary>
......@@ -73,4 +73,14 @@ public interface ISubmissionService: IAuthenticatedService {
/// <param name="keyId"></param>
/// <returns></returns>
string GetKey(string keyId);
/// <summary>
/// Uploads an attachment to the submission api
/// </summary>
/// <param name="submissionId"></param>
/// <param name="attachmentId"></param>
/// <param name="content"></param>
void UploadAttachment(string submissionId, string attachmentId, string content) =>
AddSubmissionAttachment(submissionId, attachmentId, content);
}
......@@ -17,7 +17,6 @@ public class RouteService : RestCallService, IRouteService {
/// <exception cref="NotImplementedException"></exception>
public async Task<string> GetDestinationIdAsync(string leiaKey, string? ags, string? ars,
string? areaId) {
// TODO: 1st step to implement
throw new NotImplementedException();
}
}
......@@ -11,7 +11,8 @@ For the structure look the [Structure documentation](structure.md)
## For information how to use the SDK and FitConnect visit:
* [SDK-Documentation](./documentation/documentation.md)
* [FitConnect Documentation](https://fit-connect.com/docs)
* [FIT-Connect Documentation](https://docs.fitko.de/fit-connect/docs)
* [FIT-Connect Documentation](https://fit-connect.com/docs)
## Ignored Files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment