Lots of data and model setup
This commit is contained in:
15
SVSim.Database/Repositories/BaseRepository.cs
Normal file
15
SVSim.Database/Repositories/BaseRepository.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SVSim.Database.Repositories;
|
||||
|
||||
public abstract class BaseRepository<T> where T : class
|
||||
{
|
||||
protected readonly SVSimDbContext DbContext;
|
||||
protected readonly DbSet<T> DbSet;
|
||||
|
||||
public BaseRepository(SVSimDbContext dbContext)
|
||||
{
|
||||
DbContext = dbContext;
|
||||
DbSet = DbContext.Set<T>();
|
||||
}
|
||||
}
|
||||
30
SVSim.Database/Repositories/Card/CardRepository.cs
Normal file
30
SVSim.Database/Repositories/Card/CardRepository.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using DCGEngine.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.Card;
|
||||
|
||||
public class CardRepository : BaseRepository<ShadowverseCardEntry>, ICardRepository
|
||||
{
|
||||
public CardRepository(SVSimDbContext dbContext) : base(dbContext)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<ShadowverseCardEntry>> GetAll(bool onlyCollectible)
|
||||
{
|
||||
var cards = await DbSet.AsNoTracking().Where(card => !onlyCollectible || card.CollectionInfo != null).ToListAsync();
|
||||
return cards;
|
||||
}
|
||||
|
||||
public async Task<List<ShadowverseCardEntry>> GetAllBasic()
|
||||
{
|
||||
return await DbContext.Set<ShadowverseCardSetEntry>().Where(set => set.IsBasic).SelectMany(set => set.Cards)
|
||||
.Cast<ShadowverseCardEntry>().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ShadowverseCardSetEntry>> GetCardSets(bool onlyInRotation)
|
||||
{
|
||||
return await DbContext.Set<ShadowverseCardSetEntry>().AsNoTracking()
|
||||
.Where(set => !onlyInRotation || set.IsInRotation).ToListAsync();
|
||||
}
|
||||
}
|
||||
10
SVSim.Database/Repositories/Card/ICardRepository.cs
Normal file
10
SVSim.Database/Repositories/Card/ICardRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.Card;
|
||||
|
||||
public interface ICardRepository
|
||||
{
|
||||
Task<List<ShadowverseCardEntry>> GetAll(bool onlyCollectible);
|
||||
Task<List<ShadowverseCardSetEntry>> GetCardSets(bool onlyInRotation);
|
||||
Task<List<ShadowverseCardEntry>> GetAllBasic();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.Collectibles;
|
||||
|
||||
public class CollectionRepository : ICollectionRepository
|
||||
{
|
||||
private readonly SVSimDbContext _dbContext;
|
||||
|
||||
public CollectionRepository(SVSimDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<List<LeaderSkinEntry>> GetLeaderSkins()
|
||||
{
|
||||
return await _dbContext.Set<LeaderSkinEntry>().AsNoTracking().Include(skin => skin.Class).ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.Collectibles;
|
||||
|
||||
public interface ICollectionRepository
|
||||
{
|
||||
Task<List<LeaderSkinEntry>> GetLeaderSkins();
|
||||
}
|
||||
36
SVSim.Database/Repositories/Globals/GlobalsRepository.cs
Normal file
36
SVSim.Database/Repositories/Globals/GlobalsRepository.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.Globals;
|
||||
|
||||
public class GlobalsRepository : IGlobalsRepository
|
||||
{
|
||||
private readonly SVSimDbContext _dbContext;
|
||||
|
||||
public GlobalsRepository(SVSimDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<List<ClassExpEntry>> GetClassExpCurve()
|
||||
{
|
||||
return await _dbContext.Set<ClassExpEntry>().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<BattlefieldEntry>> GetBattlefields(bool onlyOpen)
|
||||
{
|
||||
return await _dbContext.Set<BattlefieldEntry>().Where(bf => !onlyOpen || bf.IsOpen).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<GameConfiguration> GetGameConfiguration(string key)
|
||||
{
|
||||
return await _dbContext.Set<GameConfiguration>().Include(gc => gc.DefaultMyPageBackground)
|
||||
.Include(gc => gc.DefaultEmblem).Include(gc => gc.DefaultDegree).Include(gc => gc.DefaultSleeve).FirstOrDefaultAsync(gc => gc.Id == key) ??
|
||||
new GameConfiguration();
|
||||
}
|
||||
|
||||
public async Task<List<RankInfoEntry>> GetRankInfo()
|
||||
{
|
||||
return await _dbContext.Set<RankInfoEntry>().ToListAsync();
|
||||
}
|
||||
}
|
||||
11
SVSim.Database/Repositories/Globals/IGlobalsRepository.cs
Normal file
11
SVSim.Database/Repositories/Globals/IGlobalsRepository.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.Globals;
|
||||
|
||||
public interface IGlobalsRepository
|
||||
{
|
||||
Task<List<ClassExpEntry>> GetClassExpCurve();
|
||||
Task<List<BattlefieldEntry>> GetBattlefields(bool onlyOpen);
|
||||
Task<GameConfiguration> GetGameConfiguration(string key);
|
||||
Task<List<RankInfoEntry>> GetRankInfo();
|
||||
}
|
||||
@@ -5,6 +5,9 @@ namespace SVSim.Database.Repositories.Viewer;
|
||||
public interface IViewerRepository
|
||||
{
|
||||
Task<Models.Viewer?> GetViewerBySocialConnection(SocialAccountType accountType, ulong socialId);
|
||||
Task<Models.Viewer?> GetViewerWithSocials(ulong id);
|
||||
Task<Models.Viewer?> GetViewerByShortUdid(ulong shortUdid);
|
||||
Task<Models.Viewer?> GetViewerWithSocials(long id);
|
||||
Task<Models.Viewer?> GetViewerByShortUdid(long shortUdid);
|
||||
|
||||
Task<Models.Viewer> RegisterViewer(string displayName, SocialAccountType socialType,
|
||||
ulong socialAccountIdentifier, ulong? shortUdid = null);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database.Enums;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Card;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
|
||||
namespace SVSim.Database.Repositories.Viewer;
|
||||
|
||||
@@ -8,6 +10,8 @@ public class ViewerRepository : IViewerRepository
|
||||
{
|
||||
protected readonly SVSimDbContext _dbContext;
|
||||
|
||||
private const int MaxFriends = 20;
|
||||
|
||||
public ViewerRepository(SVSimDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
@@ -22,15 +26,58 @@ public class ViewerRepository : IViewerRepository
|
||||
?.Viewer;
|
||||
}
|
||||
|
||||
public async Task<Models.Viewer?> GetViewerWithSocials(ulong id)
|
||||
public async Task<Models.Viewer?> GetViewerWithSocials(long id)
|
||||
{
|
||||
return await _dbContext.Set<Models.Viewer>().AsNoTracking().Include(viewer => viewer.SocialAccountConnections)
|
||||
.FirstOrDefaultAsync(viewer => viewer.Id == id);
|
||||
}
|
||||
|
||||
public async Task<Models.Viewer?> GetViewerByShortUdid(ulong shortUdid)
|
||||
public async Task<Models.Viewer?> GetViewerByShortUdid(long shortUdid)
|
||||
{
|
||||
return await _dbContext.Set<Models.Viewer>().AsNoTracking().Include(viewer => viewer.MissionData)
|
||||
.Include(viewer => viewer.Info).FirstOrDefaultAsync(viewer => viewer.ShortUdid == shortUdid);
|
||||
}
|
||||
|
||||
public async Task<Models.Viewer> RegisterViewer(string displayName, SocialAccountType socialType,
|
||||
ulong socialAccountIdentifier, ulong? shortUdid = null)
|
||||
{
|
||||
Models.Viewer viewer = new Models.Viewer
|
||||
{
|
||||
DisplayName = displayName
|
||||
};
|
||||
GameConfiguration gameConfig = await new GlobalsRepository(_dbContext).GetGameConfiguration("default");
|
||||
|
||||
viewer.SocialAccountConnections.Add(new SocialAccountConnection
|
||||
{
|
||||
AccountId = socialAccountIdentifier,
|
||||
AccountType = socialType
|
||||
});
|
||||
|
||||
viewer.Info.MaxFriends = gameConfig.MaxFriends;
|
||||
viewer.Info.CountryCode = "KOR";
|
||||
viewer.Info.BirthDate = DateTime.UtcNow;
|
||||
viewer.Currency.Crystals = gameConfig.DefaultCrystals;
|
||||
viewer.Currency.Rupees = gameConfig.DefaultRupees;
|
||||
viewer.Currency.RedEther = gameConfig.DefaultEther;
|
||||
viewer.MissionData.TutorialState = 100; // finishes tutorial for now
|
||||
|
||||
List<ClassEntry> classes = await _dbContext.Set<ClassEntry>().ToListAsync();
|
||||
viewer.Classes = classes.Select(ce => new ViewerClassData
|
||||
{
|
||||
Class = ce,
|
||||
Exp = 0,
|
||||
Level = 0,
|
||||
LeaderSkin = ce.DefaultLeaderSkin
|
||||
}).ToList();
|
||||
|
||||
viewer.Sleeves.Add(gameConfig.DefaultSleeve);
|
||||
viewer.Degrees.Add(gameConfig.DefaultDegree);
|
||||
viewer.Emblems.Add(gameConfig.DefaultEmblem);
|
||||
viewer.MyPageBackgrounds.Add(gameConfig.DefaultMyPageBackground);
|
||||
viewer.LeaderSkins.AddRange(viewer.Classes.Select(vcd => vcd.LeaderSkin));
|
||||
|
||||
_dbContext.Set<Models.Viewer>().Add(viewer);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return viewer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user