API : l'appel à la stubLib fonctionne 😃

bravo paul pour ton travail je n'y croyais plus
master
pasquizzat 2 years ago
parent 3169158f48
commit 18bbcbb0db

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,117 @@
using ApiDePaul.DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
using System.Collections.Generic;
namespace ApiDePaul.Controllers
{
[ApiController]
[Route("[controller]")]
public class ChampionController : ControllerBase
{
private readonly ILogger<ChampionController> _logger;
public ChampionController(ILogger<ChampionController> logger)
{
_logger = logger;
}
[HttpGet]
public async Task<ActionResult<ChampionDto>> Get()
{
StubData stu = new StubData();
IEnumerable<Champion?> lcha = await stu.ChampionsMgr.GetItems(0, stu.ChampionsMgr.GetNbItems().Result);
List<ChampionDto> champs = new List<ChampionDto>();
lcha.ToList().ForEach(c => champs.Add(c.ChampToDto()));
return Ok(champs);
}
[HttpGet("{id}")]
public async Task<ActionResult<ChampionDto>> Get(int id)
{
StubData stu = new StubData();
IEnumerable<Champion?> lcha = await stu.ChampionsMgr.GetItems(id, 1);
if (id >= 0 && id < stu.ChampionsMgr.GetNbItems().Result)
{
return Ok(lcha.First().ChampToDto());
}
return BadRequest();
}
/*
// GET: ChampionController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: ChampionController/Create
public ActionResult Create()
{
return View();
}
// POST: ChampionController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: ChampionController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: ChampionController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: ChampionController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: ChampionController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}*/
}
}

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace ApiDePaul.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ApiDePaul.DTO;
using Model;
namespace ApiDePaul
{
public static class ChampionMapping
{
public static ChampionDto ChampToDto(this Champion c)
{
return new ChampionDto()
{
Name = c.Name,
Bio = c.Bio,
Icon = c.Icon
};
}
public static Champion DtoToChamp(this ChampionDto c) => new Champion(c.Name);
}
}

@ -0,0 +1,16 @@
using Model;
namespace ApiDePaul.DTO
{
public class ChampionDto
{
public string Name { get; set; }
public string Bio { get; set; }
public String Class { get; set; }
public string Icon { get; set; }
public String Image { get; set; }
public List<SkinDto> Skins { get; set; }
public Dictionary<String, int> Characteristics { get; set; }
public HashSet<Skill> Skills { get; set; }
}
}

@ -0,0 +1,6 @@
namespace ApiDePaul.DTO
{
public class SkinDto
{
}
}

@ -0,0 +1,28 @@
using Model;
using StubLib;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IDataManager, StubData>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:15019",
"sslPort": 44321
}
},
"profiles": {
"ApiDePaul": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7065;http://localhost:5065",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,13 @@
namespace ApiDePaul
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

@ -17,19 +17,24 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibEntityFramework", "Model2\LibEntityFramework.csproj", "{D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BddTests", "BddTests\BddTests.csproj", "{20E7E2FA-9482-4F46-AE84-97576399F882}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BddTests", "BddTests\BddTests.csproj", "{20E7E2FA-9482-4F46-AE84-97576399F882}"
ProjectSection(ProjectDependencies) = postProject
{00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C} = {00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}
{2960F9BA-49DE-494D-92E3-CE5A794BA1A9} = {2960F9BA-49DE-494D-92E3-CE5A794BA1A9}
{D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5} = {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrucAuMilieu", "TrucAuMilieu\TrucAuMilieu.csproj", "{00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrucAuMilieu", "TrucAuMilieu\TrucAuMilieu.csproj", "{00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}"
ProjectSection(ProjectDependencies) = postProject
{2960F9BA-49DE-494D-92E3-CE5A794BA1A9} = {2960F9BA-49DE-494D-92E3-CE5A794BA1A9}
{D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5} = {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiDePaul", "ApiDePaul\ApiDePaul.csproj", "{245F7BAC-8487-4510-8066-D12B5B2B816B}"
ProjectSection(ProjectDependencies) = postProject
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -64,6 +69,10 @@ Global
{00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}.Release|Any CPU.Build.0 = Release|Any CPU
{245F7BAC-8487-4510-8066-D12B5B2B816B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{245F7BAC-8487-4510-8066-D12B5B2B816B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{245F7BAC-8487-4510-8066-D12B5B2B816B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{245F7BAC-8487-4510-8066-D12B5B2B816B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ApiDePaul\ApiDePaul.csproj" />
<ProjectReference Include="..\Model2\LibEntityFramework.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>

Loading…
Cancel
Save