SES-142 Added endpoints for character equipment #65
@ -12,5 +12,6 @@ namespace SessionCompanion.Services.Interfaces
|
||||
|
||||
public interface ICharacterArmorService : IServiceBase<CharacterArmorViewModel, CharacterArmor>
|
||||
{
|
||||
Task<List<CharacterArmorViewModelDetails>> GetCharacterArmorsTaskList(int characterId);
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,6 @@ namespace SessionCompanion.Services.Interfaces
|
||||
|
||||
public interface ICharacterOtherEquipmentService : IServiceBase<CharacterOtherEquipmentViewModel, CharacterOtherEquipment>
|
||||
{
|
||||
Task<List<CharacterOtherEquipmentWithDetailsViewModel>> GetCharacterOtherEquipmentList(int characterId);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,11 @@ using SessionCompanion.ViewModels.CharacterWeaponViewModels;
|
||||
|
||||
namespace SessionCompanion.Services.Interfaces
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public interface ICharacterWeaponService : IServiceBase<CharacterWeaponViewModel, CharacterWeapon>
|
||||
{
|
||||
Task<List<CharacterWeaponWithWeaponDetailsViewModel>> GetCharacterWeaponsList(int characterId);
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,24 @@ namespace SessionCompanion.Services.Services
|
||||
using SessionCompanion.Services.Base;
|
||||
using SessionCompanion.Services.Interfaces;
|
||||
using SessionCompanion.ViewModels.CharacterArmorViewModels;
|
||||
using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels;
|
||||
|
||||
public class CharacterArmorService : ServiceBase<CharacterArmorViewModel, CharacterArmor>, ICharacterArmorService
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
namespace SessionCompanion.Services.Services
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SessionCompanion.Database.Repositories.Base;
|
||||
using SessionCompanion.Database.Tables;
|
||||
using SessionCompanion.Services.Base;
|
||||
@ -13,5 +17,17 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,28 @@ using SessionCompanion.ViewModels.CharacterWeaponViewModels;
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user