Getting EVERYTHING.

This commit is contained in:
Kira Jiroux 2024-12-11 18:52:55 -05:00
parent 0ff21c2905
commit 9549a635a0
9 changed files with 97 additions and 9 deletions

View File

@ -9,20 +9,29 @@ namespace PokemonSleep.Web.Controllers
{
private readonly IPokemonService _pokemonService;
public PokemonController(IPokemonService pokemonService)
private readonly IPokemonNatureService _natureService;
private readonly IPokemonSubskillService _subskillService;
public PokemonController(IPokemonService pokemonService, IPokemonNatureService natureService, IPokemonSubskillService subskillService)
{
_pokemonService = pokemonService;
_natureService = natureService;
_subskillService = subskillService;
}
public async Task<IActionResult> PokemonIndex()
{
List<PokemonDto>? list = new();
PokemonSleepDto? list = new();
ResponseDto? response = await _pokemonService.GetAllPokemonAsync();
ResponseDto? presponse = await _pokemonService.GetAllPokemonAsync();
ResponseDto? nresponse = await _natureService.GetAllPokemonNaturesAsync();
ResponseDto? sresponse = await _subskillService.GetAllPokemonSubskillsAsync();
if (response != null && response.IsSuccess)
if (presponse != null && presponse.IsSuccess)
{
list = JsonConvert.DeserializeObject<List<PokemonDto>>(Convert.ToString(response.Result));
list.pokemonList = JsonConvert.DeserializeObject<List<PokemonDto>>(Convert.ToString(presponse.Result));
list.natureList = JsonConvert.DeserializeObject<List<PokemonNatureDto>>(Convert.ToString(nresponse.Result));
list.subskillList = JsonConvert.DeserializeObject<List<PokemonSubskillDto>>(Convert.ToString(sresponse.Result));
}
return View(list);
}

View File

@ -0,0 +1,9 @@
namespace PokemonSleep.Web.Models
{
public class PokemonSleepDto
{
public List<PokemonDto>? pokemonList { get; set; }
public List<PokemonNatureDto>? natureList { get; set; }
public List<PokemonSubskillDto>? subskillList { get; set; }
}
}

View File

@ -17,6 +17,8 @@ StaticDetails.PokemonSleepAPIBase = builder.Configuration["ServiceUrls:PokemonSl
builder.Services.AddScoped<IBaseService, BaseService>();
builder.Services.AddScoped<IPokemonService, PokemonService>();
builder.Services.AddScoped<IPokemonNatureService, PokemonNatureService>();
builder.Services.AddScoped<IPokemonSubskillService, PokemonSubskillService>();
var app = builder.Build();

View File

@ -0,0 +1,10 @@
using PokemonSleep.Web.Models;
namespace PokemonSleep.Web.Service.IService
{
public interface IPokemonNatureService
{
Task<ResponseDto?> GetAllPokemonNaturesAsync();
}
}

View File

@ -0,0 +1,10 @@
using PokemonSleep.Web.Models;
namespace PokemonSleep.Web.Service.IService
{
public interface IPokemonSubskillService
{
Task<ResponseDto?> GetAllPokemonSubskillsAsync();
}
}

View File

@ -0,0 +1,24 @@
using PokemonSleep.Web.Models;
using PokemonSleep.Web.Service.IService;
using PokemonSleep.Web.Utility;
namespace PokemonSleep.Web.Service
{
public class PokemonNatureService : IPokemonNatureService
{
private readonly IBaseService _baseService;
public PokemonNatureService(IBaseService baseService)
{
_baseService = baseService;
}
public async Task<ResponseDto?> GetAllPokemonNaturesAsync()
{
return await _baseService.SendAsync(new RequestDto()
{
ApiType = StaticDetails.ApiType.GET,
Url = StaticDetails.PokemonSleepAPIBase + "/api/nature"
});
}
}
}

View File

@ -0,0 +1,24 @@
using PokemonSleep.Web.Models;
using PokemonSleep.Web.Service.IService;
using PokemonSleep.Web.Utility;
namespace PokemonSleep.Web.Service
{
public class PokemonSubskillService : IPokemonSubskillService
{
private readonly IBaseService _baseService;
public PokemonSubskillService(IBaseService baseService)
{
_baseService = baseService;
}
public async Task<ResponseDto?> GetAllPokemonSubskillsAsync()
{
return await _baseService.SendAsync(new RequestDto()
{
ApiType = StaticDetails.ApiType.GET,
Url = StaticDetails.PokemonSleepAPIBase + "/api/subskill"
});
}
}
}

View File

@ -1,4 +1,4 @@
@model IEnumerable<PokemonDto>
@model PokemonSleepDto
<div class="card shadow border-0 mt-4">
<div class="card-header bg-secondary bg-gradient ml-0 py-3">
<div class="row">
@ -37,7 +37,7 @@
<td>
<select class="form-control form-control-lg">
<option value="" disabled selected>Choose your Pokémon...</option>
@foreach(var pokemon in Model)
@foreach(var pokemon in Model.pokemonList)
{
<option>@pokemon.Id @pokemon.Name</option>
}

View File

@ -22,9 +22,9 @@ namespace PokemonSleepAPI.Controllers
_response = new ResponseDto();
}
/* Get all Pokemon Natures */
/* Get all Pokemon Subskills */
[HttpGet]
public ResponseDto GetAllPokemonNatures()
public ResponseDto GetAllPokemonSubskills()
{
try
{