diff --git a/BellumGens.Api.Core/Controllers/AccountController.cs b/BellumGens.Api.Core/Controllers/AccountController.cs index e113090..f69132e 100644 --- a/BellumGens.Api.Core/Controllers/AccountController.cs +++ b/BellumGens.Api.Core/Controllers/AccountController.cs @@ -472,15 +472,17 @@ private async Task Register(ExternalLoginInfo info) }; break; case "Steam": + var steamId = _steamService.SteamUserId(providerId); user = new ApplicationUser() { Id = Guid.NewGuid().ToString(), UserName = username, Email = email, EmailConfirmed = true, + SteamID = steamId, CSGODetails = new CSGODetails() { - SteamId = _steamService.SteamUserId(providerId) + SteamId = steamId } }; break; @@ -531,6 +533,7 @@ private async Task AddLogin(string userId, ExternalLoginInfo inf string steamid = _steamService.SteamUserId(providerId); if (user.SteamID != steamid) { + user.SteamID = steamid; user.CSGODetails.SteamId = steamid; await _dbContext.SaveChangesAsync(); } @@ -539,6 +542,7 @@ private async Task AddLogin(string userId, ExternalLoginInfo inf var battletag = info.Principal.FindFirstValue(ClaimTypes.Name); if (user.BattleNetId != providerId) { + user.BattleNetId = providerId; user.StarCraft2Details = new StarCraft2Details() { BattleNetBattleTag = battletag, diff --git a/BellumGens.Api.Core/Controllers/TournamentController.cs b/BellumGens.Api.Core/Controllers/TournamentController.cs index a533b2a..af2fe64 100644 --- a/BellumGens.Api.Core/Controllers/TournamentController.cs +++ b/BellumGens.Api.Core/Controllers/TournamentController.cs @@ -485,158 +485,125 @@ await _dbContext.TournamentSC2Groups.Where(g => g.Tournament.Active) [HttpPut] [Route("csgogroup")] + [Authorize(Roles = "admin, event-admin")] public async Task SubmitCSGOGroup(Guid? id, TournamentCSGOGroup group) { - if (await UserIsInRole("event-admin")) + TournamentCSGOGroup entity = await _dbContext.TournamentCSGOGroups.FindAsync(id); + if (entity != null) { - TournamentCSGOGroup entity = await _dbContext.TournamentCSGOGroups.FindAsync(id); - if (entity != null) - { - _dbContext.Entry(entity).CurrentValues.SetValues(group); - } - else - { - group.TournamentId = (await _dbContext.Tournaments.FirstOrDefaultAsync(t => t.Active)).ID; - _dbContext.TournamentCSGOGroups.Add(group); - } + _dbContext.Entry(entity).CurrentValues.SetValues(group); + } + else + { + group.TournamentId = (await _dbContext.Tournaments.FirstOrDefaultAsync(t => t.Active)).ID; + _dbContext.TournamentCSGOGroups.Add(group); + } - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament group update exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(group); + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament group update exception: " + e.Message); + return BadRequest("Something went wrong..."); } - return Unauthorized(); + return Ok(group); } [HttpPut] [Route("sc2group")] + [Authorize(Roles = "admin, event-admin")] public async Task SubmitSC2Group(Guid? id, TournamentSC2Group group) { - if (await UserIsInRole("event-admin")) + TournamentSC2Group entity = await _dbContext.TournamentSC2Groups.FindAsync(id); + if (entity != null) { - TournamentSC2Group entity = await _dbContext.TournamentSC2Groups.FindAsync(id); - if (entity != null) - { - _dbContext.Entry(entity).CurrentValues.SetValues(group); - } - else + _dbContext.Entry(entity).CurrentValues.SetValues(group); + } + else + { + group.TournamentId = (await _dbContext.Tournaments.FirstOrDefaultAsync(t => t.Active)).ID; + _dbContext.TournamentSC2Groups.Add(group); + } + + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament group update exception: " + e.Message); + return BadRequest("Something went wrong..."); + } + return Ok(group); + } + + [HttpDelete] + [Route("group")] + [Authorize(Roles = "admin, event-admin")] + public async Task DeleteGroup(Guid id) + { + TournamentGroup entity = await _dbContext.TournamentCSGOGroups.FindAsync(id); + if (entity != null) + { + foreach (var par in entity.Participants) { - group.TournamentId = (await _dbContext.Tournaments.FirstOrDefaultAsync(t => t.Active)).ID; - _dbContext.TournamentSC2Groups.Add(group); + par.TournamentCSGOGroupId = null; } - + _dbContext.TournamentCSGOGroups.Remove(entity as TournamentCSGOGroup); try { await _dbContext.SaveChangesAsync(); } catch (DbUpdateException e) { - System.Diagnostics.Trace.TraceError("Tournament group update exception: " + e.Message); + System.Diagnostics.Trace.TraceError("Tournament group delete exception: " + e.Message); return BadRequest("Something went wrong..."); } - return Ok(group); + return Ok(); } - return Unauthorized(); - } - - [HttpDelete] - [Route("group")] - public async Task DeleteGroup(Guid id) - { - TournamentGroup entity; - if (await UserIsInRole("event-admin")) + entity = await _dbContext.TournamentSC2Groups.FindAsync(id); + if (entity != null) { - entity = await _dbContext.TournamentCSGOGroups.FindAsync(id); - if (entity != null) + foreach (var par in entity.Participants) { - foreach (var par in entity.Participants) - { - par.TournamentCSGOGroupId = null; - } - _dbContext.TournamentCSGOGroups.Remove(entity as TournamentCSGOGroup); - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament group delete exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(); + par.TournamentSC2GroupId = null; } - entity = await _dbContext.TournamentSC2Groups.FindAsync(id); - if (entity != null) + _dbContext.TournamentSC2Groups.Remove(entity as TournamentSC2Group); + try { - foreach (var par in entity.Participants) - { - par.TournamentSC2GroupId = null; - } - _dbContext.TournamentSC2Groups.Remove(entity as TournamentSC2Group); - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament group delete exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(); + await _dbContext.SaveChangesAsync(); } - return NotFound(); + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament group delete exception: " + e.Message); + return BadRequest("Something went wrong..."); + } + return Ok(); } - return Unauthorized(); + return NotFound(); } [HttpPut] [Route("participanttogroup")] + [Authorize(Roles = "admin, event-admin")] + public async Task AddToGroup(Guid id, TournamentApplication participant) { - TournamentGroup entity; - if (await UserIsInRole("event-admin")) + TournamentGroup entity = await _dbContext.TournamentCSGOGroups.FindAsync(id); + if (entity == null) { - entity = await _dbContext.TournamentCSGOGroups.FindAsync(id); - if (entity == null) - { - entity = await _dbContext.TournamentSC2Groups.FindAsync(id); - if (entity != null) - { - TournamentApplication app = await _dbContext.TournamentApplications.FindAsync(participant.Id); - if (app == null) - { - return NotFound(); - } - - app.TournamentSC2GroupId = id; - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament group participant add exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(); - } - return NotFound(); - } - else + entity = await _dbContext.TournamentSC2Groups.FindAsync(id); + if (entity != null) { TournamentApplication app = await _dbContext.TournamentApplications.FindAsync(participant.Id); if (app == null) { - return NotFound(); + return NotFound(); } - app.TournamentCSGOGroupId = id; + app.TournamentSC2GroupId = id; try { await _dbContext.SaveChangesAsync(); @@ -648,35 +615,52 @@ public async Task AddToGroup(Guid id, TournamentApplication parti } return Ok(); } + return NotFound(); + } + else + { + TournamentApplication app = await _dbContext.TournamentApplications.FindAsync(participant.Id); + if (app == null) + { + return NotFound(); + } + + app.TournamentCSGOGroupId = id; + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament group participant add exception: " + e.Message); + return BadRequest("Something went wrong..."); + } + return Ok(); } - return Unauthorized(); } [HttpDelete] [Route("participanttogroup")] + [Authorize(Roles = "admin, event-admin")] public async Task RemoveFromGroup(Guid id) { - if (await UserIsInRole("event-admin")) + TournamentApplication entity = await _dbContext.TournamentApplications.FindAsync(id); + if (entity != null) { - TournamentApplication entity = await _dbContext.TournamentApplications.FindAsync(id); - if (entity != null) + entity.TournamentCSGOGroupId = null; + entity.TournamentSC2GroupId = null; + try { - entity.TournamentCSGOGroupId = null; - entity.TournamentSC2GroupId = null; - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament group participant delete exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(); + await _dbContext.SaveChangesAsync(); } - return NotFound(); + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament group participant delete exception: " + e.Message); + return BadRequest("Something went wrong..."); + } + return Ok(); } - return Unauthorized(); + return NotFound(); } #endregion @@ -725,256 +709,232 @@ public async Task GetSC2Match(Guid id) [HttpPut] [Route("csgomatch")] + [Authorize(Roles = "admin, event-admin")] public async Task SubmitCSGOMatch(Guid? id, TournamentCSGOMatch match) { - if (await UserIsInRole("event-admin")) + foreach (CSGOMatchMap map in match.Maps) { - foreach (CSGOMatchMap map in match.Maps) + CSGOMatchMap mapEntity = await _dbContext.CSGOMatchMaps.FindAsync(map.Id); + if (mapEntity != null) { - CSGOMatchMap mapEntity = await _dbContext.CSGOMatchMaps.FindAsync(map.Id); - if (mapEntity != null) - { - _dbContext.Entry(mapEntity).CurrentValues.SetValues(map); - } - else - { - _dbContext.CSGOMatchMaps.Add(map); - } - } - - TournamentCSGOMatch entity = await _dbContext.TournamentCSGOMatches.FindAsync(id); - - if (entity != null) - { - _dbContext.Entry(entity).CurrentValues.SetValues(match); - match = entity; + _dbContext.Entry(mapEntity).CurrentValues.SetValues(map); } else { - _dbContext.TournamentCSGOMatches.Add(match); + _dbContext.CSGOMatchMaps.Add(map); } + } - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament CS:GO match update exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - if (entity == null) - { - await _dbContext.Entry(match).Reference(m => m.Team1).LoadAsync(); - await _dbContext.Entry(match).Reference(m => m.Team2).LoadAsync(); - } + TournamentCSGOMatch entity = await _dbContext.TournamentCSGOMatches.FindAsync(id); - return Ok(match); + if (entity != null) + { + _dbContext.Entry(entity).CurrentValues.SetValues(match); + match = entity; } - return Unauthorized(); + else + { + _dbContext.TournamentCSGOMatches.Add(match); + } + + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament CS:GO match update exception: " + e.Message); + return BadRequest("Something went wrong..."); + } + if (entity == null) + { + await _dbContext.Entry(match).Reference(m => m.Team1).LoadAsync(); + await _dbContext.Entry(match).Reference(m => m.Team2).LoadAsync(); + } + + return Ok(match); } [HttpDelete] [Route("csgomatch")] + [Authorize(Roles = "admin, event-admin")] public async Task DeleteCSGOMatch(Guid? id) { - if (await UserIsInRole("event-admin")) - { - TournamentCSGOMatch entity = await _dbContext.TournamentCSGOMatches.FindAsync(id); - _dbContext.TournamentCSGOMatches.Remove(entity); + TournamentCSGOMatch entity = await _dbContext.TournamentCSGOMatches.FindAsync(id); + _dbContext.TournamentCSGOMatches.Remove(entity); - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament CS:GO match delete exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(entity); + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament CS:GO match delete exception: " + e.Message); + return BadRequest("Something went wrong..."); } - return Unauthorized(); + return Ok(entity); } [HttpPut] [Route("csgomatchmap")] + [Authorize(Roles = "admin, event-admin")] public async Task SubmitCSGOMatchMap(Guid? id, CSGOMatchMap map) { - if (await UserIsInRole("event-admin")) + CSGOMatchMap entity = await _dbContext.CSGOMatchMaps.FindAsync(id); + if (entity != null) { - CSGOMatchMap entity = await _dbContext.CSGOMatchMaps.FindAsync(id); - if (entity != null) - { - _dbContext.Entry(entity).CurrentValues.SetValues(map); - } - else - { - _dbContext.CSGOMatchMaps.Add(map); - } + _dbContext.Entry(entity).CurrentValues.SetValues(map); + } + else + { + _dbContext.CSGOMatchMaps.Add(map); + } - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament CS:GO match map update exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(map); + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament CS:GO match map update exception: " + e.Message); + return BadRequest("Something went wrong..."); } - return Unauthorized(); + return Ok(map); } [HttpDelete] [Route("csgomatchmap")] + [Authorize(Roles = "admin, event-admin")] public async Task DeleteCSGOMatchMap(Guid? id) { - if (await UserIsInRole("event-admin")) - { - CSGOMatchMap entity = await _dbContext.CSGOMatchMaps.FindAsync(id); - _dbContext.CSGOMatchMaps.Remove(entity); + CSGOMatchMap entity = await _dbContext.CSGOMatchMaps.FindAsync(id); + _dbContext.CSGOMatchMaps.Remove(entity); - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament CS:GO match map delete exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(entity); + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament CS:GO match map delete exception: " + e.Message); + return BadRequest("Something went wrong..."); } - return Unauthorized(); + return Ok(entity); } [HttpPut] [Route("sc2match")] + [Authorize(Roles = "admin, event-admin")] public async Task SubmitSC2Match(Guid? id, TournamentSC2Match match) { - if (await UserIsInRole("event-admin")) + foreach (SC2MatchMap map in match.Maps) { - foreach (SC2MatchMap map in match.Maps) - { - SC2MatchMap mapEntity = await _dbContext.SC2MatchMaps.FindAsync(map.Id); - if (mapEntity != null) - { - _dbContext.Entry(mapEntity).CurrentValues.SetValues(map); - } - else - { - _dbContext.SC2MatchMaps.Add(map); - } - } - - TournamentSC2Match entity = await _dbContext.TournamentSC2Matches.FindAsync(id); - if (entity != null) + SC2MatchMap mapEntity = await _dbContext.SC2MatchMaps.FindAsync(map.Id); + if (mapEntity != null) { - _dbContext.Entry(entity).CurrentValues.SetValues(match); - match = entity; + _dbContext.Entry(mapEntity).CurrentValues.SetValues(map); } else { - _dbContext.TournamentSC2Matches.Add(match); + _dbContext.SC2MatchMaps.Add(map); } + } - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament StarCraft II match update exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - if (entity == null) - { - await _dbContext.Entry(match).Reference(m => m.Player1).LoadAsync(); - await _dbContext.Entry(match).Reference(m => m.Player2).LoadAsync(); - } - return Ok(match); + TournamentSC2Match entity = await _dbContext.TournamentSC2Matches.FindAsync(id); + if (entity != null) + { + _dbContext.Entry(entity).CurrentValues.SetValues(match); + match = entity; + } + else + { + _dbContext.TournamentSC2Matches.Add(match); + } + + try + { + await _dbContext.SaveChangesAsync(); } - return Unauthorized(); + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament StarCraft II match update exception: " + e.Message); + return BadRequest("Something went wrong..."); + } + if (entity == null) + { + await _dbContext.Entry(match).Reference(m => m.Player1).LoadAsync(); + await _dbContext.Entry(match).Reference(m => m.Player2).LoadAsync(); + } + return Ok(match); } [HttpDelete] [Route("sc2match")] + [Authorize(Roles = "admin, event-admin")] public async Task DeleteSC2Match(Guid? id) { - if (await UserIsInRole("event-admin")) - { - TournamentSC2Match entity = await _dbContext.TournamentSC2Matches.FindAsync(id); - _dbContext.TournamentSC2Matches.Remove(entity); + TournamentSC2Match entity = await _dbContext.TournamentSC2Matches.FindAsync(id); + _dbContext.TournamentSC2Matches.Remove(entity); - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament StarCraft II match delete exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(entity); + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament StarCraft II match delete exception: " + e.Message); + return BadRequest("Something went wrong..."); } - return Unauthorized(); + return Ok(entity); } [HttpPut] [Route("sc2matchmap")] + [Authorize(Roles = "admin, event-admin")] public async Task SubmitSC2MatchMap(Guid? id, SC2MatchMap map) { - if (await UserIsInRole("event-admin")) + SC2MatchMap entity = await _dbContext.SC2MatchMaps.FindAsync(id); + if (entity != null) { - SC2MatchMap entity = await _dbContext.SC2MatchMaps.FindAsync(id); - if (entity != null) - { - _dbContext.Entry(entity).CurrentValues.SetValues(map); - } - else - { - _dbContext.SC2MatchMaps.Add(map); - } + _dbContext.Entry(entity).CurrentValues.SetValues(map); + } + else + { + _dbContext.SC2MatchMaps.Add(map); + } - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament CS:GO match map update exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(map); + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament CS:GO match map update exception: " + e.Message); + return BadRequest("Something went wrong..."); } - return Unauthorized(); + return Ok(map); } [HttpDelete] [Route("sc2matchmap")] + [Authorize(Roles = "admin, event-admin")] public async Task DeleteSC2MatchMap(Guid? id) { - if (await UserIsInRole("event-admin")) - { - SC2MatchMap entity = await _dbContext.SC2MatchMaps.FindAsync(id); - _dbContext.SC2MatchMaps.Remove(entity); + SC2MatchMap entity = await _dbContext.SC2MatchMaps.FindAsync(id); + _dbContext.SC2MatchMaps.Remove(entity); - try - { - await _dbContext.SaveChangesAsync(); - } - catch (DbUpdateException e) - { - System.Diagnostics.Trace.TraceError("Tournament CS:GO match map delete exception: " + e.Message); - return BadRequest("Something went wrong..."); - } - return Ok(entity); + try + { + await _dbContext.SaveChangesAsync(); + } + catch (DbUpdateException e) + { + System.Diagnostics.Trace.TraceError("Tournament CS:GO match map delete exception: " + e.Message); + return BadRequest("Something went wrong..."); } - return Unauthorized(); + return Ok(entity); } #endregion } diff --git a/BellumGens.Api.Core/Controllers/UsersController.cs b/BellumGens.Api.Core/Controllers/UsersController.cs index 478d81e..1d558bb 100644 --- a/BellumGens.Api.Core/Controllers/UsersController.cs +++ b/BellumGens.Api.Core/Controllers/UsersController.cs @@ -15,9 +15,11 @@ namespace BellumGens.Api.Controllers public class UsersController : BaseController { private readonly ISteamService _steamService; + private readonly IBattleNetService _battleNetService; private readonly INotificationService _notificationService; public UsersController(ISteamService steamService, - INotificationService notificationService, + IBattleNetService battleNetService, + INotificationService notificationService, UserManager userManager, RoleManager roleManager, SignInManager signInManager, @@ -26,23 +28,39 @@ public UsersController(ISteamService steamService, ILogger logger) : base(userManager, roleManager, signInManager, sender, context, logger) { _steamService = steamService; - _notificationService = notificationService; + _battleNetService = battleNetService; + _notificationService = notificationService; } [HttpGet] [AllowAnonymous] public async Task Get(string userid) { - UserStatsViewModel user = await _steamService.GetSteamUserDetails(userid); - ApplicationUser registered = null; - if (user.SteamUser != null) + ApplicationUser registered = await _dbContext.Users.Include(u => u.CSGODetails).Include(u => u.StarCraft2Details).Include(u => u.MemberOf).ThenInclude(m => m.Team).FirstOrDefaultAsync(u => u.Id == userid); + UserStatsViewModel user = new UserStatsViewModel(); + + if (registered != null) { - registered = await _dbContext.Users.Include(u => u.CSGODetails).Include(u => u.MemberOf).ThenInclude(m => m.Team).FirstOrDefaultAsync(u => u.SteamID == user.SteamUser.steamID64); + if (registered.SteamID != null) + { + user = await _steamService.GetSteamUserDetails(registered.SteamID); + } + + if (registered.BattleNetId != null) + { + user.SC2Player = await _battleNetService.GetStarCraft2Player(registered.BattleNetId); + } + user.SetUser(registered, _dbContext); } - if (registered != null) + else { - user.SetUser(registered, _dbContext); - } + user = await _steamService.GetSteamUserDetails(userid); + registered = await _dbContext.Users.Include(u => u.CSGODetails).Include(u => u.StarCraft2Details).Include(u => u.MemberOf).ThenInclude(m => m.Team).FirstOrDefaultAsync(u => u.SteamID == user.SteamUser.steamID64); + if (registered != null) + { + user.SetUser(registered, _dbContext); + } + } return Ok(user); } diff --git a/BellumGens.Api.Core/Migrations/20241212121248_FullSC2Profile.Designer.cs b/BellumGens.Api.Core/Migrations/20241212121248_FullSC2Profile.Designer.cs new file mode 100644 index 0000000..3f6314c --- /dev/null +++ b/BellumGens.Api.Core/Migrations/20241212121248_FullSC2Profile.Designer.cs @@ -0,0 +1,1645 @@ +// +using System; +using BellumGens.Api.Core.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BellumGens.Api.Core.Migrations +{ + [DbContext(typeof(BellumGensDbContext))] + [Migration("20241212121248_FullSC2Profile")] + partial class FullSC2Profile + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BellumGens.Api.Core.Models.ApplicationUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("BattleNetId") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("ESEA") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LastSeen") + .HasColumnType("datetimeoffset"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("RegisteredOn") + .HasColumnType("datetimeoffset"); + + b.Property("SearchVisible") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("SteamID") + .HasColumnType("nvarchar(450)"); + + b.Property("TwitchId") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("BattleNetId"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.HasIndex("SteamID"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.BellumGensPushSubscription", b => + { + b.Property("P256dh") + .HasColumnType("nvarchar(450)"); + + b.Property("Auth") + .HasColumnType("nvarchar(450)"); + + b.Property("Endpoint") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpirationTime") + .HasColumnType("time"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("P256dh", "Auth"); + + b.HasIndex("UserId"); + + b.ToTable("BellumGensPushSubscriptions"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.CSGODetails", b => + { + b.Property("SteamId") + .HasColumnType("nvarchar(450)"); + + b.Property("Accuracy") + .HasPrecision(5, 2) + .HasColumnType("decimal(5,2)"); + + b.Property("AvatarFull") + .HasColumnType("nvarchar(max)"); + + b.Property("AvatarIcon") + .HasColumnType("nvarchar(max)"); + + b.Property("AvatarMedium") + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .HasColumnType("nvarchar(max)"); + + b.Property("CustomUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("HeadshotPercentage") + .HasPrecision(5, 2) + .HasColumnType("decimal(5,2)"); + + b.Property("KillDeathRatio") + .HasPrecision(4, 2) + .HasColumnType("decimal(4,2)"); + + b.Property("PreferredPrimaryRole") + .HasColumnType("int"); + + b.Property("PreferredSecondaryRole") + .HasColumnType("int"); + + b.Property("RealName") + .HasColumnType("nvarchar(max)"); + + b.Property("SteamPrivate") + .HasColumnType("bit"); + + b.HasKey("SteamId"); + + b.ToTable("CSGODetails"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.CSGOMatchMap", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CsgoMatchId") + .HasColumnType("uniqueidentifier"); + + b.Property("Map") + .HasColumnType("int"); + + b.Property("Team1Score") + .HasColumnType("int"); + + b.Property("Team2Score") + .HasColumnType("int"); + + b.Property("TeamBanId") + .HasColumnType("uniqueidentifier"); + + b.Property("TeamPickId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CsgoMatchId"); + + b.HasIndex("TeamBanId"); + + b.HasIndex("TeamPickId"); + + b.ToTable("CSGOMatchMaps"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.CSGOStrategy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CustomUrl") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("EditorMetadata") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdated") + .HasColumnType("datetimeoffset"); + + b.Property("Map") + .HasColumnType("int"); + + b.Property("PrivateShareLink") + .HasColumnType("nvarchar(max)"); + + b.Property("Side") + .HasColumnType("int"); + + b.Property("StratImage") + .HasColumnType("nvarchar(max)") + .HasColumnName("Image"); + + b.Property("TeamId") + .HasColumnType("uniqueidentifier"); + + b.Property("Title") + .HasColumnType("nvarchar(max)"); + + b.Property("Url") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("Visible") + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.HasIndex("CustomUrl") + .IsUnique() + .HasFilter("[CustomUrl] IS NOT NULL"); + + b.HasIndex("TeamId"); + + b.HasIndex("UserId"); + + b.ToTable("CSGOStrategies"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.CSGOTeam", b => + { + b.Property("TeamId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CustomUrl") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Discord") + .HasColumnType("nvarchar(max)"); + + b.Property("RegisteredOn") + .HasColumnType("datetimeoffset"); + + b.Property("SteamGroupId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("TeamAvatar") + .HasColumnType("nvarchar(max)"); + + b.Property("TeamName") + .HasColumnType("nvarchar(max)"); + + b.Property("Visible") + .HasColumnType("bit"); + + b.HasKey("TeamId"); + + b.HasIndex("CustomUrl") + .IsUnique() + .HasFilter("[CustomUrl] IS NOT NULL"); + + b.HasIndex("SteamGroupId") + .IsUnique() + .HasFilter("[SteamGroupId] IS NOT NULL"); + + b.ToTable("CSGOTeams"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.Company", b => + { + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Logo") + .HasColumnType("nvarchar(max)"); + + b.Property("Website") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Name"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.JerseyDetails", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cut") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b.Property("Size") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("JerseyDetails"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.JerseyOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("City") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Confirmed") + .HasColumnType("bit"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OrderDate") + .HasColumnType("datetimeoffset"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PromoCode") + .HasColumnType("nvarchar(450)"); + + b.Property("Shipped") + .HasColumnType("bit"); + + b.Property("StreetAddress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("PromoCode"); + + b.ToTable("JerseyOrders"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.Promo", b => + { + b.Property("Code") + .HasColumnType("nvarchar(450)"); + + b.Property("Discount") + .HasPrecision(3, 2) + .HasColumnType("decimal(3,2)"); + + b.Property("Expiration") + .HasColumnType("datetimeoffset"); + + b.HasKey("Code"); + + b.HasIndex("Code") + .IsUnique(); + + b.ToTable("PromoCodes"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.SC2MatchMap", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Map") + .HasColumnType("int"); + + b.Property("PlayerBanId") + .HasColumnType("nvarchar(450)"); + + b.Property("PlayerPickId") + .HasColumnType("nvarchar(450)"); + + b.Property("Sc2MatchId") + .HasColumnType("uniqueidentifier"); + + b.Property("WinnerId") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("PlayerBanId"); + + b.HasIndex("PlayerPickId"); + + b.HasIndex("Sc2MatchId"); + + b.ToTable("SC2MatchMaps"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.StarCraft2Details", b => + { + b.Property("BattleNetId") + .HasColumnType("nvarchar(450)"); + + b.Property("AvatarUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("BattleNetBattleTag") + .HasColumnType("nvarchar(max)"); + + b.Property("ProfileUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("RealmId") + .HasColumnType("int"); + + b.Property("RegionId") + .HasColumnType("int"); + + b.HasKey("BattleNetId"); + + b.ToTable("StarCraft2Details"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.StrategyComment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Comment") + .HasColumnType("nvarchar(max)"); + + b.Property("Published") + .HasColumnType("datetimeoffset"); + + b.Property("StratId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("StratId"); + + b.HasIndex("UserId"); + + b.ToTable("StrategyComments"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.StrategyVote", b => + { + b.Property("StratId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("Vote") + .HasColumnType("int"); + + b.HasKey("StratId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("StrategyVotes"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.Subscriber", b => + { + b.Property("Email") + .HasColumnType("nvarchar(450)"); + + b.Property("SubKey") + .HasColumnType("uniqueidentifier"); + + b.Property("Subscribed") + .HasColumnType("bit"); + + b.HasKey("Email"); + + b.ToTable("Subscribers"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamApplication", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("ApplicantId") + .HasColumnType("nvarchar(450)"); + + b.Property("Message") + .HasColumnType("nvarchar(max)"); + + b.Property("Sent") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetimeoffset"); + + b.Property("State") + .HasColumnType("int"); + + b.Property("TeamId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ApplicantId"); + + b.HasIndex("TeamId"); + + b.ToTable("TeamApplications"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamAvailability", b => + { + b.Property("TeamId") + .HasColumnType("uniqueidentifier"); + + b.Property("Day") + .HasColumnType("int"); + + b.Property("Available") + .HasColumnType("bit"); + + b.Property("From") + .HasColumnType("datetimeoffset"); + + b.Property("To") + .HasColumnType("datetimeoffset"); + + b.HasKey("TeamId", "Day"); + + b.ToTable("TeamAvailabilities"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamInvite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("InvitedUserId") + .HasColumnType("nvarchar(450)"); + + b.Property("InvitingUserId") + .HasColumnType("nvarchar(450)"); + + b.Property("Message") + .HasColumnType("nvarchar(max)"); + + b.Property("Sent") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetimeoffset"); + + b.Property("State") + .HasColumnType("int"); + + b.Property("TeamId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("InvitedUserId"); + + b.HasIndex("InvitingUserId"); + + b.HasIndex("TeamId"); + + b.ToTable("TeamInvites"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamMapPool", b => + { + b.Property("TeamId") + .HasColumnType("uniqueidentifier"); + + b.Property("Map") + .HasColumnType("int"); + + b.Property("IsPlayed") + .HasColumnType("bit"); + + b.HasKey("TeamId", "Map"); + + b.ToTable("TeamMapPools"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamMember", b => + { + b.Property("TeamId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsAdmin") + .HasColumnType("bit"); + + b.Property("IsEditor") + .HasColumnType("bit"); + + b.Property("Role") + .HasColumnType("int"); + + b.HasKey("TeamId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("TeamMembers"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.Tournament", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Active") + .HasColumnType("bit"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("EndDate") + .HasColumnType("datetimeoffset"); + + b.Property("Logo") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("StartDate") + .HasColumnType("datetimeoffset"); + + b.HasKey("ID"); + + b.ToTable("Tournaments"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentApplication", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("BattleNetId") + .HasColumnType("nvarchar(max)"); + + b.Property("CompanyId") + .HasColumnType("nvarchar(450)"); + + b.Property("Country") + .HasColumnType("nvarchar(max)"); + + b.Property("DateSubmitted") + .HasColumnType("datetimeoffset"); + + b.Property("Discord") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("Game") + .HasColumnType("int"); + + b.Property("Hash") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("State") + .HasColumnType("int"); + + b.Property("TeamId") + .HasColumnType("uniqueidentifier"); + + b.Property("TournamentCSGOGroupId") + .HasColumnType("uniqueidentifier"); + + b.Property("TournamentId") + .HasColumnType("uniqueidentifier"); + + b.Property("TournamentSC2GroupId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("CompanyId"); + + b.HasIndex("TeamId"); + + b.HasIndex("TournamentCSGOGroupId"); + + b.HasIndex("TournamentId"); + + b.HasIndex("TournamentSC2GroupId"); + + b.HasIndex("UserId"); + + b.ToTable("TournamentApplications"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentCSGOGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("TournamentId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("TournamentId"); + + b.ToTable("TournamentCSGOGroups"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentCSGOMatch", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("DemoLink") + .HasColumnType("nvarchar(max)"); + + b.Property("GroupId") + .HasColumnType("uniqueidentifier"); + + b.Property("NoShow") + .HasColumnType("bit"); + + b.Property("StartTime") + .HasColumnType("datetimeoffset"); + + b.Property("Team1Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Team1Points") + .HasColumnType("int"); + + b.Property("Team2Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Team2Points") + .HasColumnType("int"); + + b.Property("TournamentId") + .HasColumnType("uniqueidentifier"); + + b.Property("VideoLink") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.HasIndex("Team1Id"); + + b.HasIndex("Team2Id"); + + b.HasIndex("TournamentId"); + + b.ToTable("TournamentCSGOMatches"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentSC2Group", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("TournamentId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("TournamentId"); + + b.ToTable("TournamentSC2Groups"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentSC2Match", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("DemoLink") + .HasColumnType("nvarchar(max)"); + + b.Property("GroupId") + .HasColumnType("uniqueidentifier"); + + b.Property("NoShow") + .HasColumnType("bit"); + + b.Property("Player1Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Player1Points") + .HasColumnType("int"); + + b.Property("Player2Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Player2Points") + .HasColumnType("int"); + + b.Property("StartTime") + .HasColumnType("datetimeoffset"); + + b.Property("TournamentId") + .HasColumnType("uniqueidentifier"); + + b.Property("VideoLink") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.HasIndex("Player1Id"); + + b.HasIndex("Player2Id"); + + b.HasIndex("TournamentId"); + + b.ToTable("TournamentSC2Matches"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.UserAvailability", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("Day") + .HasColumnType("int"); + + b.Property("Available") + .HasColumnType("bit"); + + b.Property("From") + .HasColumnType("datetimeoffset"); + + b.Property("To") + .HasColumnType("datetimeoffset"); + + b.HasKey("UserId", "Day"); + + b.ToTable("UserAvailabilities"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.UserMapPool", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("Map") + .HasColumnType("int") + .HasAnnotation("Relational:JsonPropertyName", "mapId"); + + b.Property("IsPlayed") + .HasColumnType("bit"); + + b.HasKey("UserId", "Map"); + + b.ToTable("UserMapPool"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.UserMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("From") + .HasColumnType("nvarchar(450)"); + + b.Property("Message") + .HasColumnType("nvarchar(max)"); + + b.Property("TimeStamp") + .HasColumnType("datetimeoffset"); + + b.Property("To") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("From"); + + b.HasIndex("To"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.ApplicationUser", b => + { + b.HasOne("BellumGens.Api.Core.Models.StarCraft2Details", "StarCraft2Details") + .WithMany() + .HasForeignKey("BattleNetId"); + + b.HasOne("BellumGens.Api.Core.Models.CSGODetails", "CSGODetails") + .WithMany() + .HasForeignKey("SteamID"); + + b.Navigation("CSGODetails"); + + b.Navigation("StarCraft2Details"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.BellumGensPushSubscription", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.CSGOMatchMap", b => + { + b.HasOne("BellumGens.Api.Core.Models.TournamentCSGOMatch", "Match") + .WithMany("Maps") + .HasForeignKey("CsgoMatchId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "BanningTeam") + .WithMany() + .HasForeignKey("TeamBanId"); + + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "PickingTeam") + .WithMany() + .HasForeignKey("TeamPickId"); + + b.Navigation("BanningTeam"); + + b.Navigation("Match"); + + b.Navigation("PickingTeam"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.CSGOStrategy", b => + { + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team") + .WithMany("Strategies") + .HasForeignKey("TeamId"); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("Team"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.JerseyDetails", b => + { + b.HasOne("BellumGens.Api.Core.Models.JerseyOrder", "Order") + .WithMany("Jerseys") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.JerseyOrder", b => + { + b.HasOne("BellumGens.Api.Core.Models.Promo", "Promo") + .WithMany() + .HasForeignKey("PromoCode"); + + b.Navigation("Promo"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.SC2MatchMap", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "BanningPlayer") + .WithMany() + .HasForeignKey("PlayerBanId"); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "PickingPlayer") + .WithMany() + .HasForeignKey("PlayerPickId"); + + b.HasOne("BellumGens.Api.Core.Models.TournamentSC2Match", "Match") + .WithMany("Maps") + .HasForeignKey("Sc2MatchId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("BanningPlayer"); + + b.Navigation("Match"); + + b.Navigation("PickingPlayer"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.StrategyComment", b => + { + b.HasOne("BellumGens.Api.Core.Models.CSGOStrategy", "Strategy") + .WithMany("Comments") + .HasForeignKey("StratId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("Strategy"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.StrategyVote", b => + { + b.HasOne("BellumGens.Api.Core.Models.CSGOStrategy", "Strategy") + .WithMany("Votes") + .HasForeignKey("StratId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Strategy"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamApplication", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "User") + .WithMany("TeamApplications") + .HasForeignKey("ApplicantId"); + + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team") + .WithMany("Applications") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Team"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamAvailability", b => + { + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team") + .WithMany("PracticeSchedule") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Team"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamInvite", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "InvitedUser") + .WithMany("Notifications") + .HasForeignKey("InvitedUserId") + .OnDelete(DeleteBehavior.NoAction); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "InvitingUser") + .WithMany("InvitesSent") + .HasForeignKey("InvitingUserId") + .OnDelete(DeleteBehavior.NoAction); + + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team") + .WithMany("Invites") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("InvitedUser"); + + b.Navigation("InvitingUser"); + + b.Navigation("Team"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamMapPool", b => + { + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team") + .WithMany("MapPool") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Team"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TeamMember", b => + { + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team") + .WithMany("Members") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "Member") + .WithMany("MemberOf") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Member"); + + b.Navigation("Team"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentApplication", b => + { + b.HasOne("BellumGens.Api.Core.Models.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId"); + + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team") + .WithMany() + .HasForeignKey("TeamId"); + + b.HasOne("BellumGens.Api.Core.Models.TournamentCSGOGroup", "CSGOGroup") + .WithMany("Participants") + .HasForeignKey("TournamentCSGOGroupId"); + + b.HasOne("BellumGens.Api.Core.Models.Tournament", "Tournament") + .WithMany("Applications") + .HasForeignKey("TournamentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BellumGens.Api.Core.Models.TournamentSC2Group", "SC2Group") + .WithMany("Participants") + .HasForeignKey("TournamentSC2GroupId"); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("CSGOGroup"); + + b.Navigation("Company"); + + b.Navigation("SC2Group"); + + b.Navigation("Team"); + + b.Navigation("Tournament"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentCSGOGroup", b => + { + b.HasOne("BellumGens.Api.Core.Models.Tournament", "Tournament") + .WithMany("CSGOGroups") + .HasForeignKey("TournamentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Tournament"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentCSGOMatch", b => + { + b.HasOne("BellumGens.Api.Core.Models.TournamentCSGOGroup", "Group") + .WithMany("Matches") + .HasForeignKey("GroupId"); + + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team1") + .WithMany() + .HasForeignKey("Team1Id") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.HasOne("BellumGens.Api.Core.Models.CSGOTeam", "Team2") + .WithMany() + .HasForeignKey("Team2Id") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.HasOne("BellumGens.Api.Core.Models.Tournament", "Tournament") + .WithMany("CSGOMatches") + .HasForeignKey("TournamentId"); + + b.Navigation("Group"); + + b.Navigation("Team1"); + + b.Navigation("Team2"); + + b.Navigation("Tournament"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentSC2Group", b => + { + b.HasOne("BellumGens.Api.Core.Models.Tournament", "Tournament") + .WithMany("SC2Groups") + .HasForeignKey("TournamentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Tournament"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentSC2Match", b => + { + b.HasOne("BellumGens.Api.Core.Models.TournamentSC2Group", "Group") + .WithMany("Matches") + .HasForeignKey("GroupId"); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "Player1") + .WithMany() + .HasForeignKey("Player1Id"); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "Player2") + .WithMany() + .HasForeignKey("Player2Id"); + + b.HasOne("BellumGens.Api.Core.Models.Tournament", "Tournament") + .WithMany("SC2Matches") + .HasForeignKey("TournamentId"); + + b.Navigation("Group"); + + b.Navigation("Player1"); + + b.Navigation("Player2"); + + b.Navigation("Tournament"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.UserAvailability", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "User") + .WithMany("Availability") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.UserMapPool", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "User") + .WithMany("MapPool") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.UserMessage", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "SendingUser") + .WithMany() + .HasForeignKey("From"); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", "ReceivingUser") + .WithMany() + .HasForeignKey("To"); + + b.Navigation("ReceivingUser"); + + b.Navigation("SendingUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("BellumGens.Api.Core.Models.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.ApplicationUser", b => + { + b.Navigation("Availability"); + + b.Navigation("InvitesSent"); + + b.Navigation("MapPool"); + + b.Navigation("MemberOf"); + + b.Navigation("Notifications"); + + b.Navigation("TeamApplications"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.CSGOStrategy", b => + { + b.Navigation("Comments"); + + b.Navigation("Votes"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.CSGOTeam", b => + { + b.Navigation("Applications"); + + b.Navigation("Invites"); + + b.Navigation("MapPool"); + + b.Navigation("Members"); + + b.Navigation("PracticeSchedule"); + + b.Navigation("Strategies"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.JerseyOrder", b => + { + b.Navigation("Jerseys"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.Tournament", b => + { + b.Navigation("Applications"); + + b.Navigation("CSGOGroups"); + + b.Navigation("CSGOMatches"); + + b.Navigation("SC2Groups"); + + b.Navigation("SC2Matches"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentCSGOGroup", b => + { + b.Navigation("Matches"); + + b.Navigation("Participants"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentCSGOMatch", b => + { + b.Navigation("Maps"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentSC2Group", b => + { + b.Navigation("Matches"); + + b.Navigation("Participants"); + }); + + modelBuilder.Entity("BellumGens.Api.Core.Models.TournamentSC2Match", b => + { + b.Navigation("Maps"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BellumGens.Api.Core/Migrations/20241212121248_FullSC2Profile.cs b/BellumGens.Api.Core/Migrations/20241212121248_FullSC2Profile.cs new file mode 100644 index 0000000..8a5fd70 --- /dev/null +++ b/BellumGens.Api.Core/Migrations/20241212121248_FullSC2Profile.cs @@ -0,0 +1,50 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BellumGens.Api.Core.Migrations +{ + /// + public partial class FullSC2Profile : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ProfileUrl", + table: "StarCraft2Details", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AddColumn( + name: "RealmId", + table: "StarCraft2Details", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "RegionId", + table: "StarCraft2Details", + type: "int", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ProfileUrl", + table: "StarCraft2Details"); + + migrationBuilder.DropColumn( + name: "RealmId", + table: "StarCraft2Details"); + + migrationBuilder.DropColumn( + name: "RegionId", + table: "StarCraft2Details"); + } + } +} diff --git a/BellumGens.Api.Core/Migrations/BellumGensDbContextModelSnapshot.cs b/BellumGens.Api.Core/Migrations/BellumGensDbContextModelSnapshot.cs index 7aa6efe..d513b49 100644 --- a/BellumGens.Api.Core/Migrations/BellumGensDbContextModelSnapshot.cs +++ b/BellumGens.Api.Core/Migrations/BellumGensDbContextModelSnapshot.cs @@ -483,6 +483,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("BattleNetBattleTag") .HasColumnType("nvarchar(max)"); + b.Property("ProfileUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("RealmId") + .HasColumnType("int"); + + b.Property("RegionId") + .HasColumnType("int"); + b.HasKey("BattleNetId"); b.ToTable("StarCraft2Details"); diff --git a/BellumGens.Api.Core/Models/StarCraft2Details.cs b/BellumGens.Api.Core/Models/StarCraft2Details.cs index 00d516c..c06854c 100644 --- a/BellumGens.Api.Core/Models/StarCraft2Details.cs +++ b/BellumGens.Api.Core/Models/StarCraft2Details.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; +using StarCraft2Models; +using System.ComponentModel.DataAnnotations; namespace BellumGens.Api.Core.Models { @@ -9,5 +9,8 @@ public class StarCraft2Details public string BattleNetId { get; set; } public string BattleNetBattleTag { get; set; } public string AvatarUrl { get; set; } + public string ProfileUrl { get; set; } + public int RegionId { get; set; } + public int RealmId { get; set; } } } diff --git a/BellumGens.Api.Core/Models/ViewModels/AccountViewModels.cs b/BellumGens.Api.Core/Models/ViewModels/AccountViewModels.cs index 1fc0a3c..2feab12 100644 --- a/BellumGens.Api.Core/Models/ViewModels/AccountViewModels.cs +++ b/BellumGens.Api.Core/Models/ViewModels/AccountViewModels.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; namespace BellumGens.Api.Core.Models { diff --git a/BellumGens.Api.Core/Models/ViewModels/UserStatsViewModel.cs b/BellumGens.Api.Core/Models/ViewModels/UserStatsViewModel.cs index 0faeb7e..b3efdd0 100644 --- a/BellumGens.Api.Core/Models/ViewModels/UserStatsViewModel.cs +++ b/BellumGens.Api.Core/Models/ViewModels/UserStatsViewModel.cs @@ -111,6 +111,21 @@ public void RefreshAppUserValues(BellumGensDbContext context) Sc2Details.AvatarUrl = SC2Player.avatarUrl; sc2change = true; } + if (SC2Player.profileUrl != Sc2Details.ProfileUrl) + { + Sc2Details.ProfileUrl = SC2Player.profileUrl; + sc2change = true; + } + if (SC2Player.regionId != Sc2Details.RegionId) + { + Sc2Details.RegionId = SC2Player.regionId; + sc2change = true; + } + if (SC2Player.realmId != Sc2Details.RealmId) + { + Sc2Details.RealmId = SC2Player.realmId; + sc2change = true; + } } if (userchange) { diff --git a/BellumGens.Api.Core/Providers/BattleNetServiceProvider.cs b/BellumGens.Api.Core/Providers/BattleNetServiceProvider.cs index 4155822..23953f2 100644 --- a/BellumGens.Api.Core/Providers/BattleNetServiceProvider.cs +++ b/BellumGens.Api.Core/Providers/BattleNetServiceProvider.cs @@ -15,8 +15,8 @@ public class BattleNetServiceProvider : IBattleNetService { private readonly IMemoryCache _cache; - private static readonly string _playerAccountEndpoint = "https://{0}.api.blizzard.com/sc2/player/{1}?access_token={2}"; - // private static readonly string _profileEndpoint = "https://{0}.api.blizzard.com/sc2/metadata/profile/{1}/{2}/{3}?locale=en_US&access_token={4}"; + private static readonly string _playerAccountEndpoint = "https://{0}.api.blizzard.com/sc2/player/{1}"; + private static readonly string _profileEndpoint = "https://{0}.api.blizzard.com/sc2/metadata/profile/{1}/{2}/{3}?locale=en_US&access_token={4}"; private static readonly string _tokenEndpoint = "https://oauth.battle.net/token"; private static OAuthResponse _oauth; @@ -44,18 +44,43 @@ public async Task GetStarCraft2Player(string playerid, string region = " _oauth = await GetAccessToken(); } + Uri endpoint = new(string.Format(_playerAccountEndpoint, region, playerid)); + var requestMessage = new HttpRequestMessage(HttpMethod.Get, endpoint); + requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _oauth.access_token); + using HttpClient client = new(); - Uri endpoint = new(string.Format(_playerAccountEndpoint, region, playerid, _oauth.access_token)); - var response = await client.GetStringAsync(endpoint); - player = JsonSerializer.Deserialize(response); - _cache.Set(playerid, player, DateTime.Now.AddDays(1)); - return player?[0]; + var response = await client.SendAsync(requestMessage); + if (response.IsSuccessStatusCode) + { + _tokenIssueStamp = DateTimeOffset.Now; + var responseString = await response.Content.ReadAsStringAsync(); + player = JsonSerializer.Deserialize(responseString); + _cache.Set(playerid, player, DateTime.Now.AddDays(1)); + return player?[0]; + } + return null; } - //public Task GetStarCraft2PlayerProfile(string playerid, string region = "eu", int regionid = 2, int realmid = 1) - //{ + public async Task GetStarCraft2PlayerProfile(string playerid, string region = "eu", int regionid = 2, int realmid = 1) + { + PlayerProfile profile; + if (_cache.Get(playerid) is PlayerProfile) + { + return _cache.Get(playerid) as PlayerProfile; + } + + if (_oauth == null || DateTimeOffset.Now > _tokenIssueStamp.AddSeconds(_oauth.expires_in)) + { + _oauth = await GetAccessToken(); + } - //} + using HttpClient client = new(); + Uri endpoint = new(string.Format(_profileEndpoint, region, regionid, realmid, playerid, _oauth.access_token)); + var response = await client.GetStringAsync(endpoint); + profile = JsonSerializer.Deserialize(response); + _cache.Set(playerid, profile, DateTime.Now.AddDays(1)); + return profile; + } private static async Task GetAccessToken() { diff --git a/BellumGens.Api.Core/Providers/IBattleNetService.cs b/BellumGens.Api.Core/Providers/IBattleNetService.cs index 4a58212..fcea772 100644 --- a/BellumGens.Api.Core/Providers/IBattleNetService.cs +++ b/BellumGens.Api.Core/Providers/IBattleNetService.cs @@ -6,6 +6,6 @@ namespace BellumGens.Api.Core.Providers public interface IBattleNetService { public Task GetStarCraft2Player(string playerid, string region = "eu"); - //public Task GetStarCraft2PlayerProfile(string playerid, string region, int regionid = 2, int realmid = 1); + public Task GetStarCraft2PlayerProfile(string playerid, string region = "eu", int regionid = 2, int realmid = 1); } }