WIP: DataInbox
This commit is contained in:
@@ -9,6 +9,7 @@ public class AppDbContext : DbContext
|
||||
public DbSet<Layer> Layers { get; init; }
|
||||
public DbSet<Record> Records { get; init; }
|
||||
public DbSet<ProcessSource> ProcessSources { get; init; }
|
||||
public DbSet<DataInbox> DataInbox { get; set; }
|
||||
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
||||
{
|
||||
|
||||
69
WebAPI/Controllers/DataInboxController.cs
Normal file
69
WebAPI/Controllers/DataInboxController.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Data;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using WebAPI.Models;
|
||||
|
||||
namespace WebAPI.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DataInboxController : Controller
|
||||
{
|
||||
private readonly GoogleDriveHelper _googleDriveHelper;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly LogsController _logsController;
|
||||
|
||||
public DataInboxController(
|
||||
GoogleDriveHelper googleDriveHelper,
|
||||
GoogleSheetsHelper googleSheetsHelper,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_googleDriveHelper = googleDriveHelper;
|
||||
_configuration = configuration;
|
||||
_logsController = new LogsController(googleSheetsHelper, _configuration);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Route("Add/{apiKey}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Add([FromQuery] string apiKey, [FromBody] DataInbox dataInbox)
|
||||
{
|
||||
if (apiKey != _configuration["apiKey"])
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"Unauthorized request - wrong apiKey ({dataInbox.Source})",
|
||||
Type = LogEntryType.Warning,
|
||||
LogType = LogType.DataInbox,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"Insert success: {dataInbox.Source}, {dataInbox.Name}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.DataInbox,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"Insert error: {dataInbox.Source}, {dataInbox.Name}",
|
||||
Type = LogEntryType.Error,
|
||||
LogType = LogType.DataInbox,
|
||||
Message = e.ToString(),
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ public class LogsController : Controller
|
||||
LogType.Backup => "Backup",
|
||||
LogType.Process => "Process",
|
||||
LogType.PowerBi => "PowerBIAccess",
|
||||
LogType.DataInbox => "DataInbox",
|
||||
_ => "Other"
|
||||
};
|
||||
var response = _googleSheetValues.Get(_configuration["appLogsFile"], $"{type}!A:A").Execute();
|
||||
|
||||
18
WebAPI/Models/DataInbox.cs
Normal file
18
WebAPI/Models/DataInbox.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace WebAPI.Models;
|
||||
|
||||
public class DataInbox
|
||||
{
|
||||
#region Properties
|
||||
[Key]
|
||||
public Guid Id { get; init; }
|
||||
[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; }
|
||||
#endregion
|
||||
}
|
||||
@@ -10,7 +10,8 @@ public enum LogType {
|
||||
Import,
|
||||
Backup,
|
||||
Process,
|
||||
PowerBi
|
||||
PowerBi,
|
||||
DataInbox
|
||||
}
|
||||
public class LogEntry
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user