Update `User
` Model For Currency System
Refactor ``DataContext`` REQUIRES DB UPDATE
This commit is contained in:
parent
7a2f04dee9
commit
eb0b957020
@ -1,4 +1,7 @@
|
|||||||
namespace qtc_api.Data
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace qtc_api.Data
|
||||||
{
|
{
|
||||||
public class DataContext : DbContext
|
public class DataContext : DbContext
|
||||||
{
|
{
|
||||||
@ -11,6 +14,26 @@
|
|||||||
public DbSet<RefreshToken> ValidRefreshTokens { get; set; }
|
public DbSet<RefreshToken> ValidRefreshTokens { get; set; }
|
||||||
public DbSet<Contact> Contacts { get; set; }
|
public DbSet<Contact> Contacts { get; set; }
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
{
|
||||||
|
var dbProvider = Environment.GetEnvironmentVariable("DB_PROVIDER");
|
||||||
|
var connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING");
|
||||||
|
|
||||||
|
if (dbProvider != null && connectionString != null)
|
||||||
|
{
|
||||||
|
switch (dbProvider)
|
||||||
|
{
|
||||||
|
case "MySQL":
|
||||||
|
options.UseMySQL(connectionString);
|
||||||
|
break;
|
||||||
|
case "SQLite":
|
||||||
|
options.UseSqlite(connectionString);
|
||||||
|
break;
|
||||||
|
default: throw new Exception("Unsupported Database Provider. Please Check 'DB_PROVIDER' Environment Variable.");
|
||||||
|
}
|
||||||
|
} else throw new Exception("Cannot Find Environment Variables 'DB_PROVIDER' And 'DB_CONNECTION_STRING'. Please Check Environment.");
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder builder)
|
protected override void OnModelCreating(ModelBuilder builder)
|
||||||
{
|
{
|
||||||
// Users
|
// Users
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
public DateTime DateOfBirth { get; set; }
|
public DateTime DateOfBirth { get; set; }
|
||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; }
|
||||||
public int Status { get; set; } = 0;
|
public int Status { get; set; } = 0;
|
||||||
|
public int CurrencyAmount { get; set; } = 0;
|
||||||
|
public DateTime LastCurrencySpin { get; set; }
|
||||||
|
|
||||||
public virtual IEnumerable<RefreshToken>? RefreshTokens { get; }
|
public virtual IEnumerable<RefreshToken>? RefreshTokens { get; }
|
||||||
public virtual IEnumerable<Contact>? ContactsMade { get; }
|
public virtual IEnumerable<Contact>? ContactsMade { get; }
|
||||||
|
@ -20,29 +20,6 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddDbContext<DataContext>(options =>
|
|
||||||
{
|
|
||||||
if(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING")) && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DB_PROVIDER")))
|
|
||||||
{
|
|
||||||
switch(Environment.GetEnvironmentVariable("DB_PROVIDER"))
|
|
||||||
{
|
|
||||||
case "MySQL":
|
|
||||||
options.UseMySQL(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING")!);
|
|
||||||
break;
|
|
||||||
case "SQLite":
|
|
||||||
options.UseSqlite(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING")!);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (builder.Environment.IsProduction()) options.UseMySQL(builder.Configuration.GetConnectionString("DefaultConnection")!);
|
|
||||||
else options.UseSqlite(builder.Configuration.GetConnectionString("DevelopmentConnection"));
|
|
||||||
|
|
||||||
// ignore pending model changes warning
|
|
||||||
options.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning));
|
|
||||||
});
|
|
||||||
builder.Services.AddSignalR();
|
builder.Services.AddSignalR();
|
||||||
|
|
||||||
builder.Services.AddAuthentication().AddJwtBearer(options =>
|
builder.Services.AddAuthentication().AddJwtBearer(options =>
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
{
|
{
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Key": "bgpLLhY2L2UeZN3sj6WwSzScFmY3JgWfs33ZEJNcaPzC2TEnfZz",
|
|
||||||
"Issuer": "http://localhost",
|
"Issuer": "http://localhost",
|
||||||
"Audience": "http://localhost",
|
"Audience": "http://localhost",
|
||||||
"DefaultUserRole": "User"
|
"DefaultUserRole": "User"
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
|
||||||
"DevelopmentConnection": "Data Source=qtcdev.db"
|
|
||||||
},
|
|
||||||
"GeneralConfig": {
|
"GeneralConfig": {
|
||||||
"CDNPath": "./user-content"
|
"CDNPath": "./user-content"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user