Skip to content

Commit 645c800

Browse files
committed
Fixed Database stuff. Added IndexController.cs
1 parent 2ae1ee8 commit 645c800

8 files changed

Lines changed: 42 additions & 5 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ obj/
44
riderModule.iml
55
/DisBot.DiscordBot/appsettings.json
66
/DisBot.DiscordBot/appsettings.Development.json
7+
/DisBot.API/appsettings.json
8+
/DisBot.API/appsettings.Development.json
9+
/DisBot.DiscordBot/appsettings.Development.json
710
/_ReSharper.Caches/
8-
Docker/.env
11+
Docker/.env
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.OpenApi;
3+
using Shared.Helper;
4+
5+
namespace DisBot.API.Controller.Http.General;
6+
7+
[ApiController]
8+
[Route("/")]
9+
public class IndexController : ControllerBase
10+
{
11+
[HttpGet]
12+
public async Task<ActionResult<object>> Get()
13+
{
14+
return new
15+
{
16+
version = await GitHubHelper.FetchLatestTagAsync(),
17+
status = "ok",
18+
docs = "https://docs.disbot.app/doc/api-2xx3snx3sb"
19+
};
20+
}
21+
}

DisBot.API/Startup/Startup.Base.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ private static async Task InitialiseBase(this WebApplicationBuilder builder)
1818
private static async Task LoadBase(this WebApplication application)
1919
{
2020
application.MapOpenApi();
21-
application.UseHttpsRedirection();
2221
}
2322
}

DisBot.API/Startup/Startup.Database.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ private static async Task InitialiseDatabase(this WebApplicationBuilder builder)
1212

1313
private static async Task LoadDatabase(this WebApplication application)
1414
{
15+
application.Logger.Log(LogLevel.Information, "Loading database...");
16+
1517
await using var scope = application.Services.CreateAsyncScope();
1618
var dataContext = scope.ServiceProvider.GetService<DataContext>();
1719
var migrations = await dataContext.Database.GetPendingMigrationsAsync();
1820
if (dataContext == null) throw new Exception("No Database Context found...");
21+
application.Logger.Log(LogLevel.Information, "Database initialized.");
1922
if (migrations.ToArray().Length > 0)
23+
{
2024
await dataContext.Database.MigrateAsync();
25+
application.Logger.Log(LogLevel.Information, "Database migrated.");
26+
}
27+
application.Logger.Log(LogLevel.Information, "Database ready to accept connections.");
2128
}
2229
}

DisBot.DiscordBot/DisBot.DiscordBot.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<Content Include="..\.dockerignore">
4141
<Link>.dockerignore</Link>
4242
</Content>
43+
<Content Update="appsettings.json">
44+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
45+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
46+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
47+
</Content>
4348
</ItemGroup>
4449

4550
<ItemGroup>

DisBot.DiscordBot/Startup/Startup.Bot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static partial class Startup
1515
{
1616
private static async Task InitialiseBot(this HostApplicationBuilder builder)
1717
{
18-
var version = await GitHubHelper.FetchLatestTag();
18+
var version = await GitHubHelper.FetchLatestTagAsync();
1919

2020
builder.Services
2121
.AddApplicationCommands()
@@ -40,7 +40,7 @@ private static async Task InitialiseBot(this HostApplicationBuilder builder)
4040
| GatewayIntents.DirectMessageReactions
4141
| GatewayIntents.GuildMessageReactions
4242
| GatewayIntents.Guilds
43-
| GatewayIntents.GuildPresences
43+
// | GatewayIntents.GuildPresences
4444
| GatewayIntents.GuildVoiceStates
4545
| GatewayIntents.GuildMessages
4646
| GatewayIntents.DirectMessages

DisBot.DiscordBot/Startup/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using DisBot.DiscordBot.Database;
2+
using Microsoft.Extensions.DependencyInjection;
13
using Microsoft.Extensions.Hosting;
24

35
namespace DisBot.DiscordBot.Startup;

DisBot.Shared/Helper/GitHubHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class GitHubHelper
88
{
99
public static readonly HttpClient HttpClient = new HttpClient();
1010

11-
public static async Task<string> FetchLatestTag()
11+
public static async Task<string> FetchLatestTagAsync()
1212
{
1313
HttpClient.DefaultRequestHeaders.Add("User-Agent", "DisBot-Github Helper");
1414
var data = await HttpClient.GetFromJsonAsync<GitHubTag[]>(

0 commit comments

Comments
 (0)