WIP: DataInbox API (PUT/GET)
This commit is contained in:
@@ -10,16 +10,16 @@ namespace WebAPI.Controllers;
|
||||
[Route("api/[controller]")]
|
||||
public class DataInboxController : Controller
|
||||
{
|
||||
private readonly GoogleDriveHelper _googleDriveHelper;
|
||||
private readonly AppDbContext _db;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly LogsController _logsController;
|
||||
|
||||
public DataInboxController(
|
||||
GoogleDriveHelper googleDriveHelper,
|
||||
AppDbContext db,
|
||||
GoogleSheetsHelper googleSheetsHelper,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_googleDriveHelper = googleDriveHelper;
|
||||
_db = db;
|
||||
_configuration = configuration;
|
||||
_logsController = new LogsController(googleSheetsHelper, _configuration);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class DataInboxController : Controller
|
||||
[HttpPut]
|
||||
[Route("Add/{apiKey}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Add([FromQuery] string apiKey, [FromBody] DataInbox dataInbox)
|
||||
public IActionResult Add(string apiKey, [FromBody] DataInbox dataInbox)
|
||||
{
|
||||
if (apiKey != _configuration["apiKey"])
|
||||
{
|
||||
@@ -43,6 +43,11 @@ public class DataInboxController : Controller
|
||||
|
||||
try
|
||||
{
|
||||
dataInbox.Id = Guid.NewGuid();
|
||||
dataInbox.CreatedAt = DateTime.UtcNow;
|
||||
_db.DataInbox.Add(dataInbox);
|
||||
_db.SaveChanges();
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"Insert success: {dataInbox.Source}, {dataInbox.Name}",
|
||||
@@ -66,4 +71,10 @@ public class DataInboxController : Controller
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetAll()
|
||||
{
|
||||
return Ok(_db.DataInbox);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user