Story
This commit is contained in:
49
SVSim.Database/Repositories/Story/StoryMasterRepository.cs
Normal file
49
SVSim.Database/Repositories/Story/StoryMasterRepository.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database.Entities.Story;
|
||||
|
||||
namespace SVSim.Database.Repositories.Story;
|
||||
|
||||
public class StoryMasterRepository : IStoryMasterRepository
|
||||
{
|
||||
private readonly SVSimDbContext _db;
|
||||
public StoryMasterRepository(SVSimDbContext db) { _db = db; }
|
||||
|
||||
public Task<List<StorySection>> GetSectionsByFamilyAsync(StoryApiType apiType)
|
||||
{
|
||||
var families = apiType == StoryApiType.AllStory
|
||||
? new[] { StoryApiType.Main } // AllStory effectively returns Main per spec
|
||||
: new[] { apiType };
|
||||
return _db.StorySections.Where(s => families.Contains(s.StoryApiType))
|
||||
.OrderBy(s => s.AllStoryOrderId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public Task<List<StoryWorld>> GetWorldsForSectionsAsync(IEnumerable<int> worldIds)
|
||||
=> _db.StoryWorlds.Where(w => worldIds.Contains(w.Id)).ToListAsync();
|
||||
|
||||
public Task<List<StoryChapter>> GetChaptersBySectionCharaAsync(int sectionId, int charaId)
|
||||
=> _db.StoryChapters
|
||||
.Include(c => c.BattleSettings).Include(c => c.Rewards).Include(c => c.SubChapters)
|
||||
.Where(c => c.SectionId == sectionId && c.CharaId == charaId)
|
||||
.ToListAsync();
|
||||
|
||||
// No Includes — the rollup only reads SectionId/CharaId/StoryId. Including the three owned
|
||||
// collections here would cartesian-explode across ~677 chapters and turn a single query into
|
||||
// a multi-MB result set.
|
||||
public Task<List<StoryChapter>> GetChaptersBySectionsAsync(IEnumerable<int> sectionIds)
|
||||
{
|
||||
var ids = sectionIds.ToList();
|
||||
return _db.StoryChapters
|
||||
.AsNoTracking()
|
||||
.Where(c => ids.Contains(c.SectionId))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public Task<StoryChapter?> GetChapterByIdAsync(int storyId)
|
||||
=> _db.StoryChapters
|
||||
.Include(c => c.BattleSettings).Include(c => c.Rewards).Include(c => c.SubChapters)
|
||||
.FirstOrDefaultAsync(c => c.StoryId == storyId);
|
||||
|
||||
public Task<SpecialBattleSetting?> GetSbsByIdAsync(int sbsId)
|
||||
=> _db.SpecialBattleSettings.FirstOrDefaultAsync(s => s.Id == sbsId);
|
||||
}
|
||||
Reference in New Issue
Block a user