Skip to content

Commit 67c81c4

Browse files
add database and GUI
1 parent 61933e0 commit 67c81c4

13 files changed

+279
-32
lines changed

Sherlog.Server/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ public class Config
66
public string SmtpUser { get; set; }
77
public string SmtpPassword { get; set; }
88
public string MailFrom { get; set; }
9+
public string MailReplyTo { get; set; }
910
}

Sherlog.Server/LogEntryDto.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ namespace Sherlog.Server;
22

33
public class LogEntryDto
44
{
5-
public int Id { get; set; }
65
public string Tenant { get; set; }
76
public List<string> RecipientGroups { get; set; }
87
public string LogType { get; set; }

Sherlog.Server/LogbookController.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Net;
22
using System.Net.Mail;
33
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.EntityFrameworkCore;
45

56
namespace Sherlog.Server;
67

@@ -19,6 +20,20 @@ public LogbookController()
1920
public async Task<ActionResult> AddLogEntry(LogEntryDto logEntry)
2021
{
2122
// Save the entry to database
23+
await using LogbookContext db = new LogbookContext();
24+
25+
var dbEntry = new LogEntry
26+
{
27+
Tenant = logEntry.Tenant,
28+
Project = logEntry.Project,
29+
Message = logEntry.Message,
30+
LogType = logEntry.LogType,
31+
RecipientGroups = string.Join(",", logEntry.RecipientGroups),
32+
CreatedAt = DateTime.Now,
33+
};
34+
db.LogEntries.Add(dbEntry);
35+
await db.SaveChangesAsync();
36+
2237

2338
// Get all contacts
2439
List<Contact> contacts = new();
@@ -53,6 +68,7 @@ public async Task<ActionResult> AddLogEntry(LogEntryDto logEntry)
5368
mail.To.Add(contact.Email);
5469
}
5570
mail.CC.Add(Program.Configuration.MailFrom);
71+
mail.ReplyToList.Add(Program.Configuration.MailReplyTo);
5672
mail.Subject = subject;
5773
mail.Body = message;
5874

@@ -62,9 +78,7 @@ public async Task<ActionResult> AddLogEntry(LogEntryDto logEntry)
6278
smtpServer.EnableSsl = true;
6379

6480
smtpServer.Send(mail);
65-
66-
67-
return CreatedAtAction(nameof(AddLogEntry), new { id = logEntry.Id }, logEntry);
81+
return CreatedAtAction(nameof(AddLogEntry), new { id = dbEntry.LogEntryId }, logEntry);
6882
}
6983

7084
[HttpGet("get-tenants")]

Sherlog.Server/Migrations/20240909164415_Initial.Designer.cs

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace Sherlog.Server.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class Initial : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.CreateTable(
15+
name: "LogEntries",
16+
columns: table => new
17+
{
18+
LogEntryId = table.Column<int>(type: "INTEGER", nullable: false)
19+
.Annotation("Sqlite:Autoincrement", true),
20+
Tenant = table.Column<string>(type: "TEXT", nullable: false),
21+
RecipientGroups = table.Column<string>(type: "TEXT", nullable: false),
22+
LogType = table.Column<string>(type: "TEXT", nullable: false),
23+
Project = table.Column<string>(type: "TEXT", nullable: false),
24+
Message = table.Column<string>(type: "TEXT", nullable: false),
25+
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false)
26+
},
27+
constraints: table =>
28+
{
29+
table.PrimaryKey("PK_LogEntries", x => x.LogEntryId);
30+
});
31+
}
32+
33+
/// <inheritdoc />
34+
protected override void Down(MigrationBuilder migrationBuilder)
35+
{
36+
migrationBuilder.DropTable(
37+
name: "LogEntries");
38+
}
39+
}
40+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// <auto-generated />
2+
using System;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Infrastructure;
5+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6+
using Sherlog.Server;
7+
8+
#nullable disable
9+
10+
namespace Sherlog.Server.Migrations
11+
{
12+
[DbContext(typeof(LogbookContext))]
13+
partial class LogbookContextModelSnapshot : ModelSnapshot
14+
{
15+
protected override void BuildModel(ModelBuilder modelBuilder)
16+
{
17+
#pragma warning disable 612, 618
18+
modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
19+
20+
modelBuilder.Entity("Sherlog.Server.LogEntry", b =>
21+
{
22+
b.Property<int>("LogEntryId")
23+
.ValueGeneratedOnAdd()
24+
.HasColumnType("INTEGER");
25+
26+
b.Property<DateTime>("CreatedAt")
27+
.HasColumnType("TEXT");
28+
29+
b.Property<string>("LogType")
30+
.IsRequired()
31+
.HasColumnType("TEXT");
32+
33+
b.Property<string>("Message")
34+
.IsRequired()
35+
.HasColumnType("TEXT");
36+
37+
b.Property<string>("Project")
38+
.IsRequired()
39+
.HasColumnType("TEXT");
40+
41+
b.Property<string>("RecipientGroups")
42+
.IsRequired()
43+
.HasColumnType("TEXT");
44+
45+
b.Property<string>("Tenant")
46+
.IsRequired()
47+
.HasColumnType("TEXT");
48+
49+
b.HasKey("LogEntryId");
50+
51+
b.ToTable("LogEntries");
52+
});
53+
#pragma warning restore 612, 618
54+
}
55+
}
56+
}

Sherlog.Server/Pages/Logbook.cshtml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@page
2+
@model LogbookModel
3+
@{
4+
ViewData["Title"] = "DevOps Logbook";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>This page shows sent log events:</p>
9+
10+
<table class="table">
11+
<thead>
12+
<tr>
13+
<th>Date/Time</th>
14+
<th>Tenant</th>
15+
<th>Project</th>
16+
<th>Type</th>
17+
<th>Recipient Groups</th>
18+
<th>Message</th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
@foreach (var le in Model.LogEntries)
23+
{
24+
<tr>
25+
<td>@le.CreatedAt.ToString("U")</td>
26+
<td>@le.Tenant</td>
27+
<td>@le.Project</td>
28+
<td>@le.LogType</td>
29+
<td>@le.RecipientGroups</td>
30+
<td>@le.Message</td>
31+
</tr>
32+
}
33+
</tbody>
34+
</table>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using Microsoft.EntityFrameworkCore;
4+
5+
namespace Sherlog.Server.Pages;
6+
7+
public class LogbookModel : PageModel
8+
{
9+
private readonly ILogger<LogbookModel> _logger;
10+
11+
public LogbookModel(ILogger<LogbookModel> logger)
12+
{
13+
_logger = logger;
14+
}
15+
16+
public async Task OnGetAsync()
17+
{
18+
var db = new LogbookContext();
19+
LogEntries = await db.LogEntries.ToListAsync();
20+
}
21+
22+
public List<LogEntry> LogEntries { get; set; }
23+
}

Sherlog.Server/Pages/Privacy.cshtml

Lines changed: 0 additions & 8 deletions
This file was deleted.

Sherlog.Server/Pages/Privacy.cshtml.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)