This commit is contained in:
Jonathan Jenne
2023-11-30 14:00:30 +01:00
parent 1b88a6cff7
commit c2de72be74
25 changed files with 875 additions and 148 deletions

View File

@@ -18,7 +18,7 @@ namespace EnvelopeGenerator.Web.Controllers
this.database = database;
this.logConfig = logging.LogConfig;
this.logger = logging.LogConfig.GetLoggerFor(GetType().Name);
this.state = GetState();
this.state = database.State;
}
internal ObjectResult ErrorResponse(Exception e)
@@ -29,15 +29,5 @@ namespace EnvelopeGenerator.Web.Controllers
detail: e.Message,
type: ErrorType.ServerError.ToString());
}
internal State GetState()
{
return new State
{
Database = database.MSSQL,
LogConfig = logConfig,
UserId = 2 // TODO
};
}
}
}

View File

@@ -1,16 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using EnvelopeGenerator.Common;
using EnvelopeGenerator.Web.Services;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Web.Controllers
{
public class DocumentController : BaseController
{
private readonly EnvelopeService envelopeService;
private readonly ActionService? actionService;
public DocumentController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging)
{
envelopeService = envelope;
actionService = database.Services?.actionService;
}
[HttpGet]
@@ -40,5 +43,28 @@ namespace EnvelopeGenerator.Web.Controllers
return ErrorResponse(e);
}
}
[HttpPost]
[Route("api/document/{envelopeKey}")]
public IActionResult Open(string envelopeKey)
{
try
{
logger.Info("DocumentController/Open");
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
actionService.OpenEnvelope(response.Envelope, response.Receiver.Id);
return Ok();
}
catch (Exception e)
{
return ErrorResponse(e);
}
}
}
}

View File

@@ -7,12 +7,12 @@ namespace EnvelopeGenerator.Web.Controllers
public class EnvelopeController : BaseController
{
private readonly EnvelopeService envelopeService;
private readonly EmailService emailService;
private readonly ActionService actionService;
public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging)
{
envelopeService = envelope;
emailService = new(state);
actionService = database.Services?.actionService;
}
[HttpGet]
@@ -52,17 +52,19 @@ namespace EnvelopeGenerator.Web.Controllers
string annotationData = await envelopeService.EnsureValidAnnotationData(Request);
envelopeService.InsertDocumentStatus(new DocumentStatus()
{
EnvelopeId = response.Envelope.Id,
ReceiverId = response.Receiver.Id,
Value = annotationData,
Status = Common.Constants.DocumentStatus.Signed
});
//envelopeService.InsertDocumentStatus(new DocumentStatus()
//{
// EnvelopeId = response.Envelope.Id,
// ReceiverId = response.Receiver.Id,
// Value = annotationData,
// Status = Common.Constants.DocumentStatus.Signed
//});
envelopeService.InsertHistoryEntrySigned(response);
//envelopeService.InsertHistoryEntrySigned(response);
emailService.SendSignedEmail(response.Receiver.Id, response.Envelope.Id);
//emailService.SendSignedEmail(response.Receiver.Id, response.Envelope.Id);
var signResult = actionService?.SignEnvelope(response.Envelope, response.Receiver.Id);
return Ok();
}

View File

@@ -1,45 +0,0 @@
using EnvelopeGenerator.Common;
using EnvelopeGenerator.Web.Services;
using Microsoft.AspNetCore.Mvc;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Web.Controllers
{
public class HistoryController : BaseController
{
private readonly EnvelopeService envelopeService;
public HistoryController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging)
{
envelopeService = envelope;
}
[HttpPost]
[Route("api/history/{envelopeKey}")]
public IActionResult Get(string envelopeKey)
{
try
{
logger.Info("HistoryController/Post");
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
envelopeService.InsertHistoryEntry(new EnvelopeHistoryEntry()
{
ActionDate = DateTime.Now,
Status = EnvelopeStatus.DocumentOpened,
EnvelopeId = response.Envelope.Id,
UserReference = response.Receiver.Email
});
return Ok();
}
catch (Exception e)
{
return ErrorResponse(e);
}
}
}
}

View File

@@ -7,6 +7,18 @@ namespace EnvelopeGenerator.Web.Services
{
public MSSQLServer MSSQL { get; set; }
public State State { get; set; }
public class ServiceContainer
{
public ActionService actionService;
public ServiceContainer(State state)
{
actionService = new(state);
}
}
public class ModelContainer
{
public EnvelopeModel envelopeModel;
@@ -31,6 +43,7 @@ namespace EnvelopeGenerator.Web.Services
}
}
public readonly ModelContainer? Models;
public readonly ServiceContainer? Services;
public DatabaseService(IConfiguration Config, LoggingService Logging) : base(Config, Logging)
{
@@ -41,19 +54,14 @@ namespace EnvelopeGenerator.Web.Services
if (MSSQL.DBInitialized == true)
{
logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
// There is a circular dependency between state and models
// All models need a state object, including the config Model
// The state object needs to be filled with the DbConfig property,
// which is obtained by the config Model.
// So first, the config model is initialized with an incomplete state object,
// then all the other models with the DbConfig property filled.
logger.Debug("MSSQL Connection established: [{0}]", MSSQL.MaskedConnectionString);
var state = GetState();
var configModel = new ConfigModel(state);
state.DbConfig = configModel.LoadConfiguration();
Models = new(state);
Models = new(state);
Services = new(state);
State = state;
}
else
{
@@ -61,13 +69,31 @@ namespace EnvelopeGenerator.Web.Services
}
}
public State GetState()
/// <summary>
/// There is a circular dependency between state and models
/// All models need a state object, including the config Model
/// The state object needs to be filled with the DbConfig property,
/// which is obtained by the config Model.
/// So first, the config model is initialized with an incomplete state object,
/// then all the other models with the DbConfig property filled.
/// </summary>
private State GetState()
{
var state = GetInitialState();
var configModel = new ConfigModel(state);
state.DbConfig = configModel.LoadConfiguration();
return state;
}
private State GetInitialState()
{
return new State
{
Database = MSSQL,
LogConfig = logConfig,
UserId = 2 // TODO
UserId = 0,
DbConfig = null
};
}
}

View File

@@ -8,11 +8,8 @@ namespace EnvelopeGenerator.Web.Services
{
public class EnvelopeService : BaseService
{
private ReceiverModel receiverModel;
private EnvelopeModel envelopeModel;
private HistoryModel historyModel;
private DocumentModel documentModel;
private DocumentStatusModel documentStatusModel;
private readonly ReceiverModel receiverModel;
private readonly EnvelopeModel envelopeModel;
public EnvelopeService(IConfiguration Config, LoggingService Logging, DatabaseService database) : base(Config, Logging)
{
@@ -25,9 +22,6 @@ namespace EnvelopeGenerator.Web.Services
receiverModel = database.Models.receiverModel;
envelopeModel = database.Models.envelopeModel;
historyModel = database.Models.historyModel;
documentModel = database.Models.documentModel;
documentStatusModel = database.Models.documentStatusModel;
}
public void EnsureValidEnvelopeKey(string envelopeKey)
@@ -48,7 +42,6 @@ namespace EnvelopeGenerator.Web.Services
throw new ArgumentNullException("ReceiverSignature");
}
public EnvelopeResponse LoadEnvelope(string pEnvelopeKey)
{
Tuple<string, string> result = Helpers.DecodeEnvelopeReceiverId(pEnvelopeKey);
@@ -101,27 +94,6 @@ namespace EnvelopeGenerator.Web.Services
return (List<Envelope>)envelopeModel.List(pReceiverId);
}
public bool InsertHistoryEntry(EnvelopeHistoryEntry historyEntry)
{
return historyModel.Insert(historyEntry);
}
public bool InsertHistoryEntrySigned(EnvelopeResponse response)
{
return historyModel.Insert(new EnvelopeHistoryEntry()
{
ActionDate = DateTime.Now,
Status = EnvelopeStatus.DocumentSigned,
EnvelopeId = response.Envelope.Id,
UserReference = response.Receiver.Email
});
}
public bool InsertDocumentStatus(Common.DocumentStatus documentStatus)
{
return documentStatusModel.InsertOrUpdate(documentStatus);
}
public async Task<string?> EnsureValidAnnotationData(HttpRequest request)
{
try
@@ -183,16 +155,6 @@ namespace EnvelopeGenerator.Web.Services
return document;
}
public async Task UpdateDocument(Stream fileStream, string filePath)
{
logger.Debug("Writing document to path [{0}]..", filePath);
using FileStream fs = new(filePath, FileMode.Open);
await fileStream.CopyToAsync(fs);
logger.Debug("Document written!");
}
public async Task<byte[]> GetDocumentContents(EnvelopeDocument document)
{
logger.Debug("Loading file [{0}]", document.Filepath);

View File

@@ -90,7 +90,7 @@ class App {
)
const createdAnnotations = await this.Instance.create(annotations)
await this.Network.postHistory(this.envelopeKey)
await this.Network.openDocument(this.envelopeKey)
} catch (e) {
console.error(e)
}

View File

@@ -32,8 +32,8 @@
})
}
postHistory(envelopeKey) {
const url = `/api/history/${envelopeKey}`
openDocument(envelopeKey) {
const url = `/api/document/${envelopeKey}`
const options = {
credentials: 'include',
@@ -44,7 +44,7 @@
body: JSON.stringify({}),
}
console.debug('PostHistory/Calling url: ' + url)
console.debug('OpenDocument/Calling url: ' + url)
return fetch(url, this.withCSRFToken(options))
.then(this.handleResponse)
.then((res) => {