Merge pull request 'SES-142 Added endpoints for character equipment' (#65) from SES-142 into dev

Reviewed-on: #65
This commit is contained in:
Karol Górzyński 2021-01-13 09:29:47 +01:00
commit 7d790cfdc8
7 changed files with 124 additions and 0 deletions

View File

@ -12,5 +12,6 @@ namespace SessionCompanion.Services.Interfaces
public interface ICharacterArmorService : IServiceBase<CharacterArmorViewModel, CharacterArmor> public interface ICharacterArmorService : IServiceBase<CharacterArmorViewModel, CharacterArmor>
{ {
Task<List<CharacterArmorViewModelDetails>> GetCharacterArmorsTaskList(int characterId);
} }
} }

View File

@ -12,5 +12,6 @@ namespace SessionCompanion.Services.Interfaces
public interface ICharacterOtherEquipmentService : IServiceBase<CharacterOtherEquipmentViewModel, CharacterOtherEquipment> public interface ICharacterOtherEquipmentService : IServiceBase<CharacterOtherEquipmentViewModel, CharacterOtherEquipment>
{ {
Task<List<CharacterOtherEquipmentWithDetailsViewModel>> GetCharacterOtherEquipmentList(int characterId);
} }
} }

View File

@ -4,7 +4,11 @@ using SessionCompanion.ViewModels.CharacterWeaponViewModels;
namespace SessionCompanion.Services.Interfaces namespace SessionCompanion.Services.Interfaces
{ {
using System.Collections.Generic;
using System.Threading.Tasks;
public interface ICharacterWeaponService : IServiceBase<CharacterWeaponViewModel, CharacterWeapon> public interface ICharacterWeaponService : IServiceBase<CharacterWeaponViewModel, CharacterWeapon>
{ {
Task<List<CharacterWeaponWithWeaponDetailsViewModel>> GetCharacterWeaponsList(int characterId);
} }
} }

View File

@ -16,10 +16,24 @@ namespace SessionCompanion.Services.Services
using SessionCompanion.Services.Base; using SessionCompanion.Services.Base;
using SessionCompanion.Services.Interfaces; using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.CharacterArmorViewModels; using SessionCompanion.ViewModels.CharacterArmorViewModels;
using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels;
public class CharacterArmorService : ServiceBase<CharacterArmorViewModel, CharacterArmor>, ICharacterArmorService public class CharacterArmorService : ServiceBase<CharacterArmorViewModel, CharacterArmor>, ICharacterArmorService
{ {
public CharacterArmorService(IMapper mapper, IRepository<CharacterArmor> repository) : base(mapper, repository) public CharacterArmorService(IMapper mapper, IRepository<CharacterArmor> repository) : base(mapper, repository)
{ } { }
/// <summary>
/// Metoda pobiera listę pancerzy konkretnej postaci
/// </summary>
/// <param name="characterId"> Id postaci </param>
/// <returns> Lista pancerzy posiadanych przez postać </returns>
public async Task<List<CharacterArmorViewModelDetails>> GetCharacterArmorsTaskList(int characterId)
{
var characterWeapons = await Repository.Get().Where(a => a.CharacterId.Equals(characterId)).Include(a => a.Armor).ToListAsync();
var result = Mapper.Map<List<CharacterArmorViewModelDetails>>(characterWeapons);
return result;
}
} }
} }

View File

@ -1,7 +1,11 @@
namespace SessionCompanion.Services.Services namespace SessionCompanion.Services.Services
{ {
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper; using AutoMapper;
using Microsoft.EntityFrameworkCore;
using SessionCompanion.Database.Repositories.Base; using SessionCompanion.Database.Repositories.Base;
using SessionCompanion.Database.Tables; using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base; using SessionCompanion.Services.Base;
@ -13,5 +17,17 @@
public CharacterOtherEquipmentService(IMapper mapper, IRepository<CharacterOtherEquipment> repository) : base(mapper, repository) public CharacterOtherEquipmentService(IMapper mapper, IRepository<CharacterOtherEquipment> repository) : base(mapper, repository)
{ } { }
/// <summary>
/// Metoda pobiera listę pozostałego ekwipunku konkretnej postaci
/// </summary>
/// <param name="characterId"> Id postaci </param>
/// <returns> Lista pozostałego ekwpinuku posiadanego przez postać </returns>
public async Task<List<CharacterOtherEquipmentWithDetailsViewModel>> GetCharacterOtherEquipmentList(int characterId)
{
var characterWeapons = await Repository.Get().Where(a => a.CharacterId.Equals(characterId)).Include(a => a.OtherEquipment).ToListAsync();
var result = Mapper.Map<List<CharacterOtherEquipmentWithDetailsViewModel>>(characterWeapons);
return result;
}
} }
} }

View File

@ -7,9 +7,28 @@ using SessionCompanion.ViewModels.CharacterWeaponViewModels;
namespace SessionCompanion.Services.Services namespace SessionCompanion.Services.Services
{ {
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
public class CharacterWeaponService : ServiceBase<CharacterWeaponViewModel, CharacterWeapon>, ICharacterWeaponService public class CharacterWeaponService : ServiceBase<CharacterWeaponViewModel, CharacterWeapon>, ICharacterWeaponService
{ {
public CharacterWeaponService(IMapper mapper, IRepository<CharacterWeapon> repository) : base(mapper, repository) public CharacterWeaponService(IMapper mapper, IRepository<CharacterWeapon> repository) : base(mapper, repository)
{ } { }
/// <summary>
/// Metoda pobiera listę broni konkretnej postaci
/// </summary>
/// <param name="characterId"> Id postaci </param>
/// <returns> Lista broni posiadanych przez postać </returns>
public async Task<List<CharacterWeaponWithWeaponDetailsViewModel>> GetCharacterWeaponsList(int characterId)
{
var characterWeapons = await Repository.Get().Where(w => w.CharacterId.Equals(characterId)).Include(w => w.Weapon).ToListAsync();
var result = Mapper.Map<List<CharacterWeaponWithWeaponDetailsViewModel>>(characterWeapons);
return result;
}
} }
} }

View File

@ -0,0 +1,69 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SessionCompanion.Controllers
{
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.CharacterArmorViewModels;
using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels;
using SessionCompanion.ViewModels.CharacterWeaponViewModels;
[Route("api/character/equipment")]
[ApiController]
public class EquipmentController : Controller
{
private readonly ICharacterArmorService _characterArmorServic;
private readonly ICharacterOtherEquipmentService _characterOtherEquipmentService;
private readonly ICharacterWeaponService _characterWeaponService;
public EquipmentController(ICharacterArmorService characterArmorService,
ICharacterOtherEquipmentService characterOtherEquipmentService,
ICharacterWeaponService characterWeaponService)
{
this._characterArmorServic = characterArmorService;
this._characterOtherEquipmentService = characterOtherEquipmentService;
this._characterWeaponService = characterWeaponService;
}
/// <summary>
/// Zwraca listę pozostałego ekwipunku dla danej postaci
/// </summary>
/// <param name="characterId"> Id postaci </param>
/// <returns> Lista pozostałego ekwipunku lub błąd </returns>
[HttpGet("getOtherEquipment")]
public async Task<Either<List<CharacterOtherEquipmentWithDetailsViewModel>, ErrorResponse>> GetCharacterOtherEquipment(int characterId)
{
return await this._characterOtherEquipmentService.GetCharacterOtherEquipmentList(characterId);
}
/// <summary>
/// Zwraca listę pancerzy posiadanych przez daną postać
/// </summary>
/// <param name="characterId"> Id postaci </param>
/// <returns> Lista pozostałego ekwipunku lub błąd </returns>
[HttpGet("getArmors")]
public async Task<Either<List<CharacterArmorViewModelDetails>, ErrorResponse>> GetCharacterArmors(int characterId)
{
return await this._characterArmorServic.GetCharacterArmorsTaskList(characterId);
}
/// <summary>
/// Zwraca listę broni posiadanej przez daną postać
/// </summary>
/// <param name="characterId"> Id postaci </param>
/// <returns> Lista broni lub błąd </returns>
[HttpGet("getWeapons")]
public async Task<Either<List<CharacterWeaponWithWeaponDetailsViewModel>, ErrorResponse>> GetCharacterWeapons(int characterId)
{
return await this._characterWeaponService.GetCharacterWeaponsList(characterId);
}
}
}