Merge branch 'dev' of git.wmi.amu.edu.pl:s426135/session-companion into SES-157

This commit is contained in:
Karol Górzyński 2021-01-15 18:15:16 +01:00
commit d3f9d79af1
13 changed files with 72949 additions and 4 deletions

View File

@ -35,9 +35,20 @@ namespace SessionCompanion.Database
public virtual DbSet<CharacterWeapon> CharacterWeapons { get; set; } public virtual DbSet<CharacterWeapon> CharacterWeapons { get; set; }
public virtual DbSet<OtherEquipment> OtherEquipment { get; set; } public virtual DbSet<OtherEquipment> OtherEquipment { get; set; }
public virtual DbSet<CharacterOtherEquipment> CharacterOtherEquipment { get; set; } public virtual DbSet<CharacterOtherEquipment> CharacterOtherEquipment { get; set; }
public virtual DbSet<Monster> Monsters { get; set; }
public virtual DbSet<MonsterAction> MonsterActions { get; set; }
public virtual DbSet<MonsterLegendaryAction> MonsterLegendaryActions { get; set; }
public virtual DbSet<MonsterSpecialAbility> MonsterSpecialAbilities { get; set; }
public virtual DbSet<GameAction> GameActions { get; set; }
public virtual DbSet<LegendaryAction> LegendaryActions { get; set; }
public virtual DbSet<SpecialAbility> SpecialAbilities { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public List<SpecialAbility> SpecialAbilitiesList { get; set; }
public List<LegendaryAction> LegendaryActionsList { get; set; }
public List<GameAction> GameActionsList { get; set; }
protected IEnumerable<Weapon> SeedWeapon() protected IEnumerable<Weapon> SeedWeapon()
{ {
const string file = "../SessionCompanion.Database/JsonData/weapons.json"; const string file = "../SessionCompanion.Database/JsonData/weapons.json";
@ -98,6 +109,178 @@ namespace SessionCompanion.Database
} }
return spells; return spells;
} }
protected IEnumerable<SpecialAbility> SeedSpecialAbilities()
{
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
List<SpecialAbility> specAbilities = new List<SpecialAbility>();
using (StreamReader reader = new StreamReader(file))
{
var json = reader.ReadToEnd();
dynamic jabilites = JArray.Parse(json);
int id = 1;
foreach (dynamic item in jabilites)
{
if (item.special_abilities != null)
{
foreach (dynamic sp in item.special_abilities)
{
if (specAbilities.Find(x => x.Name == (string)sp.name) is null)
{
specAbilities.Add(SeedFromJsons.SingleSpecialAbilitySeeder(sp, id));
id++;
}
}
}
}
}
SpecialAbilitiesList = specAbilities;
return specAbilities;
}
protected IEnumerable<GameAction> SeedActions()
{
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
List<GameAction> gameActions = new List<GameAction>();
using (StreamReader reader = new StreamReader(file))
{
var json = reader.ReadToEnd();
dynamic jactions = JArray.Parse(json);
int id = 1;
foreach (dynamic item in jactions)
{
if (item.actions != null)
{
foreach (dynamic a in item.actions)
{
if (gameActions.Find(x => x.Name == (string)a.name) is null)
{
gameActions.Add(SeedFromJsons.SingleActionSeeder(a, id));
id++;
}
}
}
}
}
GameActionsList = gameActions;
return gameActions;
}
protected IEnumerable<LegendaryAction> SeedLegendaryActions()
{
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
List<LegendaryAction> legendaryActions = new List<LegendaryAction>();
using (StreamReader reader = new StreamReader(file))
{
var json = reader.ReadToEnd();
dynamic jlegendaryactions = JArray.Parse(json);
int id = 1;
foreach (dynamic item in jlegendaryactions)
{
if (item.legendary_actions != null)
{
foreach (dynamic la in item.legendary_actions)
{
if (legendaryActions.Find(x => x.Name == (string)la.name) is null)
{
legendaryActions.Add(SeedFromJsons.SingleLegendaryActionSeeder(la, id));
id++;
}
}
}
}
}
LegendaryActionsList = legendaryActions;
return legendaryActions;
}
protected IEnumerable<Monster> SeedMonster()
{
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
List<Monster> monsters = new List<Monster>();
using (StreamReader reader = new StreamReader(file))
{
var json = reader.ReadToEnd();
dynamic jmonsters = JArray.Parse(json);
foreach (dynamic item in jmonsters)
monsters.Add(SeedFromJsons.SingleMonsterSeeder(item));
}
return monsters;
}
protected IEnumerable<MonsterSpecialAbility> SeedMonsterSpecialAbilities()
{
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
List<MonsterSpecialAbility> monsterSpecialAbilities = new List<MonsterSpecialAbility>();
using (StreamReader reader = new StreamReader(file))
{
var json = reader.ReadToEnd();
dynamic jabilities = JArray.Parse(json);
int id = 1;
foreach (dynamic item in jabilities)
{
if (item.special_abilities != null)
{
foreach (dynamic a in item.special_abilities)
{
var abilityId = SpecialAbilitiesList.Find(x => x.Name == (string)a.name).Id;
monsterSpecialAbilities.Add(new MonsterSpecialAbility { Id = id, MonsterId = (int)item.index, SpecialAbilityId = abilityId });
id++;
}
}
}
}
return monsterSpecialAbilities;
}
protected IEnumerable<MonsterAction> SeedMonsterActions()
{
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
List<MonsterAction> monsterActions = new List<MonsterAction>();
using (StreamReader reader = new StreamReader(file))
{
var json = reader.ReadToEnd();
dynamic jactions = JArray.Parse(json);
int id = 1;
foreach (dynamic item in jactions)
{
if (item.actions != null)
{
foreach (dynamic a in item.actions)
{
var abilityId = GameActionsList.Find(x => x.Name == (string)a.name).Id;
monsterActions.Add(new MonsterAction { Id = id, MonsterId = (int)item.index, GameActionId = abilityId });
id++;
}
}
}
}
return monsterActions;
}
protected IEnumerable<MonsterLegendaryAction> SeedMonsterLegendaryActions()
{
const string file = "../SessionCompanion.Database/JsonData/monsters.json";
List<MonsterLegendaryAction> monsterLegendaryActions = new List<MonsterLegendaryAction>();
using (StreamReader reader = new StreamReader(file))
{
var json = reader.ReadToEnd();
dynamic jactions = JArray.Parse(json);
int id = 1;
foreach (dynamic item in jactions)
{
if (item.legendary_actions != null)
{
foreach (dynamic a in item.legendary_actions)
{
var actionId = LegendaryActionsList.Find(x => x.Name == (string)a.name).Id;
monsterLegendaryActions.Add(new MonsterLegendaryAction { Id = id, MonsterId = (int)item.index, LegendaryActionId = actionId });
id++;
}
}
}
}
return monsterLegendaryActions;
}
protected override void OnModelCreating(ModelBuilder builder) protected override void OnModelCreating(ModelBuilder builder)
{ {
base.OnModelCreating(builder); base.OnModelCreating(builder);
@ -124,6 +307,13 @@ namespace SessionCompanion.Database
builder.Entity<Spell>().HasData(SeedSpell()); builder.Entity<Spell>().HasData(SeedSpell());
builder.Entity<CharacterSpell>().HasData(SeedData.SeedCharacterSpell()); builder.Entity<CharacterSpell>().HasData(SeedData.SeedCharacterSpell());
builder.Entity<CharacterSpellSlots>().HasData(SeedData.SeedCharacterSpellSlot()); builder.Entity<CharacterSpellSlots>().HasData(SeedData.SeedCharacterSpellSlot());
builder.Entity<Monster>().HasData(SeedMonster());
builder.Entity<SpecialAbility>().HasData(SeedSpecialAbilities());
builder.Entity<LegendaryAction>().HasData(SeedLegendaryActions());
builder.Entity<GameAction>().HasData(SeedActions());
builder.Entity<MonsterSpecialAbility>().HasData(SeedMonsterSpecialAbilities());
builder.Entity<MonsterAction>().HasData(SeedMonsterActions());
builder.Entity<MonsterLegendaryAction>().HasData(SeedMonsterLegendaryActions());
} }
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -320,5 +320,138 @@ namespace SessionCompanion.Database
return spell; return spell;
} }
static public SpecialAbility SingleSpecialAbilitySeeder(dynamic item, int id)
{
SpecialAbility monsterSpecialAbility = new SpecialAbility();
monsterSpecialAbility.Id = id;
monsterSpecialAbility.Name = item.name;
if (item.damage_dice != null)
{
var dice = SplitDice((string)item.damage_dice);
monsterSpecialAbility.DamageDiceAmount = dice.Item1;
monsterSpecialAbility.DamageDice = dice.Item2;
}
monsterSpecialAbility.Description = item.desc;
return monsterSpecialAbility;
}
static public GameAction SingleActionSeeder(dynamic item, int id)
{
GameAction monsterAction = new GameAction();
monsterAction.Id = id;
monsterAction.Name = item.name;
monsterAction.AttackBonus = item.attack_bonus;
monsterAction.DamageBonus = item.damage_bonus;
if (item.damage_dice != null)
{
var dice = SplitDice((string)item.damage_dice);
monsterAction.DamageDiceAmount = dice.Item1;
monsterAction.DamageDice = dice.Item2;
}
monsterAction.Description = item.desc;
return monsterAction;
}
static public LegendaryAction SingleLegendaryActionSeeder(dynamic item, int id)
{
LegendaryAction monsterLegendaryAction = new LegendaryAction();
monsterLegendaryAction.Id = id;
monsterLegendaryAction.Name = item.name;
monsterLegendaryAction.Description = item.desc;
return monsterLegendaryAction;
}
static public Monster SingleMonsterSeeder(dynamic item)
{
Monster monster = new Monster();
monster.Id = item.index;
monster.Name = item.name;
monster.Size = item.size;
monster.Type = item.type;
monster.Subtype = item.subtype;
monster.Alignment = item.alignment;
monster.ArmorClass = item.armor_class;
monster.HitPoints = item.hit_points;
var dice = SplitDice((string)item.hit_dice);
monster.HitDiceAmount = dice.Item1;
monster.HitDiceType = dice.Item2;
monster.WalkSpeed = item.speed.walk;
monster.FlySpeed = item.speed.fly;
monster.SwimSpeed = item.speed.swim;
monster.Strength = item.strength;
monster.StrengthSave = item.strength_save;
monster.Dexterity = item.dexterity;
monster.DexteritySave = item.dexterity_save;
monster.Constitution = item.constitution;
monster.ConstitutionSave = item.constitution_save;
monster.Wisdom = item.wisdom;
monster.WisdomSave = item.wisdom_save;
monster.Charisma = item.charisma;
monster.CharismaSave = item.charsisma_save;
monster.Intelligence = item.intelligence;
monster.IntelligenceSave = item.intelligence_save;
foreach (dynamic dv in item.damage_vulnerabilities)
monster.MonsterDamageVulnerabilities += dv + ";";
if (monster.MonsterDamageVulnerabilities != null)
monster.MonsterDamageVulnerabilities = monster.MonsterDamageVulnerabilities.Remove(monster.MonsterDamageVulnerabilities.Length - 1);
foreach (dynamic dr in item.damage_resistances)
monster.MonsterDamageResistances += dr + ";";
if (monster.MonsterDamageResistances != null)
monster.MonsterDamageResistances = monster.MonsterDamageResistances.Remove(monster.MonsterDamageResistances.Length - 1);
foreach (dynamic di in item.damage_immunities)
monster.MonsterDamageImmunities += di + ";";
if (monster.MonsterDamageImmunities != null)
monster.MonsterDamageImmunities = monster.MonsterDamageImmunities.Remove(monster.MonsterDamageImmunities.Length - 1);
foreach (dynamic ci in item.condition_immunities)
monster.MonsterConditionImmunities += ci + ";";
if (monster.MonsterConditionImmunities != null)
monster.MonsterConditionImmunities = monster.MonsterConditionImmunities.Remove(monster.MonsterConditionImmunities.Length - 1);
monster.MonsterSenses = item.senses;
monster.MonsterLanguages = item.languages;
monster.ChallengeRating = item.challenge_rating;
return monster;
}
static public Tuple<int, int> SplitDice(string dice)
{
int stop = dice.IndexOf('d');
var amount = int.Parse(dice.Substring(0, stop));
stop++;
var value = int.Parse(dice.Substring(stop, dice.Length - stop));
return new Tuple<int, int>(amount, value);
}
} }
} }

View File

@ -7,11 +7,14 @@ namespace SessionCompanion.Services.Interfaces
using System.Threading.Tasks; using System.Threading.Tasks;
using SessionCompanion.Database.Tables; using SessionCompanion.Database.Tables;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Base; using SessionCompanion.Services.Base;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.CharacterArmorViewModels; using SessionCompanion.ViewModels.CharacterArmorViewModels;
public interface ICharacterArmorService : IServiceBase<CharacterArmorViewModel, CharacterArmor> public interface ICharacterArmorService : IServiceBase<CharacterArmorViewModel, CharacterArmor>
{ {
Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId);
Task<List<CharacterArmorViewModelDetails>> GetCharacterArmorsTaskList(int characterId); Task<List<CharacterArmorViewModelDetails>> GetCharacterArmorsTaskList(int characterId);
} }
} }

View File

@ -4,11 +4,14 @@ using SessionCompanion.ViewModels.CharacterWeaponViewModels;
namespace SessionCompanion.Services.Interfaces namespace SessionCompanion.Services.Interfaces
{ {
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.ViewModels.ApiResponses;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
public interface ICharacterWeaponService : IServiceBase<CharacterWeaponViewModel, CharacterWeapon> public interface ICharacterWeaponService : IServiceBase<CharacterWeaponViewModel, CharacterWeapon>
{ {
Task<List<CharacterWeaponWithWeaponDetailsViewModel>> GetCharacterWeaponsList(int characterId); Task<List<CharacterWeaponWithWeaponDetailsViewModel>> GetCharacterWeaponsList(int characterId);
Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterWeapon(CharacterWeaponViewModel model);
} }
} }

View File

@ -15,7 +15,9 @@ namespace SessionCompanion.Services.Services
using SessionCompanion.Database.Tables; using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base; using SessionCompanion.Services.Base;
using SessionCompanion.Services.Interfaces; using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.CharacterArmorViewModels; using SessionCompanion.ViewModels.CharacterArmorViewModels;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels; using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels;
public class CharacterArmorService : ServiceBase<CharacterArmorViewModel, CharacterArmor>, ICharacterArmorService public class CharacterArmorService : ServiceBase<CharacterArmorViewModel, CharacterArmor>, ICharacterArmorService
@ -23,6 +25,53 @@ namespace SessionCompanion.Services.Services
public CharacterArmorService(IMapper mapper, IRepository<CharacterArmor> repository) : base(mapper, repository) public CharacterArmorService(IMapper mapper, IRepository<CharacterArmor> repository) : base(mapper, repository)
{ } { }
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId)
{
CharacterArmor armorInUse = new CharacterArmor();
CharacterArmor armorToUse = new CharacterArmor();
try
{
armorInUse = await Repository.Get(c => c.CharacterId.Equals(characterId))
.Include(a => a.Armor).Where(x => x.InUse == true).SingleAsync();
armorToUse = await Repository.Get(c => c.ArmorId.Equals(newArmorId) && c.CharacterId.Equals(characterId)).SingleAsync();
}
catch (Exception e)
{
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
}
if (armorToUse is null)
return new ErrorResponse() { StatusCode = 204, Message = "No armor to change to" };
if (armorInUse is null)
{
armorToUse.InUse = true;
try
{
await Repository.Update(armorToUse);
await Repository.Save();
return new SuccessResponse("Character armor updated") { SuccessCode = 200 };
}
catch (Exception e)
{
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
}
}
armorInUse.InUse = false;
armorToUse.InUse = true;
try
{
await Repository.Update(armorInUse);
await Repository.Update(armorToUse);
await Repository.Save();
return new SuccessResponse("Character armor updated") { SuccessCode = 204 };
}
catch (Exception e)
{
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
}
}
/// <summary> /// <summary>
/// Metoda pobiera listę pancerzy konkretnej postaci /// Metoda pobiera listę pancerzy konkretnej postaci
/// </summary> /// </summary>

View File

@ -12,6 +12,8 @@ namespace SessionCompanion.Services.Services
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.ViewModels.ApiResponses;
public class CharacterWeaponService : ServiceBase<CharacterWeaponViewModel, CharacterWeapon>, ICharacterWeaponService public class CharacterWeaponService : ServiceBase<CharacterWeaponViewModel, CharacterWeapon>, ICharacterWeaponService
{ {
@ -30,5 +32,63 @@ namespace SessionCompanion.Services.Services
var result = Mapper.Map<List<CharacterWeaponWithWeaponDetailsViewModel>>(characterWeapons); var result = Mapper.Map<List<CharacterWeaponWithWeaponDetailsViewModel>>(characterWeapons);
return result; return result;
} }
public async Task<Either<SuccessResponse,ErrorResponse>> ChangeCharacterWeapon(CharacterWeaponViewModel model)
{
// Dodaj optional rozbro postac
var allWeapons = await Repository.Get(c => c.CharacterId.Equals(model.CharacterId)).AsNoTracking().ToListAsync();
var weaponsInUse = allWeapons.Where(w => w.InUse.Equals(true)).ToList();
var weapon = Mapper.Map<CharacterWeapon>(model);
weapon.Id = allWeapons.Where(w => w.WeaponId.Equals(model.WeaponId)).Select(x => x.Id).FirstOrDefault();
if (weaponsInUse.Count() == 0)
{
// no weapon in use
// just use new one
await Repository.Update(weapon);
await Repository.Save();
return new SuccessResponse("Weapon changed") { SuccessCode = 200 };
}
var weaponInBothHands = weaponsInUse.Where(w => w.HoldInLeftHand.Equals(true) && w.HoldInRightHand.Equals(true));
if ((model.HoldInLeftHand && model.HoldInRightHand) || (weaponInBothHands.Count() > 0))
{
// our model weapon uses both hands
// or there is weapon already in both hands
foreach (var w in weaponsInUse)
{
w.InUse = false;
w.HoldInLeftHand = false;
w.HoldInRightHand = false;
await Repository.Update(w);
}
await Repository.Update(weapon);
await Repository.Save();
return new SuccessResponse("Weapon changed") { SuccessCode = 200 };
}
var weaponsToChange = weaponsInUse.Where(w => w.HoldInLeftHand.Equals(model.HoldInLeftHand) && w.HoldInRightHand.Equals(model.HoldInRightHand));
if (weaponsToChange.Count() == 1)
{
// there is weapon in the same hand set as our
// we update it
var weaponToChange = weaponsToChange.Single();
weaponToChange.InUse = false;
weaponToChange.HoldInLeftHand = false;
weaponToChange.HoldInRightHand = false;
await Repository.Update(weaponToChange);
await Repository.Update(weapon);
await Repository.Save();
return new SuccessResponse("Weapon changed") { SuccessCode = 200 };
}
// weapon is armed in empty hand
await Repository.Update(weapon);
await Repository.Save();
return new SuccessResponse("Weapon changed") { SuccessCode = 200 };
}
} }
} }

View File

@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SessionCompanion.Database\SessionCompanion.Database.csproj" /> <ProjectReference Include="..\SessionCompanion.Database\SessionCompanion.Database.csproj" />
<ProjectReference Include="..\SessionCompanion.Extensions\SessionCompanion.Extensions.csproj" />
<ProjectReference Include="..\SessionCompanion.ViewModels\SessionCompanion.ViewModels.csproj" /> <ProjectReference Include="..\SessionCompanion.ViewModels\SessionCompanion.ViewModels.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -10,10 +10,13 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.ViewModels", "SessionCompanion.ViewModels\SessionCompanion.ViewModels.csproj", "{7762AA75-7B60-4F28-B80A-B03E39140F89}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.ViewModels", "SessionCompanion.ViewModels\SessionCompanion.ViewModels.csproj", "{7762AA75-7B60-4F28-B80A-B03E39140F89}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.Services", "SessionCompanion.Services\SessionCompanion.Services.csproj", "{C0A172ED-0F4C-4E78-8B64-28E2A756F62F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.Services", "SessionCompanion.Services\SessionCompanion.Services.csproj", "{C0A172ED-0F4C-4E78-8B64-28E2A756F62F}"
ProjectSection(ProjectDependencies) = postProject
{1EE35EB3-C703-407C-B390-5605A0A46884} = {1EE35EB3-C703-407C-B390-5605A0A46884}
EndProjectSection
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.Extensions", "SessionCompanion.Extensions\SessionCompanion.Extensions.csproj", "{1EE35EB3-C703-407C-B390-5605A0A46884}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.Extensions", "SessionCompanion.Extensions\SessionCompanion.Extensions.csproj", "{1EE35EB3-C703-407C-B390-5605A0A46884}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SessionCompanion.XUnitTests", "SessionCompanion.XUnitTests\SessionCompanion.XUnitTests.csproj", "{B8A4DAF6-DD33-4B35-99B8-A1D060EE1869}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.XUnitTests", "SessionCompanion.XUnitTests\SessionCompanion.XUnitTests.csproj", "{B8A4DAF6-DD33-4B35-99B8-A1D060EE1869}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -17,7 +17,7 @@ namespace SessionCompanion.Controllers
[ApiController] [ApiController]
public class EquipmentController : Controller public class EquipmentController : Controller
{ {
private readonly ICharacterArmorService _characterArmorServic; private readonly ICharacterArmorService _characterArmorService;
private readonly ICharacterOtherEquipmentService _characterOtherEquipmentService; private readonly ICharacterOtherEquipmentService _characterOtherEquipmentService;
@ -27,7 +27,7 @@ namespace SessionCompanion.Controllers
ICharacterOtherEquipmentService characterOtherEquipmentService, ICharacterOtherEquipmentService characterOtherEquipmentService,
ICharacterWeaponService characterWeaponService) ICharacterWeaponService characterWeaponService)
{ {
this._characterArmorServic = characterArmorService; this._characterArmorService = characterArmorService;
this._characterOtherEquipmentService = characterOtherEquipmentService; this._characterOtherEquipmentService = characterOtherEquipmentService;
this._characterWeaponService = characterWeaponService; this._characterWeaponService = characterWeaponService;
} }
@ -51,7 +51,7 @@ namespace SessionCompanion.Controllers
[HttpGet("getArmors")] [HttpGet("getArmors")]
public async Task<Either<List<CharacterArmorViewModelDetails>, ErrorResponse>> GetCharacterArmors(int characterId) public async Task<Either<List<CharacterArmorViewModelDetails>, ErrorResponse>> GetCharacterArmors(int characterId)
{ {
return await this._characterArmorServic.GetCharacterArmorsTaskList(characterId); return await this._characterArmorService.GetCharacterArmorsTaskList(characterId);
} }
/// <summary> /// <summary>
@ -65,5 +65,81 @@ namespace SessionCompanion.Controllers
return await this._characterWeaponService.GetCharacterWeaponsList(characterId); return await this._characterWeaponService.GetCharacterWeaponsList(characterId);
} }
/// <summary>
/// Metoda zmienia uzywaną zbroję danej postaci na taki jaki jest wybrany
/// </summary>
/// <param name="characterId"> Id postaci </param>
/// <param name="newArmorId"> Id nowej zbroi </param>
/// <returns>SuccessResponse/ErrorResponse</returns>
[HttpPut("changeArmor")]
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId)
{
var response = await _characterArmorService.ChangeCharacterArmor(characterId, newArmorId);
return response;
}
/// <summary>
/// Metoda dodaje nową zbroje do danej postaci
/// </summary>
/// <param name="characterArmorViewModel"> View model z odpowiednimi parameterami </param>
/// <returns>SuccessResponse/ErrorResponse</returns>
[HttpPut("addArmor")]
public async Task<Either<SuccessResponse, ErrorResponse>> AddCharacterArmor(CharacterArmorViewModel characterArmorViewModel)
{
if (!ModelState.IsValid)
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
try
{
await _characterArmorService.Create(characterArmorViewModel);
await _characterArmorService.SaveAsync();
return new SuccessResponse("Armor added to character") { SuccessCode = 200 };
}
catch (Exception e)
{
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
}
}
/// <summary>
/// Metoda dodaje broń do danej postaci
/// </summary>
/// <param name="characterWeaponViewModel"> View model z odpowiednimi parameterami </param>
/// <returns>SuccessResponse/ErrorResponse</returns>
[HttpPut("addWeapon")]
public async Task<Either<SuccessResponse, ErrorResponse>> AddCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel)
{
if (!ModelState.IsValid)
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
try
{
await _characterWeaponService.Create(characterWeaponViewModel);
await _characterWeaponService.SaveAsync();
return new SuccessResponse("Weapon added to character") { SuccessCode = 200 };
}
catch (Exception e)
{
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
}
}
/// <summary>
/// Metoda zmienia broń do danej postaci
/// </summary>
/// <param name=characterWeaponViewModel> View model z odpowiednimi parameterami </param>
/// <returns>SuccessResponse/ErrorResponse</returns>
[HttpPut("changeWeapon")]
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel)
{
if (!ModelState.IsValid)
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
try
{
var response = await _characterWeaponService.ChangeCharacterWeapon(characterWeaponViewModel);
return response;
}
catch (Exception e)
{
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
}
}
} }
} }