Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSc
/// <summary>
/// The nullinside database.
/// </summary>
private readonly NullinsideContext _dbContext;
private readonly INullinsideContext _dbContext;

/// <summary>
/// The logger.
Expand All @@ -35,7 +35,7 @@ public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSc
/// <param name="encoder">The url encoder.</param>
/// <param name="dbContext">The database.</param>
public BasicAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger,
UrlEncoder encoder, NullinsideContext dbContext) : base(options, logger, encoder) {
UrlEncoder encoder, INullinsideContext dbContext) : base(options, logger, encoder) {
_dbContext = dbContext;
}

Expand Down
71 changes: 71 additions & 0 deletions src/Nullinside.Api.Model/INullinsideContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

using Nullinside.Api.Model.Ddl;

namespace Nullinside.Api.Model;

/// <summary>
/// Represents the nullinside database.
/// </summary>
public interface INullinsideContext {
/// <summary>
/// The users table which contains all of the users that have ever authenticated with the site.
/// </summary>
public DbSet<User> Users { get; set; }

/// <summary>
/// The user's roles table which contains all of the "roles" the user has in the application.
/// </summary>
public DbSet<UserRole> UserRoles { get; set; }

/// <summary>
/// The docker deployments that are configurable in the applications.
/// </summary>
public DbSet<DockerDeployments> DockerDeployments { get; set; }

/// <summary>
/// The docker deployments that are configurable in the applications.
/// </summary>
public DbSet<TwitchUser> TwitchUser { get; set; }

/// <summary>
/// The docker deployments that are configurable in the applications.
/// </summary>
public DbSet<TwitchBan> TwitchBan { get; set; }

/// <summary>
/// The feature toggles.
/// </summary>
public DbSet<FeatureToggle> FeatureToggle { get; set; }

/// <summary>
/// The twitch user configuration.
/// </summary>
public DbSet<TwitchUserConfig> TwitchUserConfig { get; set; }

/// <summary>
/// The twitch logs of users banned outside the bot.
/// </summary>
public DbSet<TwitchUserBannedOutsideOfBotLogs> TwitchUserBannedOutsideOfBotLogs { get; set; }

/// <summary>
/// The twitch logs of the user's chat.
/// </summary>
public DbSet<TwitchUserChatLogs> TwitchUserChatLogs { get; set; }

/// <summary>
/// Provides access to database related information and operations for this context.
/// </summary>
public DatabaseFacade Database { get; }

/// <summary>
/// Saves all changes made in this context to the database.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>
/// A task that represents the asynchronous save operation. The task result contains the
/// number of state entries written to the database.
/// </returns>
public Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
2 changes: 1 addition & 1 deletion src/Nullinside.Api.Model/NullinsideContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Nullinside.Api.Model;
/// <summary>
/// The nullinside database.
/// </summary>
public class NullinsideContext : DbContext {
public class NullinsideContext : DbContext, INullinsideContext {
/// <summary>
/// Initializes a new instance of <see cref="NullinsideContext" />
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.Model/Shared/UserHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class UserHelpers {
/// <param name="twitchUsername">The username of the user on twitch.</param>
/// <param name="twitchId">The id of the user on twitch.</param>
/// <returns>The bearer token if successful, null otherwise.</returns>
public static async Task<string?> GetTokenAndSaveToDatabase(NullinsideContext dbContext, string email,
public static async Task<string?> GetTokenAndSaveToDatabase(INullinsideContext dbContext, string email,
CancellationToken token = new(), string? authToken = null, string? refreshToken = null, DateTime? expires = null,
string? twitchUsername = null, string? twitchId = null) {
string bearerToken = GenerateBearerToken();
Expand Down
4 changes: 2 additions & 2 deletions src/Nullinside.Api/Controllers/DatabaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DatabaseController : ControllerBase {
/// <summary>
/// The nullinside database.
/// </summary>
private readonly NullinsideContext _dbContext;
private readonly INullinsideContext _dbContext;

/// <summary>
/// The logger.
Expand All @@ -28,7 +28,7 @@ public class DatabaseController : ControllerBase {
/// Initializes a new instance of the <see cref="DatabaseController" /> class.
/// </summary>
/// <param name="dbContext">The nullinside database.</param>
public DatabaseController(NullinsideContext dbContext) {
public DatabaseController(INullinsideContext dbContext) {
_dbContext = dbContext;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Nullinside.Api/Controllers/DockerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DockerController : ControllerBase {
/// <summary>
/// The nullinside database.
/// </summary>
private readonly NullinsideContext _dbContext;
private readonly INullinsideContext _dbContext;

/// <summary>
/// The docker proxy.
Expand All @@ -40,7 +40,7 @@ public class DockerController : ControllerBase {
/// </summary>
/// <param name="dbContext">The nullinside database.</param>
/// <param name="dockerProxy">The docker proxy.</param>
public DockerController(NullinsideContext dbContext, IDockerProxy dockerProxy) {
public DockerController(INullinsideContext dbContext, IDockerProxy dockerProxy) {
_dbContext = dbContext;
_docker = dockerProxy;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Nullinside.Api/Controllers/FeatureToggleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FeatureToggleController : ControllerBase {
/// <summary>
/// The nullinside database.
/// </summary>
private readonly NullinsideContext _dbContext;
private readonly INullinsideContext _dbContext;

/// <summary>
/// The logger.
Expand All @@ -28,7 +28,7 @@ public class FeatureToggleController : ControllerBase {
/// Initializes a new instance of the <see cref="FeatureToggleController" /> class.
/// </summary>
/// <param name="dbContext">The nullinside database.</param>
public FeatureToggleController(NullinsideContext dbContext) {
public FeatureToggleController(INullinsideContext dbContext) {
_dbContext = dbContext;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Nullinside.Api/Controllers/TwitchBotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class TwitchBotController : ControllerBase {
/// <summary>
/// The nullinside database.
/// </summary>
private readonly NullinsideContext _dbContext;
private readonly INullinsideContext _dbContext;

/// <summary>
/// The logger.
Expand All @@ -36,7 +36,7 @@ public class TwitchBotController : ControllerBase {
/// </summary>
/// <param name="configuration">The application's configuration file.</param>
/// <param name="dbContext">The nullinside database.</param>
public TwitchBotController(IConfiguration configuration, NullinsideContext dbContext) {
public TwitchBotController(IConfiguration configuration, INullinsideContext dbContext) {
_configuration = configuration;
_dbContext = dbContext;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Nullinside.Api/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class UserController : ControllerBase {
/// <summary>
/// The nullinside database.
/// </summary>
private readonly NullinsideContext _dbContext;
private readonly INullinsideContext _dbContext;

/// <summary>
/// The logger.
Expand All @@ -42,7 +42,7 @@ public class UserController : ControllerBase {
/// </summary>
/// <param name="configuration">The application's configuration file.</param>
/// <param name="dbContext">The nullinside database.</param>
public UserController(IConfiguration configuration, NullinsideContext dbContext) {
public UserController(IConfiguration configuration, INullinsideContext dbContext) {
_configuration = configuration;
_dbContext = dbContext;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
string? server = Environment.GetEnvironmentVariable("MYSQL_SERVER");
string? username = Environment.GetEnvironmentVariable("MYSQL_USERNAME");
string? password = Environment.GetEnvironmentVariable("MYSQL_PASSWORD");
builder.Services.AddDbContext<NullinsideContext>(optionsBuilder =>
builder.Services.AddDbContext<INullinsideContext, NullinsideContext>(optionsBuilder =>
optionsBuilder.UseMySQL(
$"server={server};database=nullinside;user={username};password={password};AllowUserVariables=true;",
builder => {
Expand Down
Loading