Dashboard upgrades, workflows added and assitant emailer
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using System.Reflection;
|
||||
using JobTrackerApi.Data;
|
||||
using JobTrackerApi.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JobTrackerApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/system")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public sealed class AdminSystemController : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _cfg;
|
||||
private readonly AppPaths _paths;
|
||||
private readonly JobTrackerContext _db;
|
||||
private readonly ISummarizerService _summarizer;
|
||||
private readonly IWebHostEnvironment _env;
|
||||
|
||||
public AdminSystemController(IConfiguration cfg, AppPaths paths, JobTrackerContext db, ISummarizerService summarizer, IWebHostEnvironment env)
|
||||
{
|
||||
_cfg = cfg;
|
||||
_paths = paths;
|
||||
_db = db;
|
||||
_summarizer = summarizer;
|
||||
_env = env;
|
||||
}
|
||||
|
||||
public sealed record StorageStatusDto(string DataRoot, string DbPath, bool DbExists, long? DbSizeBytes, int CompanyCount, int JobCount, int DeletedCount);
|
||||
public sealed record EmailStatusDto(bool Enabled, string? Host, int Port, bool EnableSsl, string? From, string? FromName);
|
||||
public sealed record SystemStatusDto(
|
||||
string Environment,
|
||||
string ContentRoot,
|
||||
string Version,
|
||||
StorageStatusDto Storage,
|
||||
EmailStatusDto Email,
|
||||
SummarizerMetrics Summarizer
|
||||
);
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<SystemStatusDto>> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
var dbPath = _paths.GetDbPath();
|
||||
var dbFile = new FileInfo(dbPath);
|
||||
|
||||
var jobs = await _db.JobApplications.AsNoTracking().ToListAsync(cancellationToken);
|
||||
var companies = await _db.Companies.AsNoTracking().CountAsync(cancellationToken);
|
||||
var summarizer = await _summarizer.GetMetricsAsync(cancellationToken);
|
||||
|
||||
var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";
|
||||
|
||||
return Ok(new SystemStatusDto(
|
||||
Environment: _env.EnvironmentName,
|
||||
ContentRoot: _env.ContentRootPath,
|
||||
Version: version,
|
||||
Storage: new StorageStatusDto(
|
||||
DataRoot: _paths.DataRoot,
|
||||
DbPath: dbPath,
|
||||
DbExists: dbFile.Exists,
|
||||
DbSizeBytes: dbFile.Exists ? dbFile.Length : null,
|
||||
CompanyCount: companies,
|
||||
JobCount: jobs.Count,
|
||||
DeletedCount: jobs.Count(x => x.IsDeleted)
|
||||
),
|
||||
Email: new EmailStatusDto(
|
||||
Enabled: _cfg.GetValue("Email:Enabled", false),
|
||||
Host: (_cfg["Email:SmtpHost"] ?? "").Trim(),
|
||||
Port: _cfg.GetValue("Email:SmtpPort", 587),
|
||||
EnableSsl: _cfg.GetValue("Email:SmtpEnableSsl", true),
|
||||
From: (_cfg["Email:From"] ?? "").Trim(),
|
||||
FromName: (_cfg["Email:FromName"] ?? "").Trim()
|
||||
),
|
||||
Summarizer: summarizer
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user