diff --git a/Sources/APILOL/APILOL.csproj b/Sources/APILOL/APILOL.csproj
index 607f65a..ffe0ca3 100644
--- a/Sources/APILOL/APILOL.csproj
+++ b/Sources/APILOL/APILOL.csproj
@@ -1,4 +1,4 @@
-
+
net6.0
@@ -8,6 +8,7 @@
+
all
@@ -24,4 +25,8 @@
+
+
+
+
diff --git a/Sources/APILOL/Controllers/ChampionsController.cs b/Sources/APILOL/Controllers/ChampionsController.cs
index b73d518..5fd4043 100644
--- a/Sources/APILOL/Controllers/ChampionsController.cs
+++ b/Sources/APILOL/Controllers/ChampionsController.cs
@@ -1,62 +1,146 @@
-using APILOL.Mapper;
+using APILOL.Controllers.Request;
+using APILOL.Mapper;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
+using System.Xml.Linq;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace APILOL.Controllers
{
- [Route("api/[controller]")]
[ApiController]
+ [Route("api/v{version:apiVersion}/[controller]")]
+ [ApiVersion("1.0")]
+
public class ChampionsController : ControllerBase
{
IChampionsManager dataManager;
- public ChampionsController(IDataManager dataManager)
+ private readonly ILogger _logger;
+
+ public ChampionsController(IDataManager dataManager, ILogger logger)
{
this.dataManager = dataManager.ChampionsMgr;
+ this._logger = logger;
+
}
// GET: api/
[HttpGet]
- public async Task Get(int index, int count)
+ public async Task Get([FromQuery] PageRequest request)
{
- var champions = await dataManager.GetItems(index, count);
- IEnumerable items = champions.Select(c => c.ToDto());
- return Ok(items);
+ _logger.LogInformation("API call - [GET] - CHAMPION");
+ try
+ {
+
+ var total = await dataManager.GetNbItems();
+ var champions = await dataManager.GetItems(request.offset, request.limit, request.orderingPropertyName, request.isDesc);
+ IEnumerable items = champions.Select(c => c.ToDto());
+ if (items.Count() == 0)
+ {
+ _logger.LogInformation("No champion found.");
+ return NotFound("No champion found.");
+ }
+ return Ok(items);
+ }
+ catch(Exception error)
+ {
+ return BadRequest(error.Message);
+ }
+
}
// GET api//5
[HttpGet("{name}")]
- public async Task Get(string name)
+ public async Task Get([FromQuery] PageRequest request,string name)
{
- if (dataManager.GetNbItemsByName(name) != null)
+ _logger.LogInformation("API call - [GET / NAME] - CHAMPION");
+ try
+ {
+ if (dataManager.GetNbItemsByName(name) != null)
+ {
+ var champions = await dataManager.GetItemsByName(name, request.offset, request.limit, request.orderingPropertyName, request.isDesc);
+ IEnumerable items = champions.Select(c => c.ToDto());
+ if (items.Count() == 0)
+ {
+ _logger.LogInformation("No champion found.");
+ return NotFound("No champion found.");
+ }
+
+ return Ok(items);
+ }
+ return NotFound("No champion matching with this name.");
+ }
+ catch (Exception error)
{
- return Ok(dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
+ return BadRequest(error.Message);
}
- return NotFound();
}
// POST api/
[HttpPost]
public async Task Post([FromBody] ChampionDTO championDTO)
{
+ _logger.LogInformation("API call - [POST] - CHAMPION");
- return CreatedAtAction(nameof(Get),(await dataManager.AddItem(championDTO.ToModel())).ToDto);
+ try
+ {
+ if(await dataManager.GetNbItemsByName(championDTO.Name) == 0)
+ {
+ await dataManager.AddItem(championDTO.ToModel());
+ return CreatedAtAction(nameof(Get), championDTO);
+ }
+ _logger.LogInformation("A champion already exist with this Name. ( Unique Name )");
+ return BadRequest("A champion already exist with this Name. ( Unique Name )");
+ }
+ catch (Exception error)
+ {
+ _logger.LogInformation("Error in the request");
+ return BadRequest(error.Message);
+ }
}
// PUT api//5
[HttpPut("{name}")]
public async Task PutAsync(string name, [FromBody] ChampionDTO championDTO)
{
+ _logger.LogInformation("API call - [PUT / NAME] - CHAMPION");
+ try
+ {
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ Console.WriteLine(champion.First().Name) ;
+ var champion2 = await dataManager
+ .GetItemsByName(championDTO.Name, 0, await dataManager.GetNbItems());
+ if (champion != null)
+ {
+ if(champion2.Count() == 0)
+ {
+ await dataManager.UpdateItem(champion.First(), championDTO.ToModel());
+ return Ok();
- var dtos = (await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
-
- return Ok(dataManager.UpdateItem(dtos.First(), championDTO.ToModel()));
+ }
+ _logger.LogInformation("champion already exist with this unique name.");
+ return BadRequest("champion already exist with this unique name.");
+
+ }
+ else
+ {
+ _logger.LogInformation("champion not found.");
+ return NotFound("champion not found.");
+ }
+ await dataManager.UpdateItem(champion.First(), championDTO.ToModel());
+ return Ok();
+
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+ }
}
@@ -64,13 +148,28 @@ namespace APILOL.Controllers
[HttpDelete("{name}")]
public async Task Delete(string name)
{
- var dtos = (await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
- return Ok(dataManager.DeleteItem(dtos.First()));
+ _logger.LogInformation("API call - [DELETE / NAME] - CHAMPION");
+ try
+ {
+ var champion = await (dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
+
+ if (champion.Count() != 0)
+ {
+ var championDto = champion.First().ToDto();
+ await dataManager.DeleteItem(champion.First());
+ return Ok(championDto);
+ }
+ else
+ {
+ _logger.LogInformation("No matching Champion with this name");
+ return NotFound("No matching Champion with this name");
+ }
+
+ }
+ catch(Exception error)
+ {
+ return BadRequest(error);
+ }
}
}
}
-
-/*
-var champion = new Champion("");
-var dto = ChampionMapper.ToDto(champion);
-*/
\ No newline at end of file
diff --git a/Sources/APILOL/Controllers/Request/PageRequest.cs b/Sources/APILOL/Controllers/Request/PageRequest.cs
new file mode 100644
index 0000000..119dba6
--- /dev/null
+++ b/Sources/APILOL/Controllers/Request/PageRequest.cs
@@ -0,0 +1,13 @@
+namespace APILOL.Controllers.Request
+{
+ public class PageRequest
+ {
+ public bool isDesc { get; set; } = false;
+
+ public int offset { get; set; } = 0;
+
+ public string? orderingPropertyName { get; set; } = "Name";
+ public int limit { get; set; } = 10;
+
+ }
+}
diff --git a/Sources/APILOL/Controllers/RuneController.cs b/Sources/APILOL/Controllers/RuneController.cs
new file mode 100644
index 0000000..f3a6fc0
--- /dev/null
+++ b/Sources/APILOL/Controllers/RuneController.cs
@@ -0,0 +1,172 @@
+using APILOL.Controllers.Request;
+using APILOL.Mapper;
+using DTO;
+using Microsoft.AspNetCore.Mvc;
+using Model;
+using StubLib;
+
+// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+
+namespace APILOL.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class RuneController : ControllerBase
+ {
+ IRunesManager dataManager;
+
+ private readonly ILogger _logger;
+
+ public RuneController(IDataManager dataManager, ILogger logger)
+ {
+ this.dataManager = dataManager.RunesMgr;
+ this._logger = logger;
+
+ }
+
+
+
+ // GET: api/
+ [HttpGet]
+ public async Task Get([FromQuery] PageRequest request)
+ {
+ _logger.LogInformation("API call - [GET] - RUNE");
+ try
+ {
+
+ var total = await dataManager.GetNbItems();
+ var runes = await dataManager.GetItems(request.offset, request.limit, request.orderingPropertyName, request.isDesc);
+ IEnumerable items = runes.Select(c => c.ToDto());
+ if (items.Count() == 0)
+ {
+ _logger.LogInformation("No rune found.");
+ return NotFound("No rune found.");
+ }
+ return Ok(items);
+ }
+ catch (Exception error)
+ {
+ return BadRequest(error.Message);
+ }
+
+ }
+
+ // GET api//5
+ [HttpGet("{name}")]
+ public async Task Get([FromQuery] PageRequest request, string name)
+ {
+ _logger.LogInformation("API call - [GET / NAME] - RUNE");
+ try
+ {
+ if (dataManager.GetNbItemsByName(name) != null)
+ {
+ var runes = await dataManager.GetItemsByName(name, request.offset, request.limit, request.orderingPropertyName, request.isDesc);
+ IEnumerable items = runes.Select(c => c.ToDto());
+ if (items.Count() == 0)
+ {
+ _logger.LogInformation("No rune found.");
+ return BadRequest("No rune found.");
+ }
+
+ return Ok(items);
+ }
+ return NotFound("No rune matching with this name.");
+ }
+ catch (Exception error)
+ {
+ return BadRequest(error.Message);
+ }
+ }
+
+ // POST api/
+ [HttpPost]
+ public async Task Post([FromBody] RuneDTO runeDTO)
+ {
+ _logger.LogInformation("API call - [POST] - RUNE");
+
+ try
+ {
+ if (await dataManager.GetNbItemsByName(runeDTO.Name) == 0)
+ {
+ await dataManager.AddItem(runeDTO.ToModel());
+ return CreatedAtAction(nameof(Get), runeDTO);
+ }
+ _logger.LogInformation("A rune already exist with this Name. ( Unique Name )");
+ return BadRequest("A rune already exist with this Name. ( Unique Name )");
+ }
+ catch (Exception error)
+ {
+ _logger.LogInformation("Error in the request");
+ return BadRequest(error.Message);
+ }
+ }
+
+ // PUT api//5
+ [HttpPut("{name}")]
+ public async Task PutAsync(string name, [FromBody] RuneDTO runeDTO)
+ {
+ _logger.LogInformation("API call - [PUT / NAME] - RUNE");
+ try
+ {
+ var rune = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ Console.WriteLine(rune.First().Name);
+ var rune2 = await dataManager
+ .GetItemsByName(runeDTO.Name, 0, await dataManager.GetNbItems());
+ if (rune != null)
+ {
+ if (rune2.Count() == 0)
+ {
+ await dataManager.UpdateItem(rune.First(), runeDTO.ToModel());
+ return Ok();
+
+ }
+ _logger.LogInformation("rune already exist with this unique name.");
+ return BadRequest("rune already exist with this unique name.");
+
+ }
+ else
+ {
+ _logger.LogInformation("rune not found.");
+ return NotFound("rune not found.");
+ }
+ await dataManager.UpdateItem(rune.First(), runeDTO.ToModel());
+ return Ok();
+
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+ }
+
+ }
+
+ // DELETE api//5
+ [HttpDelete("{name}")]
+ public async Task Delete(string name)
+ {
+ _logger.LogInformation("API call - [DELETE / NAME] - RUNE");
+ try
+ {
+ var rune = await (dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
+
+ if (rune.Count() != 0)
+ {
+ var runeDto = rune.First().ToDto();
+ await dataManager.DeleteItem(rune.First());
+ return Ok(runeDto);
+ }
+ else
+ {
+ _logger.LogInformation("No matching rune with this name");
+ return NotFound("No matching rune with this name");
+ }
+
+ }
+ catch (Exception error)
+ {
+ return BadRequest(error);
+ }
+ }
+ }
+}
diff --git a/Sources/APILOL/Controllers/RunePageController.cs b/Sources/APILOL/Controllers/RunePageController.cs
new file mode 100644
index 0000000..118ac50
--- /dev/null
+++ b/Sources/APILOL/Controllers/RunePageController.cs
@@ -0,0 +1,177 @@
+using APILOL.Controllers.Request;
+using APILOL.Mapper;
+using DTO;
+using Microsoft.AspNetCore.Mvc;
+using Model;
+using StubLib;
+
+// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+
+namespace APILOL.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class RunePageController : ControllerBase
+ {
+ IRunePagesManager dataManager;
+
+ private readonly ILogger _logger;
+
+ public RunePageController(IDataManager dataManager, ILogger logger)
+ {
+ this.dataManager = dataManager.RunePagesMgr;
+ this._logger = logger;
+
+ }
+
+
+
+ // GET: api/
+ [HttpGet]
+ public async Task Get([FromQuery] PageRequest request)
+ {
+ _logger.LogInformation("API call - [GET] - RUNEPAGE");
+ try
+ {
+
+ var total = await dataManager.GetNbItems();
+ var runePages = await dataManager.GetItems(request.offset, request.limit, request.orderingPropertyName, request.isDesc);
+ IEnumerable items = runePages.Select(c => c.ToDto());
+ if (items.Count() == 0)
+ {
+ _logger.LogInformation("No runePage found.");
+ return NotFound("No runePage found.");
+ }
+ return Ok(items);
+ }
+ catch (Exception error)
+ {
+ return BadRequest(error.Message);
+ }
+
+ }
+
+ // GET api//5
+ [HttpGet("{name}")]
+ public async Task Get([FromQuery] PageRequest request, string name)
+ {
+ _logger.LogInformation("API call - [GET / NAME] - RUNEPAGE");
+ try
+ {
+ if (dataManager.GetNbItemsByName(name) != null)
+ {
+ var runepages = await dataManager.GetItemsByName(name, request.offset, request.limit, request.orderingPropertyName, request.isDesc);
+ IEnumerable items = runepages.Select(c => c.ToDto());
+ if (items.Count() == 0)
+ {
+ _logger.LogInformation("No runePage found.");
+ return NotFound("No runePage found.");
+ }
+
+ return Ok(items);
+ }
+ return NotFound("No runePage matching with this name.");
+ }
+ catch (Exception error)
+ {
+ return BadRequest(error.Message);
+ }
+ }
+
+ // POST api/
+ [HttpPost]
+ public async Task Post([FromBody] RunePageDTO runePageDTO)
+ {
+ _logger.LogInformation("API call - [POST] - RUNEPAGE");
+
+ try
+ {
+ if (await dataManager.GetNbItemsByName(runePageDTO.Name) == 0)
+ {
+ await dataManager.AddItem(runePageDTO.ToModel());
+ return CreatedAtAction(nameof(Get), runePageDTO);
+ }
+ _logger.LogInformation("A runePage already exist with this Name. ( Unique Name )");
+ return BadRequest("A runePage already exist with this Name. ( Unique Name )");
+ }
+ catch (Exception error)
+ {
+ _logger.LogInformation("Error in the request");
+ return BadRequest(error.Message);
+ }
+ }
+
+ // PUT api//5
+ [HttpPut("{name}")]
+ public async Task PutAsync(string name, [FromBody] RunePageDTO runePageDTO)
+ {
+ _logger.LogInformation("API call - [PUT / NAME] - RUNEPAGE");
+ try
+ {
+ var runePage = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ Console.WriteLine(runePage.First().Name);
+ var runePage2 = await dataManager
+ .GetItemsByName(runePageDTO.Name, 0, await dataManager.GetNbItems());
+ if (runePage != null)
+ {
+ if (runePage2.Count() == 0)
+ {
+ await dataManager.UpdateItem(runePage.First(), runePageDTO.ToModel());
+ return Ok();
+
+ }
+ _logger.LogInformation("runePage already exist with this unique name.");
+ return BadRequest("runePage already exist with this unique name.");
+
+ }
+ else
+ {
+ _logger.LogInformation("runePage not found.");
+ return NotFound("runePage not found.");
+ }
+ await dataManager.UpdateItem(runePage.First(), runePageDTO.ToModel());
+ return Ok();
+
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+ }
+
+ }
+
+ // DELETE api//5
+ [HttpDelete("{name}")]
+ public async Task Delete(string name)
+ {
+ _logger.LogInformation("API call - [DELETE / NAME] - RUNEPAGE");
+ try
+ {
+ var runePage = await (dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
+
+ if (runePage.Count() != 0)
+ {
+ var runePageDto = runePage.First().ToDto();
+ await dataManager.DeleteItem(runePage.First());
+ return Ok(runePageDto);
+ }
+ else
+ {
+ _logger.LogInformation("No matching runePage with this name");
+ return NotFound("No matching runePage with this name");
+ }
+
+ }
+ catch (Exception error)
+ {
+ return BadRequest(error);
+ }
+ }
+ }
+}
+
+/*
+var champion = new Champion("");
+var dto = ChampionMapper.ToDto(champion);
+*/
\ No newline at end of file
diff --git a/Sources/APILOL/Controllers/SkinController.cs b/Sources/APILOL/Controllers/SkinController.cs
index 704413d..00db4a3 100644
--- a/Sources/APILOL/Controllers/SkinController.cs
+++ b/Sources/APILOL/Controllers/SkinController.cs
@@ -1,4 +1,5 @@
-using APILOL.Mapper;
+using APILOL.Controllers.Request;
+using APILOL.Mapper;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
@@ -11,65 +12,159 @@ namespace APILOL.Controllers
{
ISkinsManager dataManager;
- public SkinController(IDataManager dataManager)
+
+ private readonly ILogger _logger;
+
+ public SkinController(IDataManager dataManager, ILogger logger)
{
this.dataManager = dataManager.SkinsMgr;
+ this._logger = logger;
+
}
+
// GET: api/
[HttpGet]
- public async Task Get(int index, int count)
+ public async Task Get([FromQuery] PageRequest request)
{
- var skins = await dataManager.GetItems(index, count);
- IEnumerable items = skins.Select(c => c.ToDto());
- return Ok(items);
+ _logger.LogInformation("API call - [GET] - SKIN");
+ try
+ {
+
+ var total = await dataManager.GetNbItems();
+ var skins = await dataManager.GetItems(request.offset, request.limit, request.orderingPropertyName, request.isDesc);
+ IEnumerable items = skins.Select(c => c.ToDto());
+ if (items.Count() == 0)
+ {
+ _logger.LogInformation("No skin found.");
+ return NotFound("No skin found.");
+ }
+ return Ok(items);
+ }
+ catch (Exception error)
+ {
+ return BadRequest(error.Message);
+ }
+
}
// GET api//5
[HttpGet("{name}")]
- public async Task Get(string name)
+ public async Task Get([FromQuery] PageRequest request, string name)
{
- var skins = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ _logger.LogInformation("API call - [GET / NAME] - SKIN");
+ try
+ {
+ if (dataManager.GetNbItemsByName(name) != null)
+ {
+ var skins = await dataManager.GetItemsByName(name, request.offset, request.limit, request.orderingPropertyName, request.isDesc);
+ IEnumerable items = skins.Select(c => c.ToDto());
+ if (items.Count() == 0)
+ {
+ _logger.LogInformation("No Skin found.");
+ return NotFound("No Skin found.");
+ }
- if (skins != null)
+ return Ok(items);
+ }
+ return NotFound("No Skin matching with this name.");
+ }
+ catch (Exception error)
{
- IEnumerable items = skins.Select(c => c.ToDto());
- return Ok(items);
+ return BadRequest(error.Message);
}
-
- return NotFound();
}
// POST api/
[HttpPost]
public async Task Post([FromBody] SkinDTO skinDTO)
{
+ _logger.LogInformation("API call - [POST] - SKIN");
- return CreatedAtAction(nameof(Get), (await dataManager.AddItem(skinDTO.ToModel())).ToDto);
+ try
+ {
+ if (await dataManager.GetNbItemsByName(skinDTO.Name) == 0)
+ {
+ await dataManager.AddItem(skinDTO.ToModel());
+ return CreatedAtAction(nameof(Get), skinDTO);
+ }
+ _logger.LogInformation("A Skin already exist with this Name. ( Unique Name )");
+ return BadRequest("A Skin already exist with this Name. ( Unique Name )");
+ }
+ catch (Exception error)
+ {
+ _logger.LogInformation("Error in the request");
+ return BadRequest(error.Message);
+ }
}
- // PUT api//5
+ // PUT api//5
[HttpPut("{name}")]
public async Task PutAsync(string name, [FromBody] SkinDTO skinDTO)
{
+ _logger.LogInformation("API call - [PUT / NAME] - SKIN");
+ try
+ {
+ var skin = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ Console.WriteLine(skin.First().Name);
+ var skin2 = await dataManager
+ .GetItemsByName(skinDTO.Name, 0, await dataManager.GetNbItems());
+ if (skin != null)
+ {
+ if (skin2.Count() == 0)
+ {
+ await dataManager.UpdateItem(skin.First(), skinDTO.ToModel());
+ return Ok();
- var dtos = (await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
- if(dtos != null) {
- return Ok(dataManager.UpdateItem(dtos.First(), skinDTO.ToModel()));
- }
- return NotFound();
+ }
+ _logger.LogInformation("Skin already exist with this unique name.");
+ return BadRequest("Skin already exist with this unique name.");
+ }
+ else
+ {
+ _logger.LogInformation("Skin not found.");
+ return NotFound("Skin not found.");
+ }
+ await dataManager.UpdateItem(skin.First(), skinDTO.ToModel());
+ return Ok();
- }
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+ }
+ }
// DELETE api//5
[HttpDelete("{name}")]
public async Task Delete(string name)
{
- var dtos = (await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
- return Ok(dataManager.DeleteItem(dtos.First()));
+ _logger.LogInformation("API call - [DELETE / NAME] - SKIN");
+ try
+ {
+ var skin = await (dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
+
+ if (skin.Count() != 0)
+ {
+ var skinDto = skin.First().ToDto();
+ await dataManager.DeleteItem(skin.First());
+ return Ok(skinDto);
+ }
+ else
+ {
+ _logger.LogInformation("No matching skin with this name");
+ return NotFound("No matching skin with this name");
+ }
+
+ }
+ catch (Exception error)
+ {
+ return BadRequest(error);
+ }
}
}
}
diff --git a/Sources/APILOL/Mapper/RuneMapper.cs b/Sources/APILOL/Mapper/RuneMapper.cs
new file mode 100644
index 0000000..e1a582b
--- /dev/null
+++ b/Sources/APILOL/Mapper/RuneMapper.cs
@@ -0,0 +1,24 @@
+using DTO;
+using Model;
+
+namespace APILOL.Mapper
+{
+ public static class RuneMapper
+ {
+ public static RuneDTO ToDto(this Rune rune)
+ {
+ return new RuneDTO()
+ {
+ Name = rune.Name,
+ Description = rune.Description,
+ Image = rune.Image.Base64,
+ Family = rune.Family,
+ };
+ }
+
+ public static Rune ToModel(this RuneDTO rune)
+ {
+ return new Rune(rune.Name, rune.Family, rune.Image, rune.Image, rune.Description);
+ }
+ }
+}
diff --git a/Sources/APILOL/Mapper/RunePageMapper.cs b/Sources/APILOL/Mapper/RunePageMapper.cs
new file mode 100644
index 0000000..6bc4de2
--- /dev/null
+++ b/Sources/APILOL/Mapper/RunePageMapper.cs
@@ -0,0 +1,22 @@
+using DTO;
+using Model;
+
+namespace APILOL.Mapper
+{
+ public static class RunePageMapper
+ {
+ public static RunePageDTO ToDto(this RunePage runePage)
+ {
+ return new RunePageDTO()
+ {
+ Name = runePage.Name,
+ Runes = runePage.Runes
+ };
+ }
+
+ public static RunePage ToModel(this RunePageDTO runePage)
+ {
+ return new RunePage(runePage.Name);
+ }
+ }
+}
diff --git a/Sources/APILOL/Program.cs b/Sources/APILOL/Program.cs
index 440cdf0..82a752c 100644
--- a/Sources/APILOL/Program.cs
+++ b/Sources/APILOL/Program.cs
@@ -1,3 +1,5 @@
+using Microsoft.AspNetCore.Mvc.Versioning;
+using Microsoft.Extensions.Options;
using Model;
using StubLib;
@@ -19,6 +21,8 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUI();
}
+app.UseStaticFiles();
+
app.UseHttpsRedirection();
app.UseAuthorization();
@@ -26,3 +30,13 @@ app.UseAuthorization();
app.MapControllers();
app.Run();
+
+builder.Services.AddApiVersioning(opt =>
+{
+ opt.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0);
+ opt.AssumeDefaultVersionWhenUnspecified = true;
+ opt.ReportApiVersions = true;
+ opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(),
+ new HeaderApiVersionReader("x-api-version"),
+ new MediaTypeApiVersionReader("x-api-version"));
+});
diff --git a/Sources/DTO/DTO.csproj b/Sources/DTO/DTO.csproj
index 94a926e..5c5bf12 100644
--- a/Sources/DTO/DTO.csproj
+++ b/Sources/DTO/DTO.csproj
@@ -16,4 +16,8 @@
+
+
+
+
diff --git a/Sources/DTO/RuneDTO.cs b/Sources/DTO/RuneDTO.cs
new file mode 100644
index 0000000..ae3d86a
--- /dev/null
+++ b/Sources/DTO/RuneDTO.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Model;
+
+namespace DTO
+{
+ public class RuneDTO
+ {
+ public string Name { get; set; }
+ public string Description { get; set; }
+
+ public string Image { get; set; }
+
+ public RuneFamily Family { get; set; }
+ }
+}
diff --git a/Sources/DTO/RunePageDTO.cs b/Sources/DTO/RunePageDTO.cs
new file mode 100644
index 0000000..7ce42b3
--- /dev/null
+++ b/Sources/DTO/RunePageDTO.cs
@@ -0,0 +1,12 @@
+using Model;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+
+namespace DTO
+{
+ public class RunePageDTO
+ {
+ public string Name { get; set; }
+ public ReadOnlyDictionary Runes { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Sources/Shared/IGenericDataManager.cs b/Sources/Shared/IGenericDataManager.cs
index a1a66f9..c31f5e8 100644
--- a/Sources/Shared/IGenericDataManager.cs
+++ b/Sources/Shared/IGenericDataManager.cs
@@ -6,7 +6,7 @@ public interface IGenericDataManager
Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false);
Task GetNbItemsByName(string substring);
Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false);
- Task UpdateItem(T oldItem, T newItem);
+ Task UpdateItem(T oldItem, T newItem);
Task AddItem(T item);
Task DeleteItem(T item);
}
diff --git a/Sources/StubLib/StubData.Champions.cs b/Sources/StubLib/StubData.Champions.cs
index 6d99c73..bd52f87 100644
--- a/Sources/StubLib/StubData.Champions.cs
+++ b/Sources/StubLib/StubData.Champions.cs
@@ -1,4 +1,6 @@
using System;
+using System.Data.SqlTypes;
+using System.Linq;
using Model;
namespace StubLib
@@ -90,7 +92,7 @@ namespace StubLib
.Select(tuple => tuple.Item1)
.Skip(index*count).Take(count));
- private Func filterByName = (champ, substring) => champ.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);
+ private Func filterByName = (champ, substring) => champ.Name.Equals(substring);
public Task GetNbItemsByName(string substring)
=> parent.champions.GetNbItemsWithFilter(champ => filterByName(champ, substring));
@@ -100,6 +102,7 @@ namespace StubLib
public Task UpdateItem(Champion? oldItem, Champion? newItem)
=> parent.champions.UpdateItem(oldItem, newItem);
+
}
}
}
\ No newline at end of file
diff --git a/Sources/StubLib/StubData.RunePages.cs b/Sources/StubLib/StubData.RunePages.cs
index a08a947..2854f1c 100644
--- a/Sources/StubLib/StubData.RunePages.cs
+++ b/Sources/StubLib/StubData.RunePages.cs
@@ -77,6 +77,7 @@ namespace StubLib
public Task UpdateItem(RunePage? oldItem, RunePage? newItem)
=> parent.runePages.UpdateItem(oldItem, newItem);
+
}
}
}
diff --git a/Sources/StubLib/StubData.Runes.cs b/Sources/StubLib/StubData.Runes.cs
index f0e8802..329620c 100644
--- a/Sources/StubLib/StubData.Runes.cs
+++ b/Sources/StubLib/StubData.Runes.cs
@@ -63,6 +63,7 @@ namespace StubLib
public Task UpdateItem(Rune? oldItem, Rune? newItem)
=> parent.runes.UpdateItem(oldItem, newItem);
+
}
}
}
diff --git a/Sources/StubLib/StubData.Skins.cs b/Sources/StubLib/StubData.Skins.cs
index ff5fc08..9d0b876 100644
--- a/Sources/StubLib/StubData.Skins.cs
+++ b/Sources/StubLib/StubData.Skins.cs
@@ -74,6 +74,7 @@ namespace StubLib
public Task UpdateItem(Skin? oldItem, Skin? newItem)
=> parent.skins.UpdateItem(oldItem, newItem);
+
}
}
}
diff --git a/Sources/TestUnitaire/TestUnitaire.csproj b/Sources/TestUnitaire/TestUnitaire.csproj
index 15f9233..f3e7145 100644
--- a/Sources/TestUnitaire/TestUnitaire.csproj
+++ b/Sources/TestUnitaire/TestUnitaire.csproj
@@ -9,6 +9,7 @@
+
diff --git a/Sources/TestUnitaire/UnitTestChampion.cs b/Sources/TestUnitaire/UnitTestChampion.cs
index 35e6ec0..512023b 100644
--- a/Sources/TestUnitaire/UnitTestChampion.cs
+++ b/Sources/TestUnitaire/UnitTestChampion.cs
@@ -1,8 +1,11 @@
using APILOL.Controllers;
+using APILOL.Controllers.Request;
using APILOL.Mapper;
using DTO;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging.Abstractions;
using StubLib;
+using System.Web.Http;
namespace TestUnitaire
{
@@ -14,13 +17,13 @@ namespace TestUnitaire
public UnitTestChampion()
{
stub = new StubData();
- controller = new ChampionsController();
+ controller = new ChampionsController(stub, new NullLogger());
}
[TestMethod]
public async Task TestGet()
{
- var champions = await controller.Get();
+ var champions = await controller.Get(new PageRequest());
var resultObject = champions as OkObjectResult;
Assert.IsNotNull(resultObject);
@@ -31,6 +34,17 @@ namespace TestUnitaire
Assert.AreEqual(resultType.Count(), await stub.ChampionsMgr.GetNbItems());
}
+ [TestMethod]
+ public void Get_OkResult_WhenChampExists()
+ {
+
+ // Act
+ Task result = controller.Get(new PageRequest());
+
+ // Assert
+ Assert.IsInstanceOfType(result, typeof(OkResult));
+ }
+
[TestMethod]
public async Task TestPost()
{