Test controller, appsettings, additional field for user
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
29
WebAPI/Data/AppSettings.cs
Normal file
29
WebAPI/Data/AppSettings.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user