From fd84be3a5c01251d8e6ee400d8a7c4051fc17f5d Mon Sep 17 00:00:00 2001 From: Sean-mn Date: Thu, 5 Mar 2026 15:10:06 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=8A=A4=ED=82=AC=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #171 --- .../CreatePlayerCharacterDataUseCaseTests.cs | 8 +- .../GetAllPlayerCharacterDataUseCaseTests.cs | 3 +- .../GetPlayerCharacterUseCaseTests.cs | 3 +- .../Api/Extensions/ServiceExtensions.cs | 4 - .../Port/Output/StaticData/ISkillDataStore.cs | 9 -- .../Service/CharacterDataCache.cs | 28 ----- .../Service/CharacterService.cs | 73 ----------- .../StaticData/Model/CharacterData.cs | 5 +- .../StaticData/Model/SkillData.cs | 31 ----- .../StaticData/Store/CharacterStore.cs | 43 +------ .../StaticData/Store/SkillDataStore.cs | 115 ------------------ 11 files changed, 7 insertions(+), 315 deletions(-) delete mode 100644 PaperMania/Server/Application/Port/Output/StaticData/ISkillDataStore.cs delete mode 100644 PaperMania/Server/Infrastructure/Service/CharacterDataCache.cs delete mode 100644 PaperMania/Server/Infrastructure/Service/CharacterService.cs delete mode 100644 PaperMania/Server/Infrastructure/StaticData/Model/SkillData.cs delete mode 100644 PaperMania/Server/Infrastructure/StaticData/Store/SkillDataStore.cs diff --git a/PaperMania/Server.Tests/Application/Character/CreatePlayerCharacterDataUseCaseTests.cs b/PaperMania/Server.Tests/Application/Character/CreatePlayerCharacterDataUseCaseTests.cs index 1503581b..87e704aa 100644 --- a/PaperMania/Server.Tests/Application/Character/CreatePlayerCharacterDataUseCaseTests.cs +++ b/PaperMania/Server.Tests/Application/Character/CreatePlayerCharacterDataUseCaseTests.cs @@ -18,8 +18,7 @@ public class CreatePlayerCharacterDataUseCaseTests private readonly Mock _storeMock = new(); private readonly Mock _txMock = new(); - private CreatePlayerCharacterDataUseCase CreateUseCase() - => new CreatePlayerCharacterDataUseCase(_repoMock.Object, _storeMock.Object, _txMock.Object); + private CreatePlayerCharacterDataUseCase CreateUseCase() => new(_repoMock.Object, _storeMock.Object, _txMock.Object); [Fact] public async Task ExecuteAsync_Should_Throw_When_Character_Not_Found() @@ -48,10 +47,7 @@ public async Task ExecuteAsync_Should_Create_CharacterData_And_PieceData() Role: CharacterRole.Main, Rarity: CharacterRarity.Common, BaseHP: 100, - BaseATK: 20, - NormalSkillId: 1, - UltimateSkillId: 2, - SupportSkillId: 3 + BaseATK: 20 ); _storeMock.Setup(x => x.Get(10)).Returns(character); diff --git a/PaperMania/Server.Tests/Application/Character/GetAllPlayerCharacterDataUseCaseTests.cs b/PaperMania/Server.Tests/Application/Character/GetAllPlayerCharacterDataUseCaseTests.cs index 08edc1a4..d23b3f09 100644 --- a/PaperMania/Server.Tests/Application/Character/GetAllPlayerCharacterDataUseCaseTests.cs +++ b/PaperMania/Server.Tests/Application/Character/GetAllPlayerCharacterDataUseCaseTests.cs @@ -13,8 +13,7 @@ public class GetAllPlayerCharacterDataUseCaseTests { private readonly Mock _repoMock = new(); - private GetAllPlayerCharacterDataUseCase CreateUseCase() - => new GetAllPlayerCharacterDataUseCase(_repoMock.Object); + private GetAllPlayerCharacterDataUseCase CreateUseCase() => new(_repoMock.Object); [Fact] public async Task ExecuteAsync_Should_Throw_When_UserId_Invalid() diff --git a/PaperMania/Server.Tests/Application/Character/GetPlayerCharacterUseCaseTests.cs b/PaperMania/Server.Tests/Application/Character/GetPlayerCharacterUseCaseTests.cs index 43eef278..82953893 100644 --- a/PaperMania/Server.Tests/Application/Character/GetPlayerCharacterUseCaseTests.cs +++ b/PaperMania/Server.Tests/Application/Character/GetPlayerCharacterUseCaseTests.cs @@ -13,8 +13,7 @@ public class GetPlayerCharacterUseCaseTests { private readonly Mock _repoMock = new(); - private GetPlayerCharacterUseCase CreateUseCase() - => new GetPlayerCharacterUseCase(_repoMock.Object); + private GetPlayerCharacterUseCase CreateUseCase() => new(_repoMock.Object); [Fact] public async Task ExecuteAsync_Should_Throw_When_PlayerCharacter_Not_Found() diff --git a/PaperMania/Server/Api/Extensions/ServiceExtensions.cs b/PaperMania/Server/Api/Extensions/ServiceExtensions.cs index 124c4c9a..cbf732f5 100644 --- a/PaperMania/Server/Api/Extensions/ServiceExtensions.cs +++ b/PaperMania/Server/Api/Extensions/ServiceExtensions.cs @@ -97,10 +97,6 @@ public static IServiceCollection AddStaticDataStores( services.AddHostedService(sp => (LevelDefinitionStore)sp.GetRequiredService()); - services.AddSingleton(); - services.AddHostedService(sp => - (SkillDataStore)sp.GetRequiredService()); - services.AddSingleton(); services.AddHostedService(sp => (CharacterStore)sp.GetRequiredService()); diff --git a/PaperMania/Server/Application/Port/Output/StaticData/ISkillDataStore.cs b/PaperMania/Server/Application/Port/Output/StaticData/ISkillDataStore.cs deleted file mode 100644 index d102167a..00000000 --- a/PaperMania/Server/Application/Port/Output/StaticData/ISkillDataStore.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Server.Infrastructure.StaticData.Model; - -namespace Server.Application.Port.Output.StaticData; - -public interface ISkillDataStore -{ - SkillData? Get(int skillId); - bool Contains(int skillId); -} \ No newline at end of file diff --git a/PaperMania/Server/Infrastructure/Service/CharacterDataCache.cs b/PaperMania/Server/Infrastructure/Service/CharacterDataCache.cs deleted file mode 100644 index 3a84a530..00000000 --- a/PaperMania/Server/Infrastructure/Service/CharacterDataCache.cs +++ /dev/null @@ -1,28 +0,0 @@ -// using Microsoft.Extensions.Options; -// using Server.Application.Configure; -// using Server.Domain.Entity; -// using Server.Infrastructure.StaticData; -// -// namespace Server.Infrastructure.Service; -// -// public class CharacterDataCache -// { -// private const string Url = -// "https://docs.google.com/spreadsheets/d/e/2PACX-1vT-hipnb7-1L4DFLEZQdC5S7MmB0DRUhn6-unGKKlL_djdIExwoQPtTv72W6e0CP9uHKe8nhIDGHPK5/pub?output=csv"; -// private Dictionary _characters = new(); -// -// public async Task Initialize() -// { -// var characterDataDict = await CsvHelper.LoadCsvAsync( -// Url,Url -// keySelector: c => c.CharacterId -// ); -// -// _characters = characterDataDict; -// } -// -// public CharacterData? GetCharacter(string characterId) -// { -// return _characters.TryGetValue(characterId, out var character) ? character : null; -// } -// } \ No newline at end of file diff --git a/PaperMania/Server/Infrastructure/Service/CharacterService.cs b/PaperMania/Server/Infrastructure/Service/CharacterService.cs deleted file mode 100644 index 7e938ec1..00000000 --- a/PaperMania/Server/Infrastructure/Service/CharacterService.cs +++ /dev/null @@ -1,73 +0,0 @@ -// using Server.Api.Dto.Response; -// using Server.Application.Exceptions; -// using Server.Application.Port; -// using Server.Domain.Entity; -// -// namespace Server.Infrastructure.Service; -// -// public class CharacterService : ICharacterService -// { -// private readonly CharacterDataCache _cache; -// private readonly ICharacterDao _repository; -// -// public CharacterService(CharacterDataCache cache, ICharacterDao repository) -// { -// _cache = cache; -// _repository = repository; -// } -// -// public async Task> GetPlayerCharacterDataByUserIdAsync(int userId) -// { -// var playerCharacters = (await _repository.GetPlayerCharactersDataByUserIdAsync(userId)) -// .ToList(); -// -// foreach (var pc in playerCharacters) -// { -// var baseData = _cache.GetCharacter(pc.Data.CharacterId); -// if (baseData == null) -// throw new RequestException(ErrorStatusCode.NotFound, "CHARACTER_NOT_FOUND", -// new { CharacterId = pc.Data.CharacterId }); -// -// pc.Data = baseData; -// } -// -// return playerCharacters; -// } -// -// public async Task AddPlayerCharacterDataByUserIdAsync(PlayerCharacterData data) -// { -// var baseData = _cache.GetCharacter(data.Data.CharacterId); -// if (baseData == null) -// throw new RequestException(ErrorStatusCode.NotFound, "CHARACTER_NOT_FOUND", -// new { CharacterId = data.Data.CharacterId }); -// -// var exists = await _repository.HasCharacterAsync(data.UserId, data.Data.CharacterId); -// if (exists) -// { -// if (data.PieceAmount > 0) -// await _repository.AddCharacterPiecesAsync(data.UserId, data.Data.CharacterId, 10); -// -// var playerCharacters = await _repository.GetPlayerCharactersDataByUserIdAsync(data.UserId); -// var existing = playerCharacters.FirstOrDefault -// (c => c.Data.CharacterId == data.Data.CharacterId); -// if (existing == null) -// throw new RequestException(ErrorStatusCode.NotFound, "CHARACTER_NOT_FOUND", -// new { CharacterId = data.Data.CharacterId }); -// -// existing.Data = baseData; -// -// return existing; -// } -// -// var newCharacter = new PlayerCharacterData -// { -// UserId = data.UserId, -// Data = baseData -// }; -// -// var inserted = await _repository.AddPlayerCharacterDataByUserIdAsync(newCharacter); -// inserted.Data = baseData; -// -// return inserted; -// } -// } \ No newline at end of file diff --git a/PaperMania/Server/Infrastructure/StaticData/Model/CharacterData.cs b/PaperMania/Server/Infrastructure/StaticData/Model/CharacterData.cs index c0ca7dee..670e6d23 100644 --- a/PaperMania/Server/Infrastructure/StaticData/Model/CharacterData.cs +++ b/PaperMania/Server/Infrastructure/StaticData/Model/CharacterData.cs @@ -6,10 +6,7 @@ public record CharacterData( CharacterRole Role, CharacterRarity Rarity, float BaseHP, - float BaseATK, - int NormalSkillId, - int UltimateSkillId, - int SupportSkillId + float BaseATK ); public enum CharacterRole diff --git a/PaperMania/Server/Infrastructure/StaticData/Model/SkillData.cs b/PaperMania/Server/Infrastructure/StaticData/Model/SkillData.cs deleted file mode 100644 index 6c372b31..00000000 --- a/PaperMania/Server/Infrastructure/StaticData/Model/SkillData.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Server.Infrastructure.StaticData.Model; - -public record SkillData( - int SkillId, - string SkillName, - SkillType SkillType, - float CoolTime, - SkillScalingType ScalingType, - SkillTargetType TargetType -); - -public enum SkillType -{ - Normal = 1, - Ultimate = 2, - Support = 3 -} - -public enum SkillScalingType -{ - ATK = 1, - HP = 2 -} - -public enum SkillTargetType -{ - Enemy = 1, - EnemyAll = 2, - Ally = 3, - Self = 4 -} \ No newline at end of file diff --git a/PaperMania/Server/Infrastructure/StaticData/Store/CharacterStore.cs b/PaperMania/Server/Infrastructure/StaticData/Store/CharacterStore.cs index b73eb4ea..1052762b 100644 --- a/PaperMania/Server/Infrastructure/StaticData/Store/CharacterStore.cs +++ b/PaperMania/Server/Infrastructure/StaticData/Store/CharacterStore.cs @@ -8,20 +8,17 @@ public class CharacterStore : ICharacterStore, IHostedService private readonly HttpClient _httpClient; private readonly ILogger _logger; private readonly IConfiguration _configuration; - private readonly ISkillDataStore _skillStore; private Dictionary _characters = new(); public CharacterStore( IHttpClientFactory httpClientFactory, ILogger logger, - IConfiguration configuration, - ISkillDataStore skillStore) + IConfiguration configuration) { _httpClient = httpClientFactory.CreateClient(); _logger = logger; _configuration = configuration; - _skillStore = skillStore; } public CharacterData? Get(int characterId) @@ -82,9 +79,6 @@ private static CharacterData Map(string[] cols) // 3: Rarity // 4: BaseHP // 5: BaseATK - // 6: NormalSkillId - // 7: UltimateSkillId - // 8: SupportSkillId return new CharacterData( int.Parse(cols[0]), @@ -93,11 +87,7 @@ private static CharacterData Map(string[] cols) CsvHelper.ParseEnum(cols[2], "Role"), CsvHelper.ParseEnum(cols[3], "Rarity"), float.Parse(cols[4]), - float.Parse(cols[5]), - - ParseOptionalInt(cols[6]), - ParseOptionalInt(cols[7]), - ParseOptionalInt(cols[8]) + float.Parse(cols[5]) ); } @@ -111,35 +101,6 @@ private void ValidateCharacters() if (c.BaseHP <= 0 || c.BaseATK <= 0) throw new InvalidOperationException( $"Invalid base stat for CharacterId={c.CharacterId}"); - - if (c.Role == CharacterRole.Main) - { - ValidateSkill(c.NormalSkillId, SkillType.Normal, c.CharacterId); - ValidateSkill(c.UltimateSkillId, SkillType.Ultimate, c.CharacterId); - } - - if (c.Role == CharacterRole.Support) - { - ValidateSkill(c.SupportSkillId, SkillType.Support, c.CharacterId); - } } } - - private void ValidateSkill(int skillId, SkillType expectedType, int characterId) - { - if (skillId == 0) - return; - - var skill = _skillStore.Get(skillId); - if (skill == null) - throw new InvalidOperationException( - $"Invalid SkillId={skillId} for CharacterId={characterId}"); - - if (skill.SkillType != expectedType) - throw new InvalidOperationException( - $"SkillType mismatch. CharacterId={characterId}, SkillId={skillId}"); - } - - private static int ParseOptionalInt(string value) - => string.IsNullOrWhiteSpace(value) ? 0 : int.Parse(value); } \ No newline at end of file diff --git a/PaperMania/Server/Infrastructure/StaticData/Store/SkillDataStore.cs b/PaperMania/Server/Infrastructure/StaticData/Store/SkillDataStore.cs deleted file mode 100644 index 4f26125b..00000000 --- a/PaperMania/Server/Infrastructure/StaticData/Store/SkillDataStore.cs +++ /dev/null @@ -1,115 +0,0 @@ -using Server.Application.Port.Output.StaticData; -using Server.Infrastructure.StaticData.Model; - -namespace Server.Infrastructure.StaticData.Store; - -public class SkillDataStore : ISkillDataStore, IHostedService -{ - private readonly HttpClient _httpClient; - private readonly ILogger _logger; - private readonly IConfiguration _configuration; - - private Dictionary _skills = new(); - - public SkillDataStore( - IHttpClientFactory httpClientFactory, - ILogger logger, - IConfiguration configuration) - { - _httpClient = httpClientFactory.CreateClient(); - _logger = logger; - _configuration = configuration; - } - - public SkillData? Get(int skillId) - { - return _skills.TryGetValue(skillId, out var skill) ? skill : null; - } - - public bool Contains(int skillId) - { - return _skills.ContainsKey(skillId); - } - - public async Task StartAsync(CancellationToken cancellationToken) - { - try - { - _logger.LogInformation("Loading skill definitions from CSV..."); - - var secretName = _configuration["StaticData:SkillDataCsvUrlSecretName"]; - if (string.IsNullOrEmpty(secretName)) - throw new InvalidOperationException("SkillDataCsvUrlSecretName is not configured"); - - var url = _configuration[secretName]; - if (string.IsNullOrEmpty(url)) - throw new InvalidOperationException( - $"CSV URL not found. Secret name: {secretName}"); - - _skills = await CsvHelper.LoadAsync( - _httpClient, - url, - cols => Map(cols), - s => s.SkillId - ); - - ValidateSkills(); - - _logger.LogInformation( - "Skill definitions loaded successfully. Count: {Count}", - _skills.Count); - } - catch (Exception ex) - { - _logger.LogError(ex, "Failed to load skill definitions"); - throw; - } - } - - public async Task StopAsync(CancellationToken cancellationToken) - { - await Task.CompletedTask; - } - - private static SkillData Map(string[] cols) - { - // 0: SkillId - // 1: SkillName - // 2: SkillType - // 3: CoolTime - // 4: ScalingType - // 5: TargetType - - return new SkillData( - - int.Parse(cols[0]), - cols[1], - - CsvHelper.ParseEnum(cols[2], "SkillType"), - float.Parse(cols[3]), - - CsvHelper.ParseEnum(cols[4], "ScalingType"), - CsvHelper.ParseEnum(cols[5], "TargetType") - ); - } - - private void ValidateSkills() - { - foreach (var skill in _skills.Values) - { - if (skill.SkillId <= 0) - throw new InvalidOperationException("SkillId must be greater than 0"); - - if (skill.CoolTime < 0) - throw new InvalidOperationException( - $"Invalid CoolTime for SkillId={skill.SkillId}"); - - if (skill.SkillType == SkillType.Support && - skill.TargetType == SkillTargetType.Enemy) - { - throw new InvalidOperationException( - $"Support skill cannot target enemy. SkillId={skill.SkillId}"); - } - } - } -} \ No newline at end of file