🚧 mise en place liaison bdd et api
continuous-integration/drone/push Build is failing Details

api_lol
Maxence LANONE 2 years ago
parent 10979b13e8
commit a63b866b27

@ -61,11 +61,7 @@ namespace DbDatamanager
throw new NotImplementedException();
}
public async Task<int> GetNbItems()
{
var nbItems = lolContext.Champions.Count();
return nbItems;
}
public async Task<int> GetNbItems() => lolContext.Champions.Count();
private Func<Champion, string, bool> filterByName = (champ, substring) => champ.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);

@ -3,13 +3,6 @@ namespace WebApiLol
{
public class ChampionDTO
{
public ChampionDTO(string name, string bio, string icon, string championClassDTO)
{
Name = name;
Bio = bio;
Icon = icon;
Class = championClassDTO;
}
public int UniqueId { get; set; }

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
using WebApiLol.Converter;
@ -12,26 +13,29 @@ namespace WebApiLol.Controllers;
[Route("[controller]")]
public class ChampionController : ControllerBase
{
private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
//private StubData.ChampionsManager ChampionManager { get; set; } = new StubData.ChampionManager(new StubData());
private readonly ILogger<ChampionController> _logger;
public ChampionController(ILogger<ChampionController> logger)
private IChampionsManager _dataManager;
public ChampionController(ILogger<ChampionController> logger, IDataManager dataManager)
{
_logger = logger;
_dataManager = dataManager.ChampionsMgr;
}
[HttpGet]
public async Task<IActionResult> Get()
{
var list = await ChampionsManager.GetItems(0, await ChampionsManager.GetNbItems());
var list = await _dataManager.GetItems(0, await _dataManager.GetNbItems());
return Ok(list.Select(champion => champion?.toDTO()));
}
[HttpGet("name")]
public async Task<IActionResult> GetById(string name)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
return Ok(championSelected.Select(c => c?.toDTO()));
}
@ -39,7 +43,7 @@ public class ChampionController : ControllerBase
public async Task<IActionResult> AddChampion([FromBody] ChampionDTO champion)
{
var newChampion = champion.toModel();
await ChampionsManager.AddItem(newChampion);
await _dataManager.AddItem(newChampion);
if (champion.Bio == "string")
{
champion.Bio = "Aucune bio";
@ -51,7 +55,7 @@ public class ChampionController : ControllerBase
[HttpPut("Update")]
public async Task<IActionResult> UpdateChampion(string name, [FromBody] ChampionDTO champion)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
var existingChampion = championSelected.FirstOrDefault();
if (existingChampion == null)
{
@ -59,7 +63,7 @@ public class ChampionController : ControllerBase
return NotFound();
}
var updatedChampion = champion.toModel();
await ChampionsManager.UpdateItem(existingChampion, updatedChampion);
await _dataManager.UpdateItem(existingChampion, updatedChampion);
if (updatedChampion.Bio == "string")
{
updatedChampion.Bio = "Aucune bio";
@ -71,8 +75,8 @@ public class ChampionController : ControllerBase
[HttpDelete("Delete")]
public async Task<IActionResult> DeleteChampion(string name)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
if (!await ChampionsManager.DeleteItem(championSelected.FirstOrDefault()))
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
if (!await _dataManager.DeleteItem(championSelected.FirstOrDefault()))
{
Console.WriteLine("champion { " + name + " } not found !");
return NotFound();

@ -8,6 +8,8 @@ namespace WebApiLol.Converter
{
Name = champion.Name,
Bio = champion.Bio,
Icon = champion.Icon,
Class = champion.Class.ToString()
};
public static Champion toModel(this ChampionDTO champion) => new Champion(champion.Name, champion.Bio);

@ -9,6 +9,8 @@ namespace WebApiLol.Converter
{
Name = skin.Name,
Description = skin.Description,
Icon = skin.Icon,
Price = skin.Price
};
public static Skin toModel(this SkinDTO skin) => new Skin(skin.Name, skin.Description);

@ -1,5 +1,8 @@
var builder = WebApplication.CreateBuilder(args);
using DbDatamanager;
using Model;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IDataManager, DbDataManager>();
// Add services to the container.
builder.Services.AddControllers();
@ -7,6 +10,7 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.

@ -7,15 +7,6 @@ namespace WebApiLol
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
public SkinDTO(string name, string description, string icon, float price)
{
Name = name;
Description = description;
Icon = icon;
Price = price;
}
}
}

@ -11,7 +11,7 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
@ -28,5 +28,11 @@
<ProjectReference Include="..\StubLib\StubLib.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
<ProjectReference Include="..\EntityFrameWorkLib\EntityFrameWorkLib.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
<ProjectReference Include="..\DbDatamanager\DbDatamanager.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
</ItemGroup>
</Project>

Loading…
Cancel
Save