Add history inserts, add controllers
This commit is contained in:
@@ -9,25 +9,28 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
public class HistoryController : Controller
|
||||
{
|
||||
private DatabaseService database;
|
||||
private LoggingService logging;
|
||||
private Logger logger;
|
||||
private ApiService api;
|
||||
private readonly DatabaseService database;
|
||||
private readonly LoggingService logging;
|
||||
private readonly Logger logger;
|
||||
private readonly ApiService api;
|
||||
|
||||
public HistoryController(DatabaseService database, LoggingService logging, ApiService api)
|
||||
{
|
||||
this.database = database;
|
||||
this.logging = logging;
|
||||
this.logger = logging.LogConfig.GetLoggerFor("HistoryController");
|
||||
this.logger = logging.LogConfig.GetLoggerFor(GetType().Name);
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/history/{envelopeKey}")]
|
||||
public IActionResult Create(HttpContext ctx, string envelopeKey)
|
||||
[IgnoreAntiforgeryToken]
|
||||
public IActionResult Create(string envelopeKey, [FromBody] ActionObject action)
|
||||
{
|
||||
try
|
||||
{
|
||||
var Request = ControllerContext.HttpContext.Request;
|
||||
|
||||
api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
EnvelopeResponse r = database.LoadEnvelope(envelopeKey);
|
||||
var receiver = r.Envelope.Receivers.Where(receiver => receiver.Id == r.ReceiverId).SingleOrDefault();
|
||||
@@ -37,8 +40,8 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
string actionTypeString = EnsureValidQueryField(ctx.Request, "actionType");
|
||||
string actionDescription = EnsureValidQueryField(ctx.Request, "actionDescription");
|
||||
string actionTypeString = action.actionType;
|
||||
string actionDescription = action.actionDescription;
|
||||
|
||||
if (!Enum.TryParse<EnvelopeHistoryActionType>(actionTypeString, out var actionType))
|
||||
{
|
||||
@@ -54,7 +57,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
UserReference = receiver.Email
|
||||
});
|
||||
|
||||
return Json(new { });
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -63,23 +66,10 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
private string EnsureValidQueryField(HttpRequest request, string fieldName)
|
||||
public class ActionObject
|
||||
{
|
||||
if (request.Query.TryGetValue(fieldName, out StringValues documentIndexString))
|
||||
{
|
||||
try
|
||||
{
|
||||
return documentIndexString.First();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArgumentNullException(fieldName, e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentNullException(fieldName);
|
||||
}
|
||||
public string actionType { get; set; }
|
||||
public string actionDescription { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user