clean up server
This commit is contained in:
@@ -2,24 +2,17 @@
|
||||
using EnvelopeGenerator.Common;
|
||||
using EnvelopeGenerator.Web.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NLog;
|
||||
using static EnvelopeGenerator.Web.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
public class EnvelopeController : Controller
|
||||
public class EnvelopeController : BaseController
|
||||
{
|
||||
private readonly DatabaseService database;
|
||||
private readonly LoggingService logging;
|
||||
private readonly Logger logger;
|
||||
private readonly ApiService api;
|
||||
private readonly EnvelopeService envelopeService;
|
||||
|
||||
public EnvelopeController(DatabaseService database, LoggingService logging, ApiService api)
|
||||
public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging)
|
||||
{
|
||||
this.database = database;
|
||||
this.logging = logging;
|
||||
this.logger = logging.LogConfig.GetLoggerFor(GetType().Name);
|
||||
this.api = api;
|
||||
envelopeService = envelope;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -28,23 +21,17 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("Handling envelope loading.");
|
||||
logger.Info("EnvelopeController/Get");
|
||||
|
||||
EnvelopeResponse r = api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
|
||||
// Return the envelope and additional data as json
|
||||
return Json(r);
|
||||
// Validate Envelope Key and load envelope
|
||||
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
|
||||
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
|
||||
|
||||
return Json(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Better error handling & reporting
|
||||
logger.Error(e);
|
||||
return Problem(
|
||||
statusCode: 500,
|
||||
detail: e.Message,
|
||||
type: ErrorType.ServerError.ToString());
|
||||
|
||||
return ErrorResponse(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,24 +41,21 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("Handling envelope saving.");
|
||||
logger.Info("EnvelopeController/Update");
|
||||
|
||||
EnvelopeResponse r = api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
// Validate Envelope Key and load envelope
|
||||
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
|
||||
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
|
||||
|
||||
var Request = ControllerContext.HttpContext.Request;
|
||||
var document = api.GetDocument(Request, envelopeKey);
|
||||
var document = envelopeService.GetDocument(Request, envelopeKey);
|
||||
|
||||
string? annotationData = await api.EnsureValidAnnotationData(Request);
|
||||
string annotationData = await envelopeService.EnsureValidAnnotationData(Request);
|
||||
|
||||
if (annotationData == null)
|
||||
envelopeService.InsertDocumentStatus(new DocumentStatus()
|
||||
{
|
||||
throw new ArgumentNullException("AnnotationData");
|
||||
}
|
||||
|
||||
database.InsertDocumentStatus(new DocumentStatus()
|
||||
{
|
||||
EnvelopeId = r.Envelope.Id,
|
||||
ReceiverId = r.Receiver.Id,
|
||||
EnvelopeId = response.Envelope.Id,
|
||||
ReceiverId = response.Receiver.Id,
|
||||
Value = annotationData,
|
||||
Status = Common.Constants.DocumentStatus.Signed
|
||||
});
|
||||
@@ -80,12 +64,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Better error handling & reporting
|
||||
logger.Error(e);
|
||||
return Problem(
|
||||
statusCode: 500,
|
||||
detail: e.Message,
|
||||
type: ErrorType.ServerError.ToString());
|
||||
return ErrorResponse(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user