WIP: DataInbox API (PUT/GET)

This commit is contained in:
Michał Zieliski
2024-07-03 22:05:04 +02:00
parent b3f453b924
commit 26850c73ef
2 changed files with 17 additions and 6 deletions

View File

@@ -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);
}
}

View File

@@ -6,13 +6,13 @@ public class DataInbox
{
#region Properties
[Key]
public Guid Id { get; init; }
public Guid Id { get; set; }
[StringLength(50)]
public required string Name { get; init; }
[StringLength(50)]
public required string Source { get; set; }
[StringLength(int.MaxValue)]
public required string Data { get; init; }
public DateTime CreatedAt { get; init; }
public DateTime CreatedAt { get; set; }
#endregion
}