Test controller, appsettings, additional field for user

This commit is contained in:
2021-10-13 13:32:40 -04:00
parent f075a09b72
commit de1f4c9b71
6 changed files with 40 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using WebAPI.Data;
namespace WebAPI.Controllers namespace WebAPI.Controllers
{ {
@@ -15,7 +16,7 @@ namespace WebAPI.Controllers
public async Task<string> HelloWorld() public async Task<string> HelloWorld()
{ {
await Task.Delay(5000); await Task.Delay(5000);
return "Hello world!"; return AppSettings.PterodactylAPIKey;
} }
} }
} }

View File

@@ -0,0 +1,29 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebAPI.Data
{
public static class AppSettings
{
public static string PterodactylAPIKey { get; private set; }
public static void Init(IConfiguration configuration)
{
var fields = typeof(AppSettings).GetProperties();
foreach (var propertyInfo in fields)
{
if (propertyInfo.PropertyType == typeof(string))
{
propertyInfo.SetValue(null, configuration.GetValue<string>(propertyInfo.Name));
}
else if (propertyInfo.PropertyType == typeof(int))
{
propertyInfo.SetValue(null, configuration.GetValue<int>(propertyInfo.Name));
}
else if (propertyInfo.PropertyType == typeof(double))
{
propertyInfo.SetValue(null, configuration.GetValue<double>(propertyInfo.Name));
}
}
}
}
}

View File

@@ -3,5 +3,6 @@ namespace WebAPI.Data.Models
public class User : BaseEntity public class User : BaseEntity
{ {
public int? PterodactylUserId { get; set; } public int? PterodactylUserId { get; set; }
public int? ExternalAuthIdentifier { get; set; }
} }
} }

View File

@@ -21,6 +21,7 @@ namespace WebAPI
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration)
{ {
Configuration = configuration; Configuration = configuration;
AppSettings.Init(configuration);
} }
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
@@ -29,7 +30,7 @@ namespace WebAPI
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddControllers(); services.AddControllers();
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo {Title = "WebAPI", Version = "v1"}); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo {Title = "Petrie Panel Web API", Version = "v1"}); });
services.AddDbContext<AppDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"))); services.AddDbContext<AppDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
} }

View File

@@ -1,4 +1,7 @@
{ {
"ConnectionStrings": {
"DefaultConnection": "Host=my_host;Database=my_db;Username=my_user;Password=my_pw"
},
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",

View File

@@ -1,6 +1,6 @@
{ {
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "" "DefaultConnection": "Host=my_host;Database=my_db;Username=my_user;Password=my_pw"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
@@ -9,5 +9,6 @@
"Microsoft.Hosting.Lifetime": "Information" "Microsoft.Hosting.Lifetime": "Information"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"PterodactylAPIKey": "REPLACE_ME"
} }