From 0a78489572edfb571c0c283eb09f4ae0b971b7ee Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 13:30:09 -0300 Subject: [PATCH 1/9] Implemetation of character logic --- .../Controllers/Account/AccountController.cs | 1 + .../Characters/CharacterController.cs | 57 ++++++++++++++ .../CharacterDependenciesExtension.cs | 26 +++++++ 0.Api/ROAPI.Api/Mappings/CharacterMapping.cs | 58 ++++++++++++++ .../Models/Character/CharacterModel.cs | 75 ++++++++++++++++++ .../ROAPI.Api/Properties/launchSettings.json | 2 +- 0.Api/ROAPI.Api/ROAPI.Api.csproj | 5 +- 0.Api/ROAPI.Api/Startup.cs | 6 +- .../Mappings/AccountMapp.cs | 10 --- .../Dtos/CharacterDto.cs | 74 ++++++++++++++++++ .../Interfaces/ICharacterService.cs | 17 +++++ .../ROAPI.Application.Character.csproj | 19 +++++ .../Services/CharacterService.cs | 53 +++++++++++++ .../Repositories/ICharacterRepository.cs | 12 +++ .../ROAPI.Domain.Character.csproj | 15 ++++ .../Repositories/CharacterRepository.cs | 15 ++++ .../ROAPI.Data.Data/Contexts/BaseDbContext.cs | 7 -- .../ROAPI.Data.Data/Contexts/MainDbContext.cs | 4 + .../Entities/Character/CharRegNumEntity.cs | 14 ++++ .../Entities/Character/CharRegStrEntity.cs | 14 ++++ .../Entities/Character/CharacterEntity.cs | 76 +++++++++++++++++++ .../Entities/Character/InventoryEntity.cs | 44 +++++++++++ .../Entities/Character/MemoEntity.cs | 17 +++++ .../Entities/Character/PartyEntity.cs | 18 +++++ .../Entities/Character/PetEntity.cs | 25 ++++++ .../Entities/Character/QuestEntity.cs | 17 +++++ .../Entities/Character/SkillCooldownEntity.cs | 14 ++++ .../Entities/Character/SkillEntity.cs | 14 ++++ .../Character/SkillHomunculusEntity.cs | 13 ++++ .../Entities/Character/VendingItemsEntity.cs | 15 ++++ .../Entities/Character/VendingsEntity.cs | 24 ++++++ .../Extensions/QueryableExtension.cs | 42 ++++++++++ ROAPI.sln | 14 ++++ 33 files changed, 794 insertions(+), 23 deletions(-) create mode 100644 0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs create mode 100644 0.Api/ROAPI.Api/Extensions/Depencies/CharacterDependenciesExtension.cs create mode 100644 0.Api/ROAPI.Api/Mappings/CharacterMapping.cs create mode 100644 0.Api/ROAPI.Api/Models/Character/CharacterModel.cs delete mode 100644 1.Application/ROAPI.Application.Account/Mappings/AccountMapp.cs create mode 100644 1.Application/ROAPI.Application.Character/Dtos/CharacterDto.cs create mode 100644 1.Application/ROAPI.Application.Character/Interfaces/ICharacterService.cs create mode 100644 1.Application/ROAPI.Application.Character/ROAPI.Application.Character.csproj create mode 100644 1.Application/ROAPI.Application.Character/Services/CharacterService.cs create mode 100644 2.Domain/ROAPI.Domain.Character/Contracts/Repositories/ICharacterRepository.cs create mode 100644 2.Domain/ROAPI.Domain.Character/ROAPI.Domain.Character.csproj create mode 100644 2.Domain/ROAPI.Domain.Character/Repositories/CharacterRepository.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharRegNumEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharRegStrEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharacterEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/InventoryEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/MemoEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/PartyEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/PetEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/QuestEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillCooldownEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillHomunculusEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/VendingItemsEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/VendingsEntity.cs create mode 100644 3.Infrastructure/Data/ROAPI.Data.Data/Extensions/QueryableExtension.cs diff --git a/0.Api/ROAPI.Api/Controllers/Account/AccountController.cs b/0.Api/ROAPI.Api/Controllers/Account/AccountController.cs index 9a731e9..6871dcd 100644 --- a/0.Api/ROAPI.Api/Controllers/Account/AccountController.cs +++ b/0.Api/ROAPI.Api/Controllers/Account/AccountController.cs @@ -139,6 +139,7 @@ private async Task GenerateToken( new[] { new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N")), new Claim("user", login), + new Claim("accountId", account.account_id.ToString()), new Claim(ClaimTypes.Role, account.group_id.ToString()) } ); diff --git a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs new file mode 100644 index 0000000..2427fad --- /dev/null +++ b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using AutoMapper; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using ROAPI.Api.Models.Character; +using ROAPI.Application.Character.Interfaces; + +namespace ROAPI.Api.Controllers.Characters +{ + //[Authorize("Bearer")] + [Route("api/[controller]")] + [ApiController] + public class CharacterController : ControllerBase + { + private readonly ICharacterService _characterService; + private readonly IMapper _mapper; + + public CharacterController(ICharacterService characterService, IMapper mapper) + { + _characterService = characterService; + _mapper = mapper; + } + + [HttpGet("getcharbyaccountid/{:accountId}")] + public async Task> GetByAccountId([FromBody]int accountId) + { + return Ok(); + } + [HttpGet("getcharbyid/{:id}")] + public async Task> GetByCharId([FromBody]int charId) + { + return Ok(); + } + [HttpGet("GetChars")] + public async Task>> GetChars() + { + /*var identity = HttpContext.User.Identity as ClaimsIdentity; + int accountId; + int.TryParse(identity.Claims.Where(s => s.Type.ToLower() == "accountid").FirstOrDefault()?.Value, out accountId); + if (accountId == 0) + return NotFound();*/ + var characters = await _characterService.GetCharsByAccountId(2000000, 1, 10); + return Ok(_mapper.Map>(characters)); + } + [HttpGet("GetList")] + [Authorize(Roles = "99")] + public async Task>> GetList() + { + return Ok(); + } + } +} \ No newline at end of file diff --git a/0.Api/ROAPI.Api/Extensions/Depencies/CharacterDependenciesExtension.cs b/0.Api/ROAPI.Api/Extensions/Depencies/CharacterDependenciesExtension.cs new file mode 100644 index 0000000..0592417 --- /dev/null +++ b/0.Api/ROAPI.Api/Extensions/Depencies/CharacterDependenciesExtension.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.DependencyInjection; +using ROAPI.Application.Character.Interfaces; +using ROAPI.Application.Character.Services; +using ROAPI.Domain.Character.Contracts.Repositories; +using ROAPI.Domain.Character.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace ROAPI.Api.Extensions.Depencies +{ + public static class CharacterDependenciesExtension + { + public static IServiceCollection AddCharacterDependencies(this IServiceCollection services) + { + //Domain + services.AddTransient(); + + //Application + services.AddScoped(); + + return services; + } + } +} diff --git a/0.Api/ROAPI.Api/Mappings/CharacterMapping.cs b/0.Api/ROAPI.Api/Mappings/CharacterMapping.cs new file mode 100644 index 0000000..0bc98fb --- /dev/null +++ b/0.Api/ROAPI.Api/Mappings/CharacterMapping.cs @@ -0,0 +1,58 @@ +using AutoMapper; +using ROAPI.Api.Models.Character; +using ROAPI.Application.Character.Dtos; +using ROAPI.Data.Data.Entities.Character; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace ROAPI.Api.Mappings +{ + public class CharacterMapping:Profile + { + public CharacterMapping() + { + CreateMap() + .ReverseMap(); + CreateMap() + .ForMember(dest => dest.account_id, opt => opt.MapFrom(src => src.accountId)) + .ForMember(dest => dest.char_id, opt => opt.MapFrom(src => src.charId)) + .ForMember(dest => dest.char_num, opt => opt.MapFrom(src => src.charNum)) + .ForMember(dest => dest.base_exp, opt => opt.MapFrom(src => src.baseExp)) + .ForMember(dest => dest.base_level, opt => opt.MapFrom(src => src.baseLevel)) + .ForMember(dest => dest.clan_id, opt => opt.MapFrom(src => src.clanId)) + .ForMember(dest => dest.clothes_color, opt => opt.MapFrom(src => src.clothesColor)) + .ForMember(dest => dest.delete_date, opt => opt.MapFrom(src => src.deleteDate)) + .ForMember(dest => dest.elemental_id, opt => opt.MapFrom(src => src.elementalId)) + .ForMember(dest => dest.guild_id, opt => opt.MapFrom(src => src.guildId)) + .ForMember(dest => dest.hair_color, opt => opt.MapFrom(src => src.hairColor)) + .ForMember(dest => dest.head_bottom, opt => opt.MapFrom(src => src.headBottom)) + .ForMember(dest => dest.head_mid, opt => opt.MapFrom(src => src.headMid)) + .ForMember(dest => dest.head_top, opt => opt.MapFrom(src => src.headTop)) + .ForMember(dest => dest.homun_id, opt => opt.MapFrom(src => src.homunId)) + .ForMember(dest => dest.hotkey_rowshift, opt => opt.MapFrom(src => src.hotkeyRowshift)) + .ForMember(dest => dest.job_exp, opt => opt.MapFrom(src => src.jobExp)) + .ForMember(dest => dest.job_level, opt => opt.MapFrom(src => src.jobLevel)) + .ForMember(dest => dest.last_login, opt => opt.MapFrom(src => src.lastLogin)) + .ForMember(dest => dest.last_map, opt => opt.MapFrom(src => src.lastMap)) + .ForMember(dest => dest.last_x, opt => opt.MapFrom(src => src.lastX)) + .ForMember(dest => dest.last_y, opt => opt.MapFrom(src => src.lastY)) + .ForMember(dest => dest.max_hp, opt => opt.MapFrom(src => src.maxHp)) + .ForMember(dest => dest.max_sp, opt => opt.MapFrom(src => src.maxSp)) + .ForMember(dest => dest.partner_id, opt => opt.MapFrom(src => src.partnerId)) + .ForMember(dest => dest.party_id, opt => opt.MapFrom(src => src.partyId)) + .ForMember(dest => dest.pet_id, opt => opt.MapFrom(src => src.petId)) + .ForMember(dest => dest.save_map, opt => opt.MapFrom(src => src.saveMap)) + .ForMember(dest => dest.save_x, opt => opt.MapFrom(src => src.saveX)) + .ForMember(dest => dest.save_y, opt => opt.MapFrom(src => src.saveY)) + .ForMember(dest => dest.show_equip, opt => opt.MapFrom(src => src.showEquip)) + .ForMember(dest => dest.skill_point, opt => opt.MapFrom(src => src.skillPoint)) + .ForMember(dest => dest.status_point, opt => opt.MapFrom(src => src.statusPoint)) + .ForMember(dest => dest.title_id, opt => opt.MapFrom(src => src.titleId)) + .ForMember(dest => dest.unban_time, opt => opt.MapFrom(src => src.unbanTime)) + .ForMember(dest => dest.uniqueitem_counter, opt => opt.MapFrom(src => src.uniqueitemCounter)) + .ReverseMap(); + } + } +} diff --git a/0.Api/ROAPI.Api/Models/Character/CharacterModel.cs b/0.Api/ROAPI.Api/Models/Character/CharacterModel.cs new file mode 100644 index 0000000..8f01ed0 --- /dev/null +++ b/0.Api/ROAPI.Api/Models/Character/CharacterModel.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace ROAPI.Api.Models.Character +{ + public class CharacterModel + { + public int CharId { get; set; } + public int AccountId { get; set; } + public int CharNum { get; set; } + public string Name { get; set; } + public int Class { get; set; } + public int BaseLevel { get; set; } + public int JobLevel { get; set; } + public long BaseExp { get; set; } + public long JobExp { get; set; } + public long Zeny { get; set; } + public int Str { get; set; } + public int Agi { get; set; } + public int Vit { get; set; } + public int Int { get; set; } + public int Dex { get; set; } + public int Luk { get; set; } + public int MaxHp { get; set; } + public int Hp { get; set; } + public int MaxSp { get; set; } + public int Sp { get; set; } + public int StatusPoint { get; set; } + public int SkillPoint { get; set; } + public int Option { get; set; } + public int Karma { get; set; } + public int Manner { get; set; } + public int PartyId { get; set; } + public int GuildId { get; set; } + public int PetId { get; set; } + public int HomunId { get; set; } + public int ElementalId { get; set; } + public int Hair { get; set; } + public int HairColor { get; set; } + public int ClothesColor { get; set; } + public int Body { get; set; } + public int Weapon { get; set; } + public int Shield { get; set; } + public int HeadTop { get; set; } + public int HeadMid { get; set; } + public int HeadBottom { get; set; } + public int Robe { get; set; } + public string LastMap { get; set; } + public int LastX { get; set; } + public int LastY { get; set; } + public string SaveMap { get; set; } + public int SaveX { get; set; } + public int SaveY { get; set; } + public int PartnerId { get; set; } + public int Online { get; set; } + public int Father { get; set; } + public int Mother { get; set; } + public int Child { get; set; } + public int Fame { get; set; } + public int Rename { get; set; } + public int DeleteDate { get; set; } + public int Moves { get; set; } + public int UnbanTime { get; set; } + public int Font { get; set; } + public int UniqueitemCounter { get; set; } + public string Sex { get; set; } + public int HotkeyRowshift { get; set; } + public int ClanId { get; set; } + public DateTime? LastLogin { get; set; } + public int TitleId { get; set; } + public int ShowEquip { get; set; } + } +} diff --git a/0.Api/ROAPI.Api/Properties/launchSettings.json b/0.Api/ROAPI.Api/Properties/launchSettings.json index f18252a..4d4bec1 100644 --- a/0.Api/ROAPI.Api/Properties/launchSettings.json +++ b/0.Api/ROAPI.Api/Properties/launchSettings.json @@ -20,7 +20,7 @@ "Api": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "api/values", + "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, diff --git a/0.Api/ROAPI.Api/ROAPI.Api.csproj b/0.Api/ROAPI.Api/ROAPI.Api.csproj index 6057626..0d779de 100644 --- a/0.Api/ROAPI.Api/ROAPI.Api.csproj +++ b/0.Api/ROAPI.Api/ROAPI.Api.csproj @@ -20,12 +20,9 @@ - - - - + diff --git a/0.Api/ROAPI.Api/Startup.cs b/0.Api/ROAPI.Api/Startup.cs index 515d40e..1532286 100644 --- a/0.Api/ROAPI.Api/Startup.cs +++ b/0.Api/ROAPI.Api/Startup.cs @@ -53,10 +53,14 @@ public void ConfigureServices(IServiceCollection services) services.AddSwaggerServices(); services.AddConnectionDbService(Configuration); services.AddAutoMapper(typeof(Startup)); + services.AddGlobalExceptionHandlerMiddleware(); + + //Dependencies services.AddAccountDependencies(); + services.AddCharacterDependencies(); + services.AddConfigurationDependencies(); services.AddSystemDependencies(); - services.AddGlobalExceptionHandlerMiddleware(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/1.Application/ROAPI.Application.Account/Mappings/AccountMapp.cs b/1.Application/ROAPI.Application.Account/Mappings/AccountMapp.cs deleted file mode 100644 index 078e3dc..0000000 --- a/1.Application/ROAPI.Application.Account/Mappings/AccountMapp.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace ROAPI.Application.Account.Mappings -{ - class AccountMapp - { - } -} diff --git a/1.Application/ROAPI.Application.Character/Dtos/CharacterDto.cs b/1.Application/ROAPI.Application.Character/Dtos/CharacterDto.cs new file mode 100644 index 0000000..c1410d8 --- /dev/null +++ b/1.Application/ROAPI.Application.Character/Dtos/CharacterDto.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Application.Character.Dtos +{ + public class CharacterDto + { + public int charId { get; set; } + public int accountId { get; set; } + public int charNum { get; set; } + public string name { get; set; } + public int @class { get; set; } + public int baseLevel { get; set; } + public int jobLevel { get; set; } + public long baseExp { get; set; } + public long jobExp { get; set; } + public int zeny { get; set; } + public int str { get; set; } + public int agi { get; set; } + public int vit { get; set; } + public int @int { get; set; } + public int dex { get; set; } + public int luk { get; set; } + public int maxHp { get; set; } + public int hp { get; set; } + public int maxSp { get; set; } + public int sp { get; set; } + public int statusPoint { get; set; } + public int skillPoint { get; set; } + public int option { get; set; } + public int karma { get; set; } + public int manner { get; set; } + public int partyId { get; set; } + public int guildId { get; set; } + public int petId { get; set; } + public int homunId { get; set; } + public int elementalId { get; set; } + public int hair { get; set; } + public int hairColor { get; set; } + public int clothesColor { get; set; } + public int body { get; set; } + public int weapon { get; set; } + public int shield { get; set; } + public int headTop { get; set; } + public int headMid { get; set; } + public int headBottom { get; set; } + public int robe { get; set; } + public string lastMap { get; set; } + public int lastX { get; set; } + public int lastY { get; set; } + public string saveMap { get; set; } + public int saveX { get; set; } + public int saveY { get; set; } + public int partnerId { get; set; } + public int online { get; set; } + public int father { get; set; } + public int mother { get; set; } + public int child { get; set; } + public int fame { get; set; } + public int rename { get; set; } + public int deleteDate { get; set; } + public int moves { get; set; } + public int unbanTime { get; set; } + public int font { get; set; } + public int uniqueitemCounter { get; set; } + public string sex { get; set; } + public int hotkeyRowshift { get; set; } + public int clanId { get; set; } + public DateTime? lastLogin { get; set; } + public int titleId { get; set; } + public int showEquip { get; set; } + } +} diff --git a/1.Application/ROAPI.Application.Character/Interfaces/ICharacterService.cs b/1.Application/ROAPI.Application.Character/Interfaces/ICharacterService.cs new file mode 100644 index 0000000..ba30b4f --- /dev/null +++ b/1.Application/ROAPI.Application.Character/Interfaces/ICharacterService.cs @@ -0,0 +1,17 @@ +using ROAPI.Application.Character.Dtos; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace ROAPI.Application.Character.Interfaces +{ + public interface ICharacterService + { + Task> GetCharsByAccountId(int accountId, int page = 1, int pageSize = 10); + Task> GetCharsByAccountId(int accountId); + Task> GetChars(int page = 1, int pageSize = 10); + Task> GetChars(); + Task GetChar(int charId); + } +} diff --git a/1.Application/ROAPI.Application.Character/ROAPI.Application.Character.csproj b/1.Application/ROAPI.Application.Character/ROAPI.Application.Character.csproj new file mode 100644 index 0000000..5dcca67 --- /dev/null +++ b/1.Application/ROAPI.Application.Character/ROAPI.Application.Character.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.2 + + + + + + + + + + + + + + + diff --git a/1.Application/ROAPI.Application.Character/Services/CharacterService.cs b/1.Application/ROAPI.Application.Character/Services/CharacterService.cs new file mode 100644 index 0000000..c3723b2 --- /dev/null +++ b/1.Application/ROAPI.Application.Character/Services/CharacterService.cs @@ -0,0 +1,53 @@ +using ROAPI.Application.Character.Interfaces; +using ROAPI.Domain.Character.Contracts.Repositories; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using System.Linq; +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using ROAPI.Application.Character.Dtos; +using ROAPI.Data.Data.Extensions; + +namespace ROAPI.Application.Character.Services +{ + public class CharacterService: ICharacterService + { + private readonly ICharacterRepository _characterRepository; + private readonly IMapper _mapper; + + public CharacterService(ICharacterRepository characterRepository, IMapper mapper) + { + _characterRepository = characterRepository; + _mapper = mapper; + } + + public async Task> GetCharsByAccountId(int accountId, int page = 1, int pageSize = 10) + { + var debug = _characterRepository.GetAll().Where(c => c.account_id == accountId).ToSql(); + var characters = await _characterRepository.GetAll().Where(c => c.account_id == accountId).ToListAsync();//.Paged(page, pageSize).ToListAsync(); + return _mapper.Map>(characters); + } + public async Task> GetCharsByAccountId(int accountId) + { + var characters = await _characterRepository.GetAll().Where(c => c.account_id == accountId).ToListAsync(); + return _mapper.Map>(characters); + } + public async Task> GetChars(int page = 1, int pageSize = 10) + { + var characters = await _characterRepository.GetAll().Paged(page, pageSize).ToListAsync(); + return _mapper.Map>(characters); + } + public async Task> GetChars() + { + var characters = await _characterRepository.GetAll().ToListAsync(); + return _mapper.Map>(characters); + } + public async Task GetChar(int charId) + { + var character = await _characterRepository.GetById(charId); + return _mapper.Map(character); + } + } +} diff --git a/2.Domain/ROAPI.Domain.Character/Contracts/Repositories/ICharacterRepository.cs b/2.Domain/ROAPI.Domain.Character/Contracts/Repositories/ICharacterRepository.cs new file mode 100644 index 0000000..f1eebd6 --- /dev/null +++ b/2.Domain/ROAPI.Domain.Character/Contracts/Repositories/ICharacterRepository.cs @@ -0,0 +1,12 @@ +using ROAPI.Data.Data.Entities.Character; +using ROAPI.Infrastructure.Data.Data.Interfaces.Repositories; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Domain.Character.Contracts.Repositories +{ + public interface ICharacterRepository:IBaseRepository + { + } +} diff --git a/2.Domain/ROAPI.Domain.Character/ROAPI.Domain.Character.csproj b/2.Domain/ROAPI.Domain.Character/ROAPI.Domain.Character.csproj new file mode 100644 index 0000000..9ac1b4f --- /dev/null +++ b/2.Domain/ROAPI.Domain.Character/ROAPI.Domain.Character.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.2 + + + + + + + + + + + diff --git a/2.Domain/ROAPI.Domain.Character/Repositories/CharacterRepository.cs b/2.Domain/ROAPI.Domain.Character/Repositories/CharacterRepository.cs new file mode 100644 index 0000000..f56a493 --- /dev/null +++ b/2.Domain/ROAPI.Domain.Character/Repositories/CharacterRepository.cs @@ -0,0 +1,15 @@ +using ROAPI.Data.Data.Entities.Character; +using ROAPI.Domain.Character.Contracts.Repositories; +using ROAPI.Infrastructure.Data.Data.Contexts; +using ROAPI.Infrastructure.Data.Data.Repositories; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Domain.Character.Repositories +{ + public class CharacterRepository:BaseRepository, ICharacterRepository + { + public CharacterRepository(MainDbContext context) : base(context) { } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Contexts/BaseDbContext.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Contexts/BaseDbContext.cs index 3ff1443..291bdb8 100644 --- a/3.Infrastructure/Data/ROAPI.Data.Data/Contexts/BaseDbContext.cs +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Contexts/BaseDbContext.cs @@ -11,12 +11,5 @@ public abstract class BaseContext : DbContext public BaseContext(DbContextOptions options) : base(options) { } - - #region [Main Dbs] - public DbSet Login { get; set; } - #endregion - - #region [Log Dbs] - #endregion } } diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Contexts/MainDbContext.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Contexts/MainDbContext.cs index 11c861c..7c240b0 100644 --- a/3.Infrastructure/Data/ROAPI.Data.Data/Contexts/MainDbContext.cs +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Contexts/MainDbContext.cs @@ -1,9 +1,13 @@ using Microsoft.EntityFrameworkCore; +using ROAPI.Data.Data.Entities.Account; +using ROAPI.Data.Data.Entities.Character; namespace ROAPI.Infrastructure.Data.Data.Contexts { public class MainDbContext : BaseContext { public MainDbContext(DbContextOptions options) : base(options) { } + public DbSet Login { get; set; } + public DbSet Char { get; set; } } } diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharRegNumEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharRegNumEntity.cs new file mode 100644 index 0000000..d09acc4 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharRegNumEntity.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + class CharRegNumEntity + { + public int char_id { get; set; } + public string key { get; set; } + public int index { get; set; } + public long value { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharRegStrEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharRegStrEntity.cs new file mode 100644 index 0000000..a1d2fb5 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharRegStrEntity.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class CharRegStrEntity + { + public int char_id { get; set; } + public string key { get; set; } + public int index { get; set; } + public string value { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharacterEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharacterEntity.cs new file mode 100644 index 0000000..dbd7218 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharacterEntity.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class CharacterEntity + { + [Key] + public int char_id { get; set; } + public int account_id { get; set; } + public bool char_num { get; set; } + public string name { get; set; } + public int @class { get; set; } + public int base_level { get; set; } + public int job_level { get; set; } + public long base_exp { get; set; } + public long job_exp { get; set; } + public int zeny { get; set; } + public int str { get; set; } + public int agi { get; set; } + public int vit { get; set; } + public int @int { get; set; } + public int dex { get; set; } + public int luk { get; set; } + public int max_hp { get; set; } + public int hp { get; set; } + public int max_sp { get; set; } + public int sp { get; set; } + public int status_point { get; set; } + public int skill_point { get; set; } + public int option { get; set; } + public bool karma { get; set; } + public int manner { get; set; } + public int party_id { get; set; } + public int guild_id { get; set; } + public int pet_id { get; set; } + public int homun_id { get; set; } + public int elemental_id { get; set; } + public bool hair { get; set; } + public int hair_color { get; set; } + public int clothes_color { get; set; } + public int body { get; set; } + public int weapon { get; set; } + public int shield { get; set; } + public int head_top { get; set; } + public int head_mid { get; set; } + public int head_bottom { get; set; } + public int robe { get; set; } + public string last_map { get; set; } + public int last_x { get; set; } + public int last_y { get; set; } + public string save_map { get; set; } + public int save_x { get; set; } + public int save_y { get; set; } + public int partner_id { get; set; } + public bool online { get; set; } + public int father { get; set; } + public int mother { get; set; } + public int child { get; set; } + public int fame { get; set; } + public int rename { get; set; } + public int delete_date { get; set; } + public int moves { get; set; } + public int unban_time { get; set; } + public bool font { get; set; } + public int uniqueitem_counter { get; set; } + public string sex { get; set; } + public bool hotkey_rowshift { get; set; } + public int clan_id { get; set; } + public DateTime? last_login { get; set; } + public int title_id { get; set; } + public bool show_equip { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/InventoryEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/InventoryEntity.cs new file mode 100644 index 0000000..1f3a0b7 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/InventoryEntity.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class InventoryEntity + { + [Key] + public int id { get; set; } + public int char_id { get; set; } + public int nameid { get; set; } + public int amount { get; set; } + public int equip { get; set; } + public int identify { get; set; } + public int refine { get; set; } + public int attribute { get; set; } + public int card0 { get; set; } + public int card1 { get; set; } + public int card2 { get; set; } + public int card3 { get; set; } + public int option_id0 { get; set; } + public int option_val0 { get; set; } + public int option_parm0 { get; set; } + public int option_id1 { get; set; } + public int option_val1 { get; set; } + public int option_parm1 { get; set; } + public int option_id2 { get; set; } + public int option_val2 { get; set; } + public int option_parm2 { get; set; } + public int option_id3 { get; set; } + public int option_val3 { get; set; } + public int option_parm3 { get; set; } + public int option_id4 { get; set; } + public int option_val4 { get; set; } + public int option_parm4 { get; set; } + public int expire_time { get; set; } + public int favorite { get; set; } + public int bound { get; set; } + public long unique_id { get; set; } + public int equip_switch { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/MemoEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/MemoEntity.cs new file mode 100644 index 0000000..35736ce --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/MemoEntity.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class MemoEntity + { + [Key] + public int memo_id { get; set; } + public int char_id { get; set; } + public string map { get; set; } + public int x { get; set; } + public int y { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/PartyEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/PartyEntity.cs new file mode 100644 index 0000000..fe0228d --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/PartyEntity.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class PartyEntity + { + [Key] + public int party_id { get; set; } + public string name { get; set; } + public int exp { get; set; } + public int item { get; set; } + public int leader_id { get; set; } + public int leader_char { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/PetEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/PetEntity.cs new file mode 100644 index 0000000..a7e4c67 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/PetEntity.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class PetEntity + { + [Key] + public int pet_id { get; set; } + public int @class { get; set; } + public string name { get; set; } + public int account_id { get; set; } + public int char_id { get; set; } + public int level { get; set; } + public int egg_id { get; set; } + public int equip { get; set; } + public int intimate { get; set; } + public int hungry { get; set; } + public int rename_flag { get; set; } + public int incubate { get; set; } + public int autofeed { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/QuestEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/QuestEntity.cs new file mode 100644 index 0000000..d08a414 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/QuestEntity.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class QuestEntity + { + public int char_id { get; set; } + public int quest_id { get; set; } + public int state { get; set; } + public int time { get; set; } + public int count1 { get; set; } + public int count2 { get; set; } + public int count3 { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillCooldownEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillCooldownEntity.cs new file mode 100644 index 0000000..7688572 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillCooldownEntity.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class SkillCooldownEntity + { + public int account_id { get; set; } + public int char_id { get; set; } + public int skill { get; set; } + public long tick { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillEntity.cs new file mode 100644 index 0000000..460dfaa --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillEntity.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class SkillEntity + { + public int char_id { get; set; } + public int id { get; set; } + public int lv { get; set; } + public int flag { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillHomunculusEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillHomunculusEntity.cs new file mode 100644 index 0000000..4034658 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/SkillHomunculusEntity.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class SkillHomunculusEntity + { + public int homun_id { get; set; } + public int id { get; set; } + public int lv { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/VendingItemsEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/VendingItemsEntity.cs new file mode 100644 index 0000000..8b3266f --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/VendingItemsEntity.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class VendingItemsEntity + { + public int vending_id { get; set; } + public int index { get; set; } + public int cartinventory_id { get; set; } + public int amount { get; set; } + public int price { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/VendingsEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/VendingsEntity.cs new file mode 100644 index 0000000..db28cf9 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/VendingsEntity.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace ROAPI.Data.Data.Entities.Character +{ + public class VendingsEntity + { + [Key] + public int id { get; set; } + public int account_id { get; set; } + public int char_id { get; set; } + public string sex { get; set; } + public string map { get; set; } + public int x { get; set; } + public int y { get; set; } + public string title { get; set; } + public char body_direction { get; set; } + public char head_direction { get; set; } + public char sit { get; set; } + public int autotrade { get; set; } + } +} diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Extensions/QueryableExtension.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Extensions/QueryableExtension.cs new file mode 100644 index 0000000..e74d694 --- /dev/null +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Extensions/QueryableExtension.cs @@ -0,0 +1,42 @@ +using System.Linq; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Query; +using Microsoft.EntityFrameworkCore.Query.Internal; +using Microsoft.EntityFrameworkCore.Query.Expressions; +using Microsoft.EntityFrameworkCore.Query.Sql; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; +//using Microsoft.EntityFrameworkCore.Storage; + +namespace ROAPI.Data.Data.Extensions +{ + public static class QueryableExtension + { + private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo(); + + private static readonly FieldInfo QueryCompilerField = typeof(EntityQueryProvider).GetTypeInfo().DeclaredFields.First(x => x.Name == "_queryCompiler"); + private static readonly FieldInfo QueryModelGeneratorField = typeof(QueryCompiler).GetTypeInfo().DeclaredFields.First(x => x.Name == "_queryModelGenerator"); + private static readonly FieldInfo DataBaseField = QueryCompilerTypeInfo.DeclaredFields.Single(x => x.Name == "_database"); + private static readonly PropertyInfo DatabaseDependenciesField = typeof(Microsoft.EntityFrameworkCore.Storage.Database).GetTypeInfo().DeclaredProperties.Single(x => x.Name == "Dependencies"); + + public static string ToSql(this IQueryable query) + { + var queryCompiler = (QueryCompiler)QueryCompilerField.GetValue(query.Provider); + var queryModelGenerator = (QueryModelGenerator)QueryModelGeneratorField.GetValue(queryCompiler); + var queryModel = queryModelGenerator.ParseQuery(query.Expression); + var database = DataBaseField.GetValue(queryCompiler); + var databaseDependencies = (Microsoft.EntityFrameworkCore.Storage.DatabaseDependencies)DatabaseDependenciesField.GetValue(database); + var queryCompilationContext = databaseDependencies.QueryCompilationContextFactory.Create(false); + var modelVisitor = (RelationalQueryModelVisitor)queryCompilationContext.CreateQueryModelVisitor(); + modelVisitor.CreateQueryExecutor(queryModel); + var sql = modelVisitor.Queries.First().ToString(); + + return sql; + } + public static IQueryable Paged(this IQueryable source, int page, int pageSize) + { + return source + .Skip((page - 1) * pageSize) + .Take(pageSize); + } + } +} diff --git a/ROAPI.sln b/ROAPI.sln index 62a7e30..1685433 100644 --- a/ROAPI.sln +++ b/ROAPI.sln @@ -25,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RPAPI.Domain.Common", "2.Do EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ROAPI.Application.Common", "1.Application\ROAPI.Application.Common\ROAPI.Application.Common.csproj", "{6D103010-D056-4A2A-91D6-A1C734927289}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ROAPI.Domain.Character", "2.Domain\ROAPI.Domain.Character\ROAPI.Domain.Character.csproj", "{74EF6F8B-C568-434C-9D5F-E1CE3E4F4E2B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ROAPI.Application.Character", "1.Application\ROAPI.Application.Character\ROAPI.Application.Character.csproj", "{F585D008-9F72-4F2A-98A7-8359BA93EFB1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +59,14 @@ Global {6D103010-D056-4A2A-91D6-A1C734927289}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D103010-D056-4A2A-91D6-A1C734927289}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D103010-D056-4A2A-91D6-A1C734927289}.Release|Any CPU.Build.0 = Release|Any CPU + {74EF6F8B-C568-434C-9D5F-E1CE3E4F4E2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74EF6F8B-C568-434C-9D5F-E1CE3E4F4E2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74EF6F8B-C568-434C-9D5F-E1CE3E4F4E2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74EF6F8B-C568-434C-9D5F-E1CE3E4F4E2B}.Release|Any CPU.Build.0 = Release|Any CPU + {F585D008-9F72-4F2A-98A7-8359BA93EFB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F585D008-9F72-4F2A-98A7-8359BA93EFB1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F585D008-9F72-4F2A-98A7-8359BA93EFB1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F585D008-9F72-4F2A-98A7-8359BA93EFB1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -67,6 +79,8 @@ Global {CB9C7D7D-7547-4D5B-B0CA-51A5002653D6} = {63BA2177-E944-4DB0-8C8D-733F97ADD16D} {938827FB-876A-4704-AE8E-E5CFD1C21CE6} = {63BA2177-E944-4DB0-8C8D-733F97ADD16D} {6D103010-D056-4A2A-91D6-A1C734927289} = {1512328E-00C5-496C-844A-DE5511FA8D1B} + {74EF6F8B-C568-434C-9D5F-E1CE3E4F4E2B} = {63BA2177-E944-4DB0-8C8D-733F97ADD16D} + {F585D008-9F72-4F2A-98A7-8359BA93EFB1} = {1512328E-00C5-496C-844A-DE5511FA8D1B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {9E3D5474-E888-4203-A1B2-2B3B53595ED4} From dc886c6affcc15a651f54c910e5c7807f98b2a8b Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 13:47:46 -0300 Subject: [PATCH 2/9] Fix in some variables for dev env --- 0.Api/ROAPI.Api/appsettings.Development.json | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/0.Api/ROAPI.Api/appsettings.Development.json b/0.Api/ROAPI.Api/appsettings.Development.json index 85d582e..c6d86d2 100644 --- a/0.Api/ROAPI.Api/appsettings.Development.json +++ b/0.Api/ROAPI.Api/appsettings.Development.json @@ -1,8 +1,8 @@ { "ConnectionStrings": { - "MainConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True", - "LogConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True", - "ConexaoRedis": "localhost,port: 6379" + "MainConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true", + "LogConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true", + "CacheConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true" }, "Logging": { "LogLevel": { @@ -10,5 +10,22 @@ "System": "Information", "Microsoft": "Information" } + }, + "TokenConfigurations": { + "Audience": "ROAPI", + "Issuer": "ROAPI", + //Token expiration in seconds + "TokenExpiration": 3600, + //Refresh Token Expiration in seconds + "RefreshTokenExpiration": 7200 + }, + "CacheConfiguration": { + //Db name where the cache table was created + "Schema": "ragnarok", + //Table name + "Table": "cache" + }, + "RagnarokConfigurations": { + "UseMd5Pass": true } } From afdf43bfcc0834f0fa0da9ebd9f826411ebf327b Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 14:26:05 -0300 Subject: [PATCH 3/9] Fix for character fields, MySQL tinyint has to be considered as int for easier manipulation TODO: Need to fix the fields that should be bool --- .../ROAPI.Api/Models/Character/CharacterModel.cs | 2 +- 0.Api/ROAPI.Api/appsettings.Development.json | 6 +++--- .../Dtos/CharacterDto.cs | 2 +- .../Entities/Character/CharacterEntity.cs | 16 ++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/0.Api/ROAPI.Api/Models/Character/CharacterModel.cs b/0.Api/ROAPI.Api/Models/Character/CharacterModel.cs index 8f01ed0..564fe49 100644 --- a/0.Api/ROAPI.Api/Models/Character/CharacterModel.cs +++ b/0.Api/ROAPI.Api/Models/Character/CharacterModel.cs @@ -67,7 +67,7 @@ public class CharacterModel public int UniqueitemCounter { get; set; } public string Sex { get; set; } public int HotkeyRowshift { get; set; } - public int ClanId { get; set; } + public int? ClanId { get; set; } public DateTime? LastLogin { get; set; } public int TitleId { get; set; } public int ShowEquip { get; set; } diff --git a/0.Api/ROAPI.Api/appsettings.Development.json b/0.Api/ROAPI.Api/appsettings.Development.json index c6d86d2..8266df6 100644 --- a/0.Api/ROAPI.Api/appsettings.Development.json +++ b/0.Api/ROAPI.Api/appsettings.Development.json @@ -1,8 +1,8 @@ { "ConnectionStrings": { - "MainConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true", - "LogConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true", - "CacheConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true" + "MainConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true;TreatTinyAsBoolean=false", + "LogConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true;TreatTinyAsBoolean=false", + "CacheConnection": "Server=localhost;Database=ragnarok;Uid=ragnarok;Pwd=ragnarok;convert zero datetime=True;Allow User Variables=true;TreatTinyAsBoolean=false" }, "Logging": { "LogLevel": { diff --git a/1.Application/ROAPI.Application.Character/Dtos/CharacterDto.cs b/1.Application/ROAPI.Application.Character/Dtos/CharacterDto.cs index c1410d8..a203309 100644 --- a/1.Application/ROAPI.Application.Character/Dtos/CharacterDto.cs +++ b/1.Application/ROAPI.Application.Character/Dtos/CharacterDto.cs @@ -66,7 +66,7 @@ public class CharacterDto public int uniqueitemCounter { get; set; } public string sex { get; set; } public int hotkeyRowshift { get; set; } - public int clanId { get; set; } + public int? clanId { get; set; } public DateTime? lastLogin { get; set; } public int titleId { get; set; } public int showEquip { get; set; } diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharacterEntity.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharacterEntity.cs index dbd7218..3692e7d 100644 --- a/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharacterEntity.cs +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Entities/Character/CharacterEntity.cs @@ -10,7 +10,7 @@ public class CharacterEntity [Key] public int char_id { get; set; } public int account_id { get; set; } - public bool char_num { get; set; } + public int char_num { get; set; } public string name { get; set; } public int @class { get; set; } public int base_level { get; set; } @@ -31,14 +31,14 @@ public class CharacterEntity public int status_point { get; set; } public int skill_point { get; set; } public int option { get; set; } - public bool karma { get; set; } + public int karma { get; set; } public int manner { get; set; } public int party_id { get; set; } public int guild_id { get; set; } public int pet_id { get; set; } public int homun_id { get; set; } public int elemental_id { get; set; } - public bool hair { get; set; } + public int hair { get; set; } public int hair_color { get; set; } public int clothes_color { get; set; } public int body { get; set; } @@ -55,7 +55,7 @@ public class CharacterEntity public int save_x { get; set; } public int save_y { get; set; } public int partner_id { get; set; } - public bool online { get; set; } + public int online { get; set; } public int father { get; set; } public int mother { get; set; } public int child { get; set; } @@ -64,13 +64,13 @@ public class CharacterEntity public int delete_date { get; set; } public int moves { get; set; } public int unban_time { get; set; } - public bool font { get; set; } + public int font { get; set; } public int uniqueitem_counter { get; set; } public string sex { get; set; } - public bool hotkey_rowshift { get; set; } - public int clan_id { get; set; } + public int hotkey_rowshift { get; set; } + public int? clan_id { get; set; } public DateTime? last_login { get; set; } public int title_id { get; set; } - public bool show_equip { get; set; } + public int show_equip { get; set; } } } From 0c395b6032290e8c54b94fc3c3f748874370f6e2 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 17:01:40 -0300 Subject: [PATCH 4/9] fix for search by id --- .../Interfaces/Repositories/IBaseRepository.cs | 4 ++-- .../Data/ROAPI.Data.Data/Repositories/BaseRepository.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Interfaces/Repositories/IBaseRepository.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Interfaces/Repositories/IBaseRepository.cs index a8bb63b..2f7c587 100644 --- a/3.Infrastructure/Data/ROAPI.Data.Data/Interfaces/Repositories/IBaseRepository.cs +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Interfaces/Repositories/IBaseRepository.cs @@ -9,10 +9,10 @@ namespace ROAPI.Infrastructure.Data.Data.Interfaces.Repositories public interface IBaseRepository : IDisposable where TEntity : class { Task Add(TEntity obj); - Task GetById(long id); + Task GetById(int id); IQueryable GetAll(); TEntity Update(TEntity obj); - void Remove(long id); + void Remove(int id); Task SaveChanges(); } } diff --git a/3.Infrastructure/Data/ROAPI.Data.Data/Repositories/BaseRepository.cs b/3.Infrastructure/Data/ROAPI.Data.Data/Repositories/BaseRepository.cs index ef31af4..db5c738 100644 --- a/3.Infrastructure/Data/ROAPI.Data.Data/Repositories/BaseRepository.cs +++ b/3.Infrastructure/Data/ROAPI.Data.Data/Repositories/BaseRepository.cs @@ -27,11 +27,11 @@ public virtual async Task Add(TEntity obj) return obj; } - public virtual async Task GetById(long id) + public virtual async Task GetById(int id) { - return await DbSet.FindAsync(id); + var obj = await DbSet.FindAsync(id); + return obj; } - public virtual IQueryable GetAll() { return DbSet; @@ -43,7 +43,7 @@ public virtual TEntity Update(TEntity obj) return obj; } - public virtual void Remove(long id) + public virtual void Remove(int id) { DbSet.Remove(DbSet.Find(id)); } From 07019e7eca68456e98de8b1df5c2d3dbf0f0be81 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 17:02:33 -0300 Subject: [PATCH 5/9] Add new method to search with no tracking --- .../Contracts/Repositories/ICharacterRepository.cs | 2 ++ .../Repositories/CharacterRepository.cs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/2.Domain/ROAPI.Domain.Character/Contracts/Repositories/ICharacterRepository.cs b/2.Domain/ROAPI.Domain.Character/Contracts/Repositories/ICharacterRepository.cs index f1eebd6..04b8563 100644 --- a/2.Domain/ROAPI.Domain.Character/Contracts/Repositories/ICharacterRepository.cs +++ b/2.Domain/ROAPI.Domain.Character/Contracts/Repositories/ICharacterRepository.cs @@ -3,10 +3,12 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading.Tasks; namespace ROAPI.Domain.Character.Contracts.Repositories { public interface ICharacterRepository:IBaseRepository { + Task GetByIdNoTracking(int id); } } diff --git a/2.Domain/ROAPI.Domain.Character/Repositories/CharacterRepository.cs b/2.Domain/ROAPI.Domain.Character/Repositories/CharacterRepository.cs index f56a493..30b7e42 100644 --- a/2.Domain/ROAPI.Domain.Character/Repositories/CharacterRepository.cs +++ b/2.Domain/ROAPI.Domain.Character/Repositories/CharacterRepository.cs @@ -5,11 +5,18 @@ using System; using System.Collections.Generic; using System.Text; +using System.Linq; +using Microsoft.EntityFrameworkCore; +using System.Threading.Tasks; namespace ROAPI.Domain.Character.Repositories { public class CharacterRepository:BaseRepository, ICharacterRepository { public CharacterRepository(MainDbContext context) : base(context) { } + public async Task GetByIdNoTracking(int id) + { + return await DbSet.AsNoTracking().Where(c => c.char_id == id).FirstOrDefaultAsync(); + } } } From 835339c0fdd119e5403337b440a9ab61fb955ee9 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 17:03:13 -0300 Subject: [PATCH 6/9] Implementation of update service. --- .../ROAPI.Api/Properties/launchSettings.json | 30 ++++++++ .../Controllers/Account/AccountController.cs | 12 ++-- .../Characters/CharacterController.cs | 68 +++++++++++++++---- .../Extensions/AddConnectionDbExtension.cs | 7 +- .../PublishProfiles/CustomProfile.pubxml | 27 ++++++++ .../Interfaces/ICharacterService.cs | 1 + .../ROAPI.Application.Character.csproj | 6 ++ .../Services/CharacterService.cs | 16 ++++- 8 files changed, 144 insertions(+), 23 deletions(-) create mode 100644 0.API/ROAPI.Api/Properties/launchSettings.json create mode 100644 0.Api/ROAPI.Api/Properties/PublishProfiles/CustomProfile.pubxml diff --git a/0.API/ROAPI.Api/Properties/launchSettings.json b/0.API/ROAPI.Api/Properties/launchSettings.json new file mode 100644 index 0000000..4d4bec1 --- /dev/null +++ b/0.API/ROAPI.Api/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:64767", + "sslPort": 44301 + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Api": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + } + } +} \ No newline at end of file diff --git a/0.Api/ROAPI.Api/Controllers/Account/AccountController.cs b/0.Api/ROAPI.Api/Controllers/Account/AccountController.cs index 6871dcd..fa241de 100644 --- a/0.Api/ROAPI.Api/Controllers/Account/AccountController.cs +++ b/0.Api/ROAPI.Api/Controllers/Account/AccountController.cs @@ -45,9 +45,9 @@ public AccountController(ILoginService loginService, IMapper mapper, IConfigurat _ragnarokConfigurations = configurationService.GetRagnarokConfigurations(); _httpContextAccessor = httpContextAccessor; } - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesErrorResponseType(typeof(AccountModel))] - [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(AccountModel))] + [ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))] + [ProducesResponseType(statusCode: StatusCodes.Status401Unauthorized, type: typeof(Nullable))] [HttpGet] public async Task> Get() { @@ -59,9 +59,8 @@ public async Task> Get() return NotFound(); } - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesErrorResponseType(typeof(AccessTokenModel))] - [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(AccessTokenModel))] + [ProducesResponseType(statusCode: StatusCodes.Status400BadRequest, type: typeof(AccessTokenModel))] [AllowAnonymous] [HttpPost("Login")] public async Task> Login( @@ -115,6 +114,7 @@ public async Task> Login( } } + [ProducesResponseType(StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [AllowAnonymous] diff --git a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs index 2427fad..b17ad4e 100644 --- a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs +++ b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs @@ -6,8 +6,10 @@ using AutoMapper; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.Mvc; using ROAPI.Api.Models.Character; +using ROAPI.Application.Character.Dtos; using ROAPI.Application.Character.Interfaces; namespace ROAPI.Api.Controllers.Characters @@ -25,33 +27,75 @@ public CharacterController(ICharacterService characterService, IMapper mapper) _characterService = characterService; _mapper = mapper; } - - [HttpGet("getcharbyaccountid/{:accountId}")] - public async Task> GetByAccountId([FromBody]int accountId) + [ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(List))] + [ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))] + [HttpGet("Getcharbyaccountid/{accountId}")] + [Authorize(Roles = "99")] + public async Task>> GetByAccountId([FromBody]int accountId) { - return Ok(); + var characters = await _characterService.GetCharsByAccountId(accountId); + if (characters != null) + return Ok(_mapper.Map>(characters)); + else + return NotFound(); } - [HttpGet("getcharbyid/{:id}")] + [ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(CharacterModel))] + [ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))] + [HttpGet("Getcharbyid/{id}")] public async Task> GetByCharId([FromBody]int charId) { - return Ok(); + var character = await _characterService.GetChar(charId); + if (character != null) + return Ok(_mapper.Map(character)); + else + return NotFound(); } + [ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(List))] + [ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))] [HttpGet("GetChars")] - public async Task>> GetChars() + public async Task>> GetChars(bool paged = false, int page = 1, int pageSize = 10) { - /*var identity = HttpContext.User.Identity as ClaimsIdentity; + var identity = HttpContext.User.Identity as ClaimsIdentity; int accountId; int.TryParse(identity.Claims.Where(s => s.Type.ToLower() == "accountid").FirstOrDefault()?.Value, out accountId); if (accountId == 0) - return NotFound();*/ - var characters = await _characterService.GetCharsByAccountId(2000000, 1, 10); + return NotFound(); + var characters = paged? + await _characterService.GetCharsByAccountId(accountId, page, pageSize) : + await _characterService.GetCharsByAccountId(accountId); + return Ok(_mapper.Map>(characters)); } + [ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(List))] + [ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))] [HttpGet("GetList")] [Authorize(Roles = "99")] - public async Task>> GetList() + public async Task>> GetList(bool paged = false, int page = 1, int pageSize = 10) { - return Ok(); + var characters = paged ? + await _characterService.GetChars(page, pageSize) : + await _characterService.GetChars(); + if (characters != null) + return Ok(_mapper.Map>(characters)); + else + return NotFound(); + } + [ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(CharacterModel))] + [ProducesResponseType(statusCode: StatusCodes.Status304NotModified)] + [HttpPatch("Edit/{characterId}")] + public async Task> Patch(int characterId, [FromBody]JsonPatchDocument model) + { + + var actualDto = await _characterService.GetChar(characterId); + if(actualDto == null && actualDto.charId != characterId) + return new StatusCodeResult(304); + var actualModel = _mapper.Map(actualDto); + model.ApplyTo(actualModel); + var result = await _characterService.Updatecharacter(_mapper.Map(actualModel)); + if(result == null) + return new StatusCodeResult(304); + return Ok(_mapper.Map(result)); + } } } \ No newline at end of file diff --git a/0.Api/ROAPI.Api/Extensions/AddConnectionDbExtension.cs b/0.Api/ROAPI.Api/Extensions/AddConnectionDbExtension.cs index 4de835b..d8b9a64 100644 --- a/0.Api/ROAPI.Api/Extensions/AddConnectionDbExtension.cs +++ b/0.Api/ROAPI.Api/Extensions/AddConnectionDbExtension.cs @@ -13,9 +13,12 @@ public static class AddConnectionDbExtension { public static void AddConnectionDbService(this IServiceCollection services, IConfiguration configuration ) { - services.AddDbContext(options => + services.AddDbContext(options => { options.UseMySql( - configuration.GetConnectionString("MainConnection"))); + configuration.GetConnectionString("MainConnection")); + //options.EnableSensitiveDataLogging(); + //options.EnableDetailedErrors(); + }); services.AddDbContext(options => options.UseMySql( configuration.GetConnectionString("LogConnection"))); diff --git a/0.Api/ROAPI.Api/Properties/PublishProfiles/CustomProfile.pubxml b/0.Api/ROAPI.Api/Properties/PublishProfiles/CustomProfile.pubxml new file mode 100644 index 0000000..abd4479 --- /dev/null +++ b/0.Api/ROAPI.Api/Properties/PublishProfiles/CustomProfile.pubxml @@ -0,0 +1,27 @@ + + + + + MSDeploy + Release + Any CPU + luan122-001-site4.atempurl.com/swagger + True + False + netcoreapp2.2 + 3f17e218-9c69-463f-9b9e-c62bde97a03b + false + <_IsPortable>true + https://luan122-001-site4.atempurl.com:8172/MsDeploy.axd?site=luan122-001-site4 + luan122-001-site4 + + False + WMSVC + True + luan122-001 + <_SavePWD>True + + \ No newline at end of file diff --git a/1.Application/ROAPI.Application.Character/Interfaces/ICharacterService.cs b/1.Application/ROAPI.Application.Character/Interfaces/ICharacterService.cs index ba30b4f..7cbea4c 100644 --- a/1.Application/ROAPI.Application.Character/Interfaces/ICharacterService.cs +++ b/1.Application/ROAPI.Application.Character/Interfaces/ICharacterService.cs @@ -13,5 +13,6 @@ public interface ICharacterService Task> GetChars(int page = 1, int pageSize = 10); Task> GetChars(); Task GetChar(int charId); + Task Updatecharacter(CharacterDto dto); } } diff --git a/1.Application/ROAPI.Application.Character/ROAPI.Application.Character.csproj b/1.Application/ROAPI.Application.Character/ROAPI.Application.Character.csproj index 5dcca67..e9b5d55 100644 --- a/1.Application/ROAPI.Application.Character/ROAPI.Application.Character.csproj +++ b/1.Application/ROAPI.Application.Character/ROAPI.Application.Character.csproj @@ -16,4 +16,10 @@ + + + C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.jsonpatch\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.JsonPatch.dll + + + diff --git a/1.Application/ROAPI.Application.Character/Services/CharacterService.cs b/1.Application/ROAPI.Application.Character/Services/CharacterService.cs index c3723b2..4fb7bb7 100644 --- a/1.Application/ROAPI.Application.Character/Services/CharacterService.cs +++ b/1.Application/ROAPI.Application.Character/Services/CharacterService.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore; using ROAPI.Application.Character.Dtos; using ROAPI.Data.Data.Extensions; +using Microsoft.AspNetCore.JsonPatch; +using ROAPI.Data.Data.Entities.Character; namespace ROAPI.Application.Character.Services { @@ -25,8 +27,7 @@ public CharacterService(ICharacterRepository characterRepository, IMapper mapper public async Task> GetCharsByAccountId(int accountId, int page = 1, int pageSize = 10) { - var debug = _characterRepository.GetAll().Where(c => c.account_id == accountId).ToSql(); - var characters = await _characterRepository.GetAll().Where(c => c.account_id == accountId).ToListAsync();//.Paged(page, pageSize).ToListAsync(); + var characters = await _characterRepository.GetAll().Where(c => c.account_id == accountId).Paged(page, pageSize).ToListAsync(); return _mapper.Map>(characters); } public async Task> GetCharsByAccountId(int accountId) @@ -46,8 +47,17 @@ public async Task> GetChars() } public async Task GetChar(int charId) { - var character = await _characterRepository.GetById(charId); + var character = await _characterRepository.GetByIdNoTracking(charId); return _mapper.Map(character); } + public async Task Updatecharacter(CharacterDto dto) + { + var entity = _characterRepository.Update(_mapper.Map(dto)); + var update = await _characterRepository.SaveChanges(); + if (update > 0) + return _mapper.Map(entity); + else + return null; + } } } From bf86720204d7580f6134270acd7981956e427c32 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 17:09:10 -0300 Subject: [PATCH 7/9] Fix for security with bearer --- 0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs index b17ad4e..bc3cd09 100644 --- a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs +++ b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs @@ -14,7 +14,7 @@ namespace ROAPI.Api.Controllers.Characters { - //[Authorize("Bearer")] + [Authorize("Bearer")] [Route("api/[controller]")] [ApiController] public class CharacterController : ControllerBase From fdc973a0880023a63e0a4ebffd92c9b170925308 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 17:21:02 -0300 Subject: [PATCH 8/9] Validation to verify if the logged user is admin and if it's editing their own character --- .../Characters/CharacterController.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs index bc3cd09..3fdeaad 100644 --- a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs +++ b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs @@ -21,9 +21,13 @@ public class CharacterController : ControllerBase { private readonly ICharacterService _characterService; private readonly IMapper _mapper; + private readonly ClaimsIdentity _identity; + private readonly int _accountId; public CharacterController(ICharacterService characterService, IMapper mapper) { + _identity = HttpContext.User.Identity as ClaimsIdentity; + int.TryParse(_identity.Claims.Where(s => s.Type.ToLower() == "accountid").FirstOrDefault()?.Value, out _accountId); _characterService = characterService; _mapper = mapper; } @@ -55,14 +59,11 @@ public async Task> GetByCharId([FromBody]int charId [HttpGet("GetChars")] public async Task>> GetChars(bool paged = false, int page = 1, int pageSize = 10) { - var identity = HttpContext.User.Identity as ClaimsIdentity; - int accountId; - int.TryParse(identity.Claims.Where(s => s.Type.ToLower() == "accountid").FirstOrDefault()?.Value, out accountId); - if (accountId == 0) + if (_accountId == 0) return NotFound(); var characters = paged? - await _characterService.GetCharsByAccountId(accountId, page, pageSize) : - await _characterService.GetCharsByAccountId(accountId); + await _characterService.GetCharsByAccountId(_accountId, page, pageSize) : + await _characterService.GetCharsByAccountId(_accountId); return Ok(_mapper.Map>(characters)); } @@ -87,6 +88,11 @@ public async Task> Patch(int characterId, [FromBody { var actualDto = await _characterService.GetChar(characterId); + if(_identity.Claims.Where(s => s.Type.ToLower() == "roles").FirstOrDefault()?.Value != "99") + { + if (actualDto.accountId != _accountId) + return new StatusCodeResult(StatusCodes.Status401Unauthorized); + } if(actualDto == null && actualDto.charId != characterId) return new StatusCodeResult(304); var actualModel = _mapper.Map(actualDto); From 303491a214a777c35636365e2f1897c95ec4afeb Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 25 Jun 2020 17:28:43 -0300 Subject: [PATCH 9/9] More security when trying to get character information --- .../ROAPI.Api/Controllers/Characters/CharacterController.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs index 3fdeaad..8d6f6ac 100644 --- a/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs +++ b/0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs @@ -49,6 +49,11 @@ public async Task>> GetByAccountId([FromBody]i public async Task> GetByCharId([FromBody]int charId) { var character = await _characterService.GetChar(charId); + if (_identity.Claims.Where(s => s.Type.ToLower() == "roles").FirstOrDefault()?.Value != "99") + { + if (character.accountId != _accountId) + return new StatusCodeResult(StatusCodes.Status401Unauthorized); + } if (character != null) return Ok(_mapper.Map(character)); else