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