diff --git a/Api/Api.csproj b/Api/Api.csproj
index e92b9c7..fdb1a36 100644
--- a/Api/Api.csproj
+++ b/Api/Api.csproj
@@ -7,11 +7,29 @@
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
-
+
+
+
+
+ false
+
+
+
diff --git a/Api/Program.cs b/Api/Program.cs
index 04e6c05..147cee7 100644
--- a/Api/Program.cs
+++ b/Api/Program.cs
@@ -1,22 +1,70 @@
-var builder = WebApplication.CreateBuilder(args);
+// Configure Serilog logger
-// Add services to the container.
+using Api.Configurations;
+using Application;
+using Database;
+using HealthChecks.UI.Client;
+using Microsoft.AspNetCore.Diagnostics.HealthChecks;
+using Serilog;
-builder.Services.AddControllers();
-// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
-builder.Services.AddEndpointsApiExplorer();
-builder.Services.AddSwaggerGen();
+Log.Logger = new LoggerConfiguration()
+ .WriteTo.Console()
+ .CreateBootstrapLogger();
-var app = builder.Build();
+try
+{
+ Log.Information("Starting API . . . ");
+ var builder = WebApplication.CreateBuilder(args);
+
+ builder.Services.AddSerilog(options =>
+ {
+ options.ReadFrom.Configuration(builder.Configuration);
+ });
+
+ builder.Services.AddDatabase(builder.Configuration);
+ builder.Services.AddApplication();
+
+ builder.Services.AddControllers();
+ builder.Services.AddEndpointsApiExplorer();
+
+ builder.Services.ConfigureAndApiVersioning();
+ builder.Services.ConfigureAndAddSwagger();
+ builder.Services.ConfigureAndAddCors();
+ builder.Services.ConfigureAndAddHealthChecks(builder.Configuration);
+
+ var jwtSection = builder.Configuration.GetRequiredSection("Jwt");
+ builder.Services.ConfigureAndAddAuthentication(jwtSection);
+
+ var app = builder.Build();
-app.UseSwagger();
-app.UseSwaggerUI();
+ app.UseSwagger();
+ app.UseSwaggerUI();
-app.UseHttpsRedirection();
+ app.UseCors("AllowAll");
-app.UseAuthorization();
+ app.UseSerilogRequestLogging();
-app.MapControllers();
+ app.UseHttpsRedirection();
+
+ app.UseAuthentication();
+ app.UseAuthorization();
+
+ app.MapControllers();
+
+ app.MapHealthChecks("/health", new HealthCheckOptions()
+ {
+ ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
+ });
+
+ app.Run();
+}
+catch (Exception e)
+{
+ Log.Fatal(e, e.Message);
+}
+finally
+{
+ Log.CloseAndFlush();
+}
-app.Run();
diff --git a/Database/Configurations/PlayerConfiguration.cs b/Database/Configurations/PlayerConfiguration.cs
index 8b7664b..ba9f072 100644
--- a/Database/Configurations/PlayerConfiguration.cs
+++ b/Database/Configurations/PlayerConfiguration.cs
@@ -14,8 +14,8 @@ public class PlayerConfiguration : IEntityTypeConfiguration
builder.Property(player => player.Level).IsRequired().HasMaxLength(3);
builder.HasOne(player => player.Rank)
- .WithOne(rank => rank.Player)
- .HasForeignKey(rank => rank.PlayerId)
+ .WithMany(rank => rank.Players)
+ .HasForeignKey(player => player.RankId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasMany(player => player.VsDuels)
diff --git a/Database/Configurations/RankConfiguration.cs b/Database/Configurations/RankConfiguration.cs
index 9529dc9..90a50c2 100644
--- a/Database/Configurations/RankConfiguration.cs
+++ b/Database/Configurations/RankConfiguration.cs
@@ -16,33 +16,28 @@ public class RankConfiguration : IEntityTypeConfiguration
{
new()
{
- Id = new Guid(""),
- Name = "R5",
- Player = null!
+ Id = new Guid("b1c10a1c-5cf3-4e22-9fc1-d9b165b85dd3"),
+ Name = "R5"
},
new()
{
- Id = new Guid(""),
- Name = "R4",
- Player = null!
+ Id = new Guid("0fc2f68a-0a4d-4922-981e-c624e4c39024"),
+ Name = "R4"
},
new()
{
- Id = new Guid(""),
- Name = "R3",
- Player = null!
+ Id = new Guid("4970e1f5-f7f5-43e8-88cc-7f8fc4075418"),
+ Name = "R3"
},
new()
{
- Id = new Guid(""),
- Name = "R2",
- Player = null!
+ Id = new Guid("d8d0c587-f269-45ff-b13e-4631298bf0af"),
+ Name = "R2"
},
new()
{
- Id = new Guid(""),
- Name = "R1",
- Player = null!
+ Id = new Guid("326edef0-5074-43a5-9db9-edc71221a0f7"),
+ Name = "R1"
}
};
diff --git a/Database/Configurations/RoleConfiguration.cs b/Database/Configurations/RoleConfiguration.cs
index ce0dba8..3726218 100644
--- a/Database/Configurations/RoleConfiguration.cs
+++ b/Database/Configurations/RoleConfiguration.cs
@@ -13,25 +13,25 @@ public class RoleConfiguration : IEntityTypeConfiguration>
{
new()
{
- Id = new Guid(""),
+ Id = new Guid("d8b9f882-95f0-4ba0-80ed-9c22c27ac88a"),
NormalizedName = ApplicationRoles.SystemAdministrator.ToUpper(),
Name = ApplicationRoles.SystemAdministrator
},
new()
{
- Id = new Guid(""),
+ Id = new Guid("47de05ba-ff1e-46b6-9995-269084006c24"),
NormalizedName = ApplicationRoles.Administrator.ToUpper(),
Name = ApplicationRoles.Administrator
},
new()
{
- Id = new Guid(""),
+ Id = new Guid("5cc27946-5601-4a25-b9a9-75b8a11c0cf4"),
NormalizedName = ApplicationRoles.User.ToUpper(),
Name = ApplicationRoles.User
},
new()
{
- Id = new Guid(""),
+ Id = new Guid("207bb0a3-ad50-49bb-bc41-b266fce66529"),
NormalizedName = ApplicationRoles.ReadOnly.ToUpper(),
Name = ApplicationRoles.ReadOnly
}
diff --git a/Database/Configurations/UserConfiguration.cs b/Database/Configurations/UserConfiguration.cs
index 0aec250..4f4de37 100644
--- a/Database/Configurations/UserConfiguration.cs
+++ b/Database/Configurations/UserConfiguration.cs
@@ -11,8 +11,8 @@ public class UserConfiguration : IEntityTypeConfiguration
builder.Property(user => user.PlayerName).IsRequired().HasMaxLength(200);
builder.HasOne(user => user.Alliance)
- .WithOne(alliance => alliance.User)
- .HasForeignKey(alliance => alliance.UserId)
+ .WithMany(alliance => alliance.Users)
+ .HasForeignKey(user => user.AllianceId)
.OnDelete(DeleteBehavior.NoAction);
}
}
\ No newline at end of file
diff --git a/Database/Database.csproj b/Database/Database.csproj
index fabce66..a688b5a 100644
--- a/Database/Database.csproj
+++ b/Database/Database.csproj
@@ -7,10 +7,15 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/Database/DatabaseDependencyInjection.cs b/Database/DatabaseDependencyInjection.cs
index 912a699..1389d12 100644
--- a/Database/DatabaseDependencyInjection.cs
+++ b/Database/DatabaseDependencyInjection.cs
@@ -1,4 +1,5 @@
-using Database.Entities;
+using System.Reflection;
+using Database.Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@@ -10,6 +11,8 @@ public static class DatabaseDependencyInjection
{
public static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
{
+ services.AddDataProtection();
+
services.AddDbContext(options =>
{
options.UseSqlServer(configuration.GetConnectionString("ApplicationDbConnection"));
@@ -35,7 +38,6 @@ public static class DatabaseDependencyInjection
options.TokenLifespan = TimeSpan.FromHours(2);
});
-
return services;
}
}
\ No newline at end of file
diff --git a/Database/Entities/Alliance.cs b/Database/Entities/Alliance.cs
index ff39083..fae0ed4 100644
--- a/Database/Entities/Alliance.cs
+++ b/Database/Entities/Alliance.cs
@@ -8,9 +8,7 @@ public class Alliance : BaseEntity
public required string Abbreviation { get; set; }
- public User User { get; set; }
+ public ICollection Players { get; set; } = [];
- public Guid UserId { get; set; }
-
- public ICollection Players { get; set; }
+ public ICollection Users { get; set; } = [];
}
\ No newline at end of file
diff --git a/Database/Entities/Player.cs b/Database/Entities/Player.cs
index 4fa1cf3..7f111c4 100644
--- a/Database/Entities/Player.cs
+++ b/Database/Entities/Player.cs
@@ -6,8 +6,12 @@ public class Player : BaseEntity
public required Rank Rank { get; set; }
+ public Guid RankId { get; set; }
+
public Alliance Alliance { get; set; }
+ public Guid AllianceId { get; set; }
+
public required string Level { get; set; }
public ICollection DesertStorms { get; set; } = [];
diff --git a/Database/Entities/Rank.cs b/Database/Entities/Rank.cs
index ec86b4a..84df995 100644
--- a/Database/Entities/Rank.cs
+++ b/Database/Entities/Rank.cs
@@ -4,7 +4,5 @@ public class Rank : BaseEntity
{
public required string Name { get; set; }
- public Guid PlayerId { get; set; }
-
- public required Player Player { get; set; }
+ public ICollection Players { get; set; } = [];
}
\ No newline at end of file
diff --git a/Database/Entities/User.cs b/Database/Entities/User.cs
index 44078dc..42c3163 100644
--- a/Database/Entities/User.cs
+++ b/Database/Entities/User.cs
@@ -6,5 +6,7 @@ public class User : IdentityUser
{
public required Alliance Alliance { get; set; }
+ public Guid AllianceId { get; set; }
+
public required string PlayerName { get; set; }
}
\ No newline at end of file
diff --git a/PlayerManagement.sln b/PlayerManagement.sln
index a16ca63..ac6ba05 100644
--- a/PlayerManagement.sln
+++ b/PlayerManagement.sln
@@ -3,11 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35122.118
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Database", "Database\Database.csproj", "{93C305BF-7225-492E-9FBA-D2DD9B0698DF}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Database", "Database\Database.csproj", "{93C305BF-7225-492E-9FBA-D2DD9B0698DF}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utilities", "Utilities\Utilities.csproj", "{FA8FEE7C-58A5-458F-A7D5-509D9364159B}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utilities", "Utilities\Utilities.csproj", "{FA8FEE7C-58A5-458F-A7D5-509D9364159B}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "Api\Api.csproj", "{B3CFE8A6-2BA3-4CB2-893F-3F2B0FABB08F}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api", "Api\Api.csproj", "{B3CFE8A6-2BA3-4CB2-893F-3F2B0FABB08F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\Application.csproj", "{BFE66A98-A2BC-4B8C-803E-610705855E7A}"
+EndProject
+Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "Ui", "Ui\Ui.esproj", "{77168004-AF1E-4F51-A096-E8E8BF18A37A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -27,6 +31,16 @@ Global
{B3CFE8A6-2BA3-4CB2-893F-3F2B0FABB08F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3CFE8A6-2BA3-4CB2-893F-3F2B0FABB08F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3CFE8A6-2BA3-4CB2-893F-3F2B0FABB08F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BFE66A98-A2BC-4B8C-803E-610705855E7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BFE66A98-A2BC-4B8C-803E-610705855E7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BFE66A98-A2BC-4B8C-803E-610705855E7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BFE66A98-A2BC-4B8C-803E-610705855E7A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {77168004-AF1E-4F51-A096-E8E8BF18A37A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {77168004-AF1E-4F51-A096-E8E8BF18A37A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {77168004-AF1E-4F51-A096-E8E8BF18A37A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {77168004-AF1E-4F51-A096-E8E8BF18A37A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {77168004-AF1E-4F51-A096-E8E8BF18A37A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {77168004-AF1E-4F51-A096-E8E8BF18A37A}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE