From 22e5115f3bd29ea0baac00c71f210eccbea63463 Mon Sep 17 00:00:00 2001 From: hydrant Date: Sun, 8 Mar 2020 20:12:37 +0100 Subject: [PATCH] Extend data service --- .../Controllers/UserController.cs | 13 ++++++++-- ReallifeGamemode.DataService/Program.cs | 8 ++----- ReallifeGamemode.DataService/Startup.cs | 2 ++ .../Types/GetUserDataResponse.cs | 24 +++++++++++++++++++ .../ReallifeGamemode.Server.Log.csproj | 2 +- .../ReallifeGamemode.Server.Types.csproj | 2 +- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/ReallifeGamemode.DataService/Controllers/UserController.cs b/ReallifeGamemode.DataService/Controllers/UserController.cs index f06d2696..4197d3a9 100644 --- a/ReallifeGamemode.DataService/Controllers/UserController.cs +++ b/ReallifeGamemode.DataService/Controllers/UserController.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; using ReallifeGamemode.DataService.Types; @@ -31,7 +32,7 @@ namespace ReallifeGamemode.DataService.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult Data() { - User user = dbContext.Users.Where(u => u.Id == UserId).FirstOrDefault(); + User user = dbContext.Users.Include(u => u.Faction).Include(u => u.FactionRank).Where(u => u.Id == UserId).FirstOrDefault(); if (user == null) { @@ -42,7 +43,15 @@ namespace ReallifeGamemode.DataService.Controllers { Name = user.Name, AdminLevel = user.AdminLevel, - RegistrationDate = user.RegistrationDate + RegistrationDate = user.RegistrationDate, + BankMoney = user.GetBankAccount().Balance, + HandMoney = user.Handmoney, + FactionName = user.Faction?.Name, + FactionRankName = user.FactionRank?.RankName, + WantedLevel = user.Wanteds, + CarDrivingLicense = user.DriverLicenseVehicle, + BikeDrivingLicense = user.DriverLicenseBike, + PlaneLicense = user.FlyingLicensePlane }; } diff --git a/ReallifeGamemode.DataService/Program.cs b/ReallifeGamemode.DataService/Program.cs index 2fb62b8a..8e5e9738 100644 --- a/ReallifeGamemode.DataService/Program.cs +++ b/ReallifeGamemode.DataService/Program.cs @@ -21,15 +21,11 @@ namespace ReallifeGamemode.DataService public static IWebHost BuildWebHost(string[] args) { return WebHost.CreateDefaultBuilder(args) - .ConfigureLogging((ctx, l) => + .ConfigureLogging((ctx, builder) => { - l.AddLog4Net(Path.Combine(ctx.HostingEnvironment.ContentRootPath, "log4net.config")); + builder.AddLog4Net(Path.Combine(ctx.HostingEnvironment.ContentRootPath, "log4net.config")); }) .UseStartup() - .UseKestrel(k => - { - k.Listen(IPAddress.Any, 5000); - }) .Build(); } } diff --git a/ReallifeGamemode.DataService/Startup.cs b/ReallifeGamemode.DataService/Startup.cs index 27b9ffba..06830c90 100644 --- a/ReallifeGamemode.DataService/Startup.cs +++ b/ReallifeGamemode.DataService/Startup.cs @@ -132,6 +132,8 @@ namespace ReallifeGamemode.DataService app.UseDeveloperExceptionPage(); } + app.UseRouting(); + app.UseAuthentication(); app.UseStaticFiles(); diff --git a/ReallifeGamemode.DataService/Types/GetUserDataResponse.cs b/ReallifeGamemode.DataService/Types/GetUserDataResponse.cs index 1e37aff3..de951ab9 100644 --- a/ReallifeGamemode.DataService/Types/GetUserDataResponse.cs +++ b/ReallifeGamemode.DataService/Types/GetUserDataResponse.cs @@ -13,5 +13,29 @@ namespace ReallifeGamemode.DataService.Types public AdminLevel AdminLevel { get; set; } public DateTime RegistrationDate { get; set; } + + public int RegisteredSince => (int)(DateTime.Now - RegistrationDate).TotalDays; + + public int HandMoney { get; set; } + + public int BankMoney { get; set; } + + public string FactionName { get; set; } + + public string FactionRankName { get; set; } + + public string Job { get; set; } + + public int WantedLevel { get; set; } + + public bool CarDrivingLicense { get; set; } + + public bool BikeDrivingLicense { get; set; } + + public bool BoatLicense { get; set; } + + public bool HelicopterLicense { get; set; } + + public bool PlaneLicense { get; set; } } } diff --git a/ReallifeGamemode.Server.Log/ReallifeGamemode.Server.Log.csproj b/ReallifeGamemode.Server.Log/ReallifeGamemode.Server.Log.csproj index c10fcea9..392a6be8 100644 --- a/ReallifeGamemode.Server.Log/ReallifeGamemode.Server.Log.csproj +++ b/ReallifeGamemode.Server.Log/ReallifeGamemode.Server.Log.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.1 diff --git a/ReallifeGamemode.Server.Types/ReallifeGamemode.Server.Types.csproj b/ReallifeGamemode.Server.Types/ReallifeGamemode.Server.Types.csproj index 9f5c4f4a..d4c395e8 100644 --- a/ReallifeGamemode.Server.Types/ReallifeGamemode.Server.Types.csproj +++ b/ReallifeGamemode.Server.Types/ReallifeGamemode.Server.Types.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.1