Skip to content

Commit 516d4ea

Browse files
Merge pull request #41 from nullinside-development-group/feature/Poc2Prod
Adding interfaces for database
2 parents 62cf982 + ee7a6fd commit 516d4ea

File tree

10 files changed

+86
-15
lines changed

10 files changed

+86
-15
lines changed

src/Nullinside.Api.Common.AspNetCore/Middleware/BasicAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSc
2020
/// <summary>
2121
/// The nullinside database.
2222
/// </summary>
23-
private readonly NullinsideContext _dbContext;
23+
private readonly INullinsideContext _dbContext;
2424

2525
/// <summary>
2626
/// The logger.
@@ -35,7 +35,7 @@ public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSc
3535
/// <param name="encoder">The url encoder.</param>
3636
/// <param name="dbContext">The database.</param>
3737
public BasicAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger,
38-
UrlEncoder encoder, NullinsideContext dbContext) : base(options, logger, encoder) {
38+
UrlEncoder encoder, INullinsideContext dbContext) : base(options, logger, encoder) {
3939
_dbContext = dbContext;
4040
}
4141

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Infrastructure;
3+
4+
using Nullinside.Api.Model.Ddl;
5+
6+
namespace Nullinside.Api.Model;
7+
8+
/// <summary>
9+
/// Represents the nullinside database.
10+
/// </summary>
11+
public interface INullinsideContext {
12+
/// <summary>
13+
/// The users table which contains all of the users that have ever authenticated with the site.
14+
/// </summary>
15+
public DbSet<User> Users { get; set; }
16+
17+
/// <summary>
18+
/// The user's roles table which contains all of the "roles" the user has in the application.
19+
/// </summary>
20+
public DbSet<UserRole> UserRoles { get; set; }
21+
22+
/// <summary>
23+
/// The docker deployments that are configurable in the applications.
24+
/// </summary>
25+
public DbSet<DockerDeployments> DockerDeployments { get; set; }
26+
27+
/// <summary>
28+
/// The docker deployments that are configurable in the applications.
29+
/// </summary>
30+
public DbSet<TwitchUser> TwitchUser { get; set; }
31+
32+
/// <summary>
33+
/// The docker deployments that are configurable in the applications.
34+
/// </summary>
35+
public DbSet<TwitchBan> TwitchBan { get; set; }
36+
37+
/// <summary>
38+
/// The feature toggles.
39+
/// </summary>
40+
public DbSet<FeatureToggle> FeatureToggle { get; set; }
41+
42+
/// <summary>
43+
/// The twitch user configuration.
44+
/// </summary>
45+
public DbSet<TwitchUserConfig> TwitchUserConfig { get; set; }
46+
47+
/// <summary>
48+
/// The twitch logs of users banned outside the bot.
49+
/// </summary>
50+
public DbSet<TwitchUserBannedOutsideOfBotLogs> TwitchUserBannedOutsideOfBotLogs { get; set; }
51+
52+
/// <summary>
53+
/// The twitch logs of the user's chat.
54+
/// </summary>
55+
public DbSet<TwitchUserChatLogs> TwitchUserChatLogs { get; set; }
56+
57+
/// <summary>
58+
/// Provides access to database related information and operations for this context.
59+
/// </summary>
60+
public DatabaseFacade Database { get; }
61+
62+
/// <summary>
63+
/// Saves all changes made in this context to the database.
64+
/// </summary>
65+
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
66+
/// <returns>
67+
/// A task that represents the asynchronous save operation. The task result contains the
68+
/// number of state entries written to the database.
69+
/// </returns>
70+
public Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
71+
}

src/Nullinside.Api.Model/NullinsideContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Nullinside.Api.Model;
77
/// <summary>
88
/// The nullinside database.
99
/// </summary>
10-
public class NullinsideContext : DbContext {
10+
public class NullinsideContext : DbContext, INullinsideContext {
1111
/// <summary>
1212
/// Initializes a new instance of <see cref="NullinsideContext" />
1313
/// </summary>

src/Nullinside.Api.Model/Shared/UserHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class UserHelpers {
2323
/// <param name="twitchUsername">The username of the user on twitch.</param>
2424
/// <param name="twitchId">The id of the user on twitch.</param>
2525
/// <returns>The bearer token if successful, null otherwise.</returns>
26-
public static async Task<string?> GetTokenAndSaveToDatabase(NullinsideContext dbContext, string email,
26+
public static async Task<string?> GetTokenAndSaveToDatabase(INullinsideContext dbContext, string email,
2727
CancellationToken token = new(), string? authToken = null, string? refreshToken = null, DateTime? expires = null,
2828
string? twitchUsername = null, string? twitchId = null) {
2929
string bearerToken = GenerateBearerToken();

src/Nullinside.Api/Controllers/DatabaseController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class DatabaseController : ControllerBase {
1717
/// <summary>
1818
/// The nullinside database.
1919
/// </summary>
20-
private readonly NullinsideContext _dbContext;
20+
private readonly INullinsideContext _dbContext;
2121

2222
/// <summary>
2323
/// The logger.
@@ -28,7 +28,7 @@ public class DatabaseController : ControllerBase {
2828
/// Initializes a new instance of the <see cref="DatabaseController" /> class.
2929
/// </summary>
3030
/// <param name="dbContext">The nullinside database.</param>
31-
public DatabaseController(NullinsideContext dbContext) {
31+
public DatabaseController(INullinsideContext dbContext) {
3232
_dbContext = dbContext;
3333
}
3434

src/Nullinside.Api/Controllers/DockerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class DockerController : ControllerBase {
2323
/// <summary>
2424
/// The nullinside database.
2525
/// </summary>
26-
private readonly NullinsideContext _dbContext;
26+
private readonly INullinsideContext _dbContext;
2727

2828
/// <summary>
2929
/// The docker proxy.
@@ -40,7 +40,7 @@ public class DockerController : ControllerBase {
4040
/// </summary>
4141
/// <param name="dbContext">The nullinside database.</param>
4242
/// <param name="dockerProxy">The docker proxy.</param>
43-
public DockerController(NullinsideContext dbContext, IDockerProxy dockerProxy) {
43+
public DockerController(INullinsideContext dbContext, IDockerProxy dockerProxy) {
4444
_dbContext = dbContext;
4545
_docker = dockerProxy;
4646
}

src/Nullinside.Api/Controllers/FeatureToggleController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class FeatureToggleController : ControllerBase {
1717
/// <summary>
1818
/// The nullinside database.
1919
/// </summary>
20-
private readonly NullinsideContext _dbContext;
20+
private readonly INullinsideContext _dbContext;
2121

2222
/// <summary>
2323
/// The logger.
@@ -28,7 +28,7 @@ public class FeatureToggleController : ControllerBase {
2828
/// Initializes a new instance of the <see cref="FeatureToggleController" /> class.
2929
/// </summary>
3030
/// <param name="dbContext">The nullinside database.</param>
31-
public FeatureToggleController(NullinsideContext dbContext) {
31+
public FeatureToggleController(INullinsideContext dbContext) {
3232
_dbContext = dbContext;
3333
}
3434

src/Nullinside.Api/Controllers/TwitchBotController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class TwitchBotController : ControllerBase {
2424
/// <summary>
2525
/// The nullinside database.
2626
/// </summary>
27-
private readonly NullinsideContext _dbContext;
27+
private readonly INullinsideContext _dbContext;
2828

2929
/// <summary>
3030
/// The logger.
@@ -36,7 +36,7 @@ public class TwitchBotController : ControllerBase {
3636
/// </summary>
3737
/// <param name="configuration">The application's configuration file.</param>
3838
/// <param name="dbContext">The nullinside database.</param>
39-
public TwitchBotController(IConfiguration configuration, NullinsideContext dbContext) {
39+
public TwitchBotController(IConfiguration configuration, INullinsideContext dbContext) {
4040
_configuration = configuration;
4141
_dbContext = dbContext;
4242
}

src/Nullinside.Api/Controllers/UserController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class UserController : ControllerBase {
3030
/// <summary>
3131
/// The nullinside database.
3232
/// </summary>
33-
private readonly NullinsideContext _dbContext;
33+
private readonly INullinsideContext _dbContext;
3434

3535
/// <summary>
3636
/// The logger.
@@ -42,7 +42,7 @@ public class UserController : ControllerBase {
4242
/// </summary>
4343
/// <param name="configuration">The application's configuration file.</param>
4444
/// <param name="dbContext">The nullinside database.</param>
45-
public UserController(IConfiguration configuration, NullinsideContext dbContext) {
45+
public UserController(IConfiguration configuration, INullinsideContext dbContext) {
4646
_configuration = configuration;
4747
_dbContext = dbContext;
4848
}

src/Nullinside.Api/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
string? server = Environment.GetEnvironmentVariable("MYSQL_SERVER");
2323
string? username = Environment.GetEnvironmentVariable("MYSQL_USERNAME");
2424
string? password = Environment.GetEnvironmentVariable("MYSQL_PASSWORD");
25-
builder.Services.AddDbContext<NullinsideContext>(optionsBuilder =>
25+
builder.Services.AddDbContext<INullinsideContext, NullinsideContext>(optionsBuilder =>
2626
optionsBuilder.UseMySQL(
2727
$"server={server};database=nullinside;user={username};password={password};AllowUserVariables=true;",
2828
builder => {

0 commit comments

Comments
 (0)