diff --git a/ReallifeGamemode.DataService/Controllers/UserController.cs b/ReallifeGamemode.DataService/Controllers/UserController.cs index b0b7108a..04cfdedc 100644 --- a/ReallifeGamemode.DataService/Controllers/UserController.cs +++ b/ReallifeGamemode.DataService/Controllers/UserController.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; @@ -25,6 +27,8 @@ namespace ReallifeGamemode.DataService.Controllers } [HttpGet("Data")] + [ProducesResponseType(typeof(GetUserDataResponse), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult Data() { User user = dbContext.Users.Where(u => u.Id == UserId).FirstOrDefault(); diff --git a/ReallifeGamemode.DataService/Program.cs b/ReallifeGamemode.DataService/Program.cs index 92e1077b..2fb62b8a 100644 --- a/ReallifeGamemode.DataService/Program.cs +++ b/ReallifeGamemode.DataService/Program.cs @@ -18,13 +18,19 @@ namespace ReallifeGamemode.DataService BuildWebHost(args).Run(); } - public static IWebHost BuildWebHost(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup() - .UseKestrel(k => - { - k.Listen(IPAddress.Any, 5000); - }) - .Build(); + public static IWebHost BuildWebHost(string[] args) + { + return WebHost.CreateDefaultBuilder(args) + .ConfigureLogging((ctx, l) => + { + l.AddLog4Net(Path.Combine(ctx.HostingEnvironment.ContentRootPath, "log4net.config")); + }) + .UseStartup() + .UseKestrel(k => + { + k.Listen(IPAddress.Any, 5000); + }) + .Build(); + } } } diff --git a/ReallifeGamemode.DataService/ReallifeGamemode.DataService.csproj b/ReallifeGamemode.DataService/ReallifeGamemode.DataService.csproj index 0d25699c..fe4e587b 100644 --- a/ReallifeGamemode.DataService/ReallifeGamemode.DataService.csproj +++ b/ReallifeGamemode.DataService/ReallifeGamemode.DataService.csproj @@ -7,22 +7,31 @@ true + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive + - + diff --git a/ReallifeGamemode.DataService/Startup.cs b/ReallifeGamemode.DataService/Startup.cs index 029a21f4..65ce4b3a 100644 --- a/ReallifeGamemode.DataService/Startup.cs +++ b/ReallifeGamemode.DataService/Startup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; using ReallifeGamemode.Database.Models; using ReallifeGamemode.DataService.Logic; using Swashbuckle.AspNetCore.Swagger; @@ -33,10 +35,7 @@ namespace ReallifeGamemode.DataService { services.Configure(cfg => Configuration.Bind(cfg)); - services.AddDbContext(db => - { - db.UseMySql(Configuration["ConnectionString"]); - }); + services.AddDbContext(); services.AddLogic(); @@ -78,35 +77,46 @@ namespace ReallifeGamemode.DataService services.AddSwaggerGen(c => { - Info info = new Info + OpenApiInfo info = new OpenApiInfo { Title = "GTA:V ControlPanl DataService", Version = "0.1", }; - if(debugToken != null) + if (debugToken != null) { info.Description = $"Debug-Token: {debugToken}"; } c.SwaggerDoc("DataService", info); - c.AddSecurityDefinition("Bearer", new ApiKeyScheme + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Name = "Authorization", - In = "Header", - Type = "apiKey" + In = ParameterLocation.Header, + Type = SecuritySchemeType.ApiKey, + Scheme = "Bearer" }); - c.AddSecurityRequirement(new Dictionary>() + c.AddSecurityRequirement(new OpenApiSecurityRequirement() { - { "Bearer", new string[] { } } + { + new OpenApiSecurityScheme() + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + new string[] {} + } }); }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseAuthentication(); diff --git a/ReallifeGamemode.DataService/log4net.config b/ReallifeGamemode.DataService/log4net.config new file mode 100644 index 00000000..99019952 --- /dev/null +++ b/ReallifeGamemode.DataService/log4net.config @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file