From 7a68ce0d0d779fd1ac033df57c0de17a90cc1a03 Mon Sep 17 00:00:00 2001 From: Nathan BOILEAU Date: Wed, 8 Feb 2023 15:59:21 +0100 Subject: [PATCH 01/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index ace3152..8334648 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From cbc3c9461b524212cbd57d238bcb4eff37fe05e3 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Wed, 8 Feb 2023 16:04:24 +0100 Subject: [PATCH 02/34] Modif : gitignore no push sonar --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6c2aa92..5913f3d 100644 --- a/.gitignore +++ b/.gitignore @@ -428,4 +428,5 @@ FodyWeavers.xsd *.sln.iml *.db -*Migrations \ No newline at end of file +*Migrations +*.sonarqube \ No newline at end of file From 867f3428935c7266929c7b69fe0b64e06d13dbb3 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Thu, 9 Feb 2023 13:38:08 +0100 Subject: [PATCH 03/34] gitignore : add sonarqube --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6c2aa92..5913f3d 100644 --- a/.gitignore +++ b/.gitignore @@ -428,4 +428,5 @@ FodyWeavers.xsd *.sln.iml *.db -*Migrations \ No newline at end of file +*Migrations +*.sonarqube \ No newline at end of file From a446a44976690a1d803c3e5714f485dec206aa92 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Thu, 9 Feb 2023 13:44:22 +0100 Subject: [PATCH 04/34] correction ToModel de champion --- Sources/apiLOL/ChampionMapper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/apiLOL/ChampionMapper.cs b/Sources/apiLOL/ChampionMapper.cs index 564b52b..35c0e98 100644 --- a/Sources/apiLOL/ChampionMapper.cs +++ b/Sources/apiLOL/ChampionMapper.cs @@ -11,7 +11,9 @@ namespace apiLOL public static Champion ToModel(this ChampionDTO championDTO) { - return new Champion(championDTO.Name); + Champion champ = new Champion(championDTO.Name); + champ.Bio = championDTO.Bio; + return champ; } } From 06b1ae84b04390a1ae52d7be668b82a966816158 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Thu, 9 Feb 2023 13:54:33 +0100 Subject: [PATCH 05/34] Requete POST --- Sources/apiLOL/Controllers/ControllerChampions.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 00e2396..a6581fc 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -42,11 +42,12 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] - public IActionResult Post(ChampionDTO champDTO) + public async Task Post([FromBody] ChampionDTO champDTO) { Champion tmp = champDTO.ToModel(); - data.ChampionsMgr.AddItem(tmp); - return Ok(); + Champion champ = await data.ChampionsMgr.AddItem(tmp); + ChampionDTO dto = champ.ToDTO(); + return CreatedAtAction(nameof(GetChampion), new { name = dto.Name }, dto); } // PUT api//5 From 2f6c475ecdcf8885d0866bcc6506724efc4e6aa7 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Thu, 9 Feb 2023 13:57:19 +0100 Subject: [PATCH 06/34] Test Unitaire POST --- Sources/TestUnitaire/TestAPILol.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/TestUnitaire/TestAPILol.cs b/Sources/TestUnitaire/TestAPILol.cs index 43a6d08..20fc95b 100644 --- a/Sources/TestUnitaire/TestAPILol.cs +++ b/Sources/TestUnitaire/TestAPILol.cs @@ -28,7 +28,6 @@ namespace TestUnitaire Task nbItemTask = nbItem; // Assert - Assert.IsType(result); // Verify that the champions is added to the stub Assert.Equal(7, nbItemTask.Result); From 73d28960fe75899fa2684588ed40b492bee63bc4 Mon Sep 17 00:00:00 2001 From: Bastien OLLIER Date: Thu, 9 Feb 2023 14:03:35 +0100 Subject: [PATCH 07/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 8334648..ace3152 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From 6b645b9e3b99338bb076462d4708a0db54429f23 Mon Sep 17 00:00:00 2001 From: Bastien OLLIER Date: Thu, 9 Feb 2023 14:14:35 +0100 Subject: [PATCH 08/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index ace3152..8334648 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From 3b18159f14242d9765199db8005a564b39b31ad5 Mon Sep 17 00:00:00 2001 From: Bastien OLLIER Date: Thu, 9 Feb 2023 14:16:30 +0100 Subject: [PATCH 09/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 8334648..ace3152 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From c629765e33aee49188da85ecedd482a269e8c7b5 Mon Sep 17 00:00:00 2001 From: Bastien OLLIER Date: Thu, 9 Feb 2023 14:43:09 +0100 Subject: [PATCH 10/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'=20.drone.ym?= =?UTF-8?q?l'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml => .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .drone.yml => .drone.yml (99%) diff --git a/.drone.yml b/ .drone.yml similarity index 99% rename from .drone.yml rename to .drone.yml index ace3152..8334648 100644 --- a/.drone.yml +++ b/ .drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From bd28b706887702cce1e0889e78a95242d4bc4af4 Mon Sep 17 00:00:00 2001 From: Bastien OLLIER Date: Thu, 9 Feb 2023 14:43:35 +0100 Subject: [PATCH 11/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'=20.drone.ym?= =?UTF-8?q?l'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ .drone.yml b/ .drone.yml index 8334648..4a1a70f 100644 --- a/ .drone.yml +++ b/ .drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From 7db85395a66b3324c54c789fde7862d85ab14bd5 Mon Sep 17 00:00:00 2001 From: Bastien OLLIER Date: Thu, 9 Feb 2023 14:47:12 +0100 Subject: [PATCH 12/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'=20.drone.ym?= =?UTF-8?q?l'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ .drone.yml b/ .drone.yml index 4a1a70f..4185e1a 100644 --- a/ .drone.yml +++ b/ .drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From 2f000ba51a1a48fa14c64cb71e7f5e688505aa44 Mon Sep 17 00:00:00 2001 From: Bastien OLLIER Date: Thu, 9 Feb 2023 14:47:50 +0100 Subject: [PATCH 13/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'=20.drone.ym?= =?UTF-8?q?l'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ .drone.yml b/ .drone.yml index 4185e1a..4a1a70f 100644 --- a/ .drone.yml +++ b/ .drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From 7216ac7c5d337988942abec9be353c0088c90ad1 Mon Sep 17 00:00:00 2001 From: Nathan BOILEAU Date: Thu, 9 Feb 2023 14:48:44 +0100 Subject: [PATCH 14/34] Supprimer ' .drone.yml' --- .drone.yml | 66 ----------------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 .drone.yml diff --git a/ .drone.yml b/ .drone.yml deleted file mode 100644 index 4a1a70f..0000000 --- a/ .drone.yml +++ /dev/null @@ -1,66 +0,0 @@ -kind: pipeline -type: docker -name: default - -trigger: - event: - - push - -steps: - - name: build - image: mcr.microsoft.com/dotnet/sdk:6.0 - volumes: - - name: docs - path: /docs - commands: - - cd Sources/ - - dotnet restore LeagueOfLegends.sln - - dotnet build LeagueOfLegends.sln -c Release --no-restore - - dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release - - - name: tests - image: mcr.microsoft.com/dotnet/sdk:6.0 - commands: - - cd Sources/ - - dotnet restore LeagueOfLegends.sln - - dotnet test LeagueOfLegends.sln --no-restore - depends_on: [build] - - - name: code-analysis - image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 - commands: - - cd Sources/ - - dotnet restore LeagueOfLegends.sln - - dotnet sonarscanner begin /k:a /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} - - dotnet build LeagueOfLegends.sln -c Release --no-restore - - dotnet test LeagueOfLegends.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" - - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" - - dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release - - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} - secrets: [ SECRET_SONAR_LOGIN ] - settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} - sonar_host: https://codefirst.iut.uca.fr/sonar/ - # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} - sonar_token: - from_secret: SECRET_SONAR_LOGIN - depends_on: [tests] - - - name: generate-and-deploy-docs - image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer - failure: ignore - volumes: - - name: docs - path: /docs - commands: - #- cd Documentation/doxygen - #- doxygen Doxyfile - - /entrypoint.sh - when: - branch: - - master - depends_on: [ build ] - -volumes: -- name: docs - temp: {} \ No newline at end of file From e69aa37d766f9afc107c0bb43d1788f2ab9178ee Mon Sep 17 00:00:00 2001 From: Nathan BOILEAU Date: Thu, 9 Feb 2023 14:48:58 +0100 Subject: [PATCH 15/34] Ajouter '.drone.yml' --- .drone.yml | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..4a1a70f --- /dev/null +++ b/.drone.yml @@ -0,0 +1,66 @@ +kind: pipeline +type: docker +name: default + +trigger: + event: + - push + +steps: + - name: build + image: mcr.microsoft.com/dotnet/sdk:6.0 + volumes: + - name: docs + path: /docs + commands: + - cd Sources/ + - dotnet restore LeagueOfLegends.sln + - dotnet build LeagueOfLegends.sln -c Release --no-restore + - dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release + + - name: tests + image: mcr.microsoft.com/dotnet/sdk:6.0 + commands: + - cd Sources/ + - dotnet restore LeagueOfLegends.sln + - dotnet test LeagueOfLegends.sln --no-restore + depends_on: [build] + + - name: code-analysis + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 + commands: + - cd Sources/ + - dotnet restore LeagueOfLegends.sln + - dotnet sonarscanner begin /k:a /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + - dotnet build LeagueOfLegends.sln -c Release --no-restore + - dotnet test LeagueOfLegends.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + - dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release + - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + secrets: [ SECRET_SONAR_LOGIN ] + settings: + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + sonar_host: https://codefirst.iut.uca.fr/sonar/ + # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} + sonar_token: + from_secret: SECRET_SONAR_LOGIN + depends_on: [tests] + + - name: generate-and-deploy-docs + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer + failure: ignore + volumes: + - name: docs + path: /docs + commands: + #- cd Documentation/doxygen + #- doxygen Doxyfile + - /entrypoint.sh + when: + branch: + - master + depends_on: [ build ] + +volumes: +- name: docs + temp: {} \ No newline at end of file From 84f8e940d060812f00a25ca7d23bb135c63792fb Mon Sep 17 00:00:00 2001 From: Bastien OLLIER Date: Thu, 9 Feb 2023 14:54:39 +0100 Subject: [PATCH 16/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 4a1a70f..4185e1a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From 90d6ffa765485e2d448ab074c462406d350da39c Mon Sep 17 00:00:00 2001 From: Nathan BOILEAU Date: Thu, 9 Feb 2023 14:57:59 +0100 Subject: [PATCH 17/34] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 4185e1a..5db9dbb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,7 @@ steps: - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} secrets: [ SECRET_SONAR_LOGIN ] settings: - # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} sonar_host: https://codefirst.iut.uca.fr/sonar/ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} sonar_token: From 21109c85e4dd4b560614fe694ce9267c0836a35c Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Thu, 9 Feb 2023 15:15:19 +0100 Subject: [PATCH 18/34] add delete api --- Sources/apiLOL/Controllers/ControllerChampions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index a6581fc..91d71f2 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -57,9 +57,11 @@ namespace apiLOL.Controllers } // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) + [HttpDelete("{name}")] + public async void Delete(String name) { + var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); + data.ChampionsMgr.DeleteItem(champ); } } From ec9ad445da475eba01cc46513ba6d27bd8518162 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Thu, 9 Feb 2023 15:19:57 +0100 Subject: [PATCH 19/34] Test unitaire : POST + GET --- Sources/TestUnitaire/TestAPILol.cs | 43 +++++++++++++------ .../apiLOL/Controllers/ControllerChampions.cs | 8 ++-- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Sources/TestUnitaire/TestAPILol.cs b/Sources/TestUnitaire/TestAPILol.cs index 20fc95b..02dbdee 100644 --- a/Sources/TestUnitaire/TestAPILol.cs +++ b/Sources/TestUnitaire/TestAPILol.cs @@ -7,30 +7,49 @@ namespace TestUnitaire { public class TestAPILol { - [Fact] - public void Test1() + [Theory] + [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] + [InlineData("Ahri", "Ahri est un champion de League of Legends")] + [InlineData("Akali", "Akali est un champion de League of Legends")] + public async Task TestPostChampion(string name, string bio) { + // Arrange + var data = new StubData(); + var controller = new ControllerChampions(new StubData()); + var champDTO = new ChampionDTO(name, bio); + + // Act + var nbInListBefore = data.ChampionsMgr.GetNbItems().Result; + var result = await controller.Post(champDTO); + var nbInListAfter = data.ChampionsMgr.GetNbItems().Result; + // Assert + // IS the champion added to the list, number of champions in the list + 1 + Assert.Equal(nbInListBefore + 1, nbInListAfter); } - [Fact] - public void TestPostChampion() + + [Theory] + [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] + [InlineData("Ahri", "Ahri est un champion de League of Legends")] + [InlineData("Akali", "Akali est un champion de League of Legends")] + public async Task TestGetChampion(string name, string bio) { // Arrange var data = new StubData(); var controller = new ControllerChampions(new StubData()); - var champDTO = new ChampionDTO("Charles", "Charles est un champion de League of Legends"); + var champDTO = new ChampionDTO(name, bio); // Act - var result = controller.Post(champDTO); - data.ChampionsMgr.AddItem(champDTO.ToModel()); - var nbItem = data.ChampionsMgr.GetNbItems(); - Task nbItemTask = nbItem; + // Call method POST to add a champion + var result = await controller.Post(champDTO); + // Call method GET to get the champion + var resultGet = await controller.GetChampion(name); // Assert - // Verify that the champions is added to the stub - Assert.Equal(7, nbItemTask.Result); - + // IS the champion added to the list, number of champions in the list + 1 + Assert.Equal(name, champDTO.Name); + Assert.Equal(bio, champDTO.Bio); } } } \ No newline at end of file diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index a6581fc..91e39b2 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -42,12 +42,12 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] - public async Task Post([FromBody] ChampionDTO champDTO) + public async Task Post(ChampionDTO champDTO) { Champion tmp = champDTO.ToModel(); - Champion champ = await data.ChampionsMgr.AddItem(tmp); - ChampionDTO dto = champ.ToDTO(); - return CreatedAtAction(nameof(GetChampion), new { name = dto.Name }, dto); + Champion champion = await data.ChampionsMgr.AddItem(tmp); + ChampionDTO dtoChamp = champion.ToDTO(); + return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp); } // PUT api//5 From e2dec91fd2e1018b064c18ba731ca2c9f298f27e Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Tue, 21 Feb 2023 18:23:09 +0100 Subject: [PATCH 20/34] Add : Log on method of the controller --- Sources/apiLOL/Controllers/ControllerChampions.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 3d6a80b..5911c45 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -12,12 +12,13 @@ namespace apiLOL.Controllers public class ControllerChampions : Controller { private readonly IDataManager data; - - + private readonly ILogger _logger; - public ControllerChampions(IDataManager manager) + + public ControllerChampions(IDataManager manager, ILogger log) { data = manager; + _logger = log; } @@ -25,6 +26,8 @@ namespace apiLOL.Controllers [HttpGet] public async Task Get() { + _logger.LogInformation($"methode Get de ControllerChampions appelée"); + _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); return Ok(champs); } @@ -35,6 +38,7 @@ namespace apiLOL.Controllers [Route("{name}")] public async Task GetChampion(string name) { + _logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}"); var champs = (await data.ChampionsMgr.GetItemsByName(name,0,1)).First(); return Ok(champs.ToDTO()); } @@ -44,6 +48,7 @@ namespace apiLOL.Controllers [HttpPost] public async Task Post(ChampionDTO champDTO) { + _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); Champion tmp = champDTO.ToModel(); Champion champion = await data.ChampionsMgr.AddItem(tmp); ChampionDTO dtoChamp = champion.ToDTO(); From 1edff0366aa7902208deae68e2461da02a90ae44 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Tue, 21 Feb 2023 18:32:17 +0100 Subject: [PATCH 21/34] Add example : Filter --- Sources/apiLOL/Controllers/ControllerChampions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 5911c45..7bc619f 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,8 +24,9 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get() + public async Task Get([FromQuery] string name = "") { + //FromQuery permet de filtrer dans la collection de champions en fonction du nom _logger.LogInformation($"methode Get de ControllerChampions appelée"); _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); From 57a6046a0580341ac2b20ea00ca48503bde92266 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Tue, 21 Feb 2023 18:51:33 +0100 Subject: [PATCH 22/34] Add example pagination --- Sources/apiLOL/ChampionPageDTO.cs | 13 +++++++++++++ Sources/apiLOL/Controllers/ControllerChampions.cs | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Sources/apiLOL/ChampionPageDTO.cs diff --git a/Sources/apiLOL/ChampionPageDTO.cs b/Sources/apiLOL/ChampionPageDTO.cs new file mode 100644 index 0000000..5fff791 --- /dev/null +++ b/Sources/apiLOL/ChampionPageDTO.cs @@ -0,0 +1,13 @@ +namespace apiLOL +{ + public class ChampionPageDTO + { + public IEnumerable Data { get; set; } + + public int Index { get; set; } + + public int Count { get; set; } + + public int TotalCount { get; set; } + } +} diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 7bc619f..5e1a255 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,13 +24,22 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get([FromQuery] string name = "") + public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom _logger.LogInformation($"methode Get de ControllerChampions appelée"); _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); + var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); - return Ok(champs); + + var page = new ChampionPageDTO + { + Data = champs, + Index = index, + Count = count, + TotalCount = 100 + }; + return Ok(page); } From 94f1ec76e632bd0f45303397802a61d7974b878e Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Wed, 22 Feb 2023 15:35:02 +0100 Subject: [PATCH 23/34] Commentaire --- Sources/apiLOL/Controllers/ControllerChampions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 5e1a255..242abe6 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -27,6 +27,7 @@ namespace apiLOL.Controllers public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom + // Possible de faire une classe PageRequest pour gérer les paramètres index et count _logger.LogInformation($"methode Get de ControllerChampions appelée"); _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); From 05ed2809d455b74c7e056a4101c6c21bc97ca8b7 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Wed, 22 Feb 2023 15:49:29 +0100 Subject: [PATCH 24/34] test --- Sources/apiLOL/ChampionDTO.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/apiLOL/ChampionDTO.cs b/Sources/apiLOL/ChampionDTO.cs index 253af0a..f015a14 100644 --- a/Sources/apiLOL/ChampionDTO.cs +++ b/Sources/apiLOL/ChampionDTO.cs @@ -11,6 +11,6 @@ public string Name { get; set; } - public string Bio { get; set; } + public string Bio { get; set; } } } From a2e49a7cde2ea280c4b483a0ce73e5cdaa0ea000 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Wed, 22 Feb 2023 15:53:54 +0100 Subject: [PATCH 25/34] test --- Sources/apiLOL/ChampionMapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/apiLOL/ChampionMapper.cs b/Sources/apiLOL/ChampionMapper.cs index 35c0e98..4a27adf 100644 --- a/Sources/apiLOL/ChampionMapper.cs +++ b/Sources/apiLOL/ChampionMapper.cs @@ -14,7 +14,7 @@ namespace apiLOL Champion champ = new Champion(championDTO.Name); champ.Bio = championDTO.Bio; return champ; - } + } } } From c9066e286213394a926af012f99e83a92ecc3940 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Fri, 24 Feb 2023 15:45:17 +0100 Subject: [PATCH 26/34] gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5913f3d..1132ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -428,5 +428,7 @@ FodyWeavers.xsd *.sln.iml *.db +*.db-shm +*.db-wal *Migrations *.sonarqube \ No newline at end of file From 8caf88020d3b2ba37529ab13ad2dea080d53f131 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 16:04:24 +0100 Subject: [PATCH 27/34] add get avec Pagination --- Sources/apiLOL/Controllers/ControllerChampions.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 242abe6..1c36c13 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,21 +24,23 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") + public async Task Get(int index = 0, int count = 10) { //FromQuery permet de filtrer dans la collection de champions en fonction du nom // Possible de faire une classe PageRequest pour gérer les paramètres index et count _logger.LogInformation($"methode Get de ControllerChampions appelée"); - _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); - - var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); + int nbChampions = await data.ChampionsMgr.GetNbItems(); + _logger.LogInformation($"Nombre de champions : {nbChampions}"); + + //var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); + var champs = (await data.ChampionsMgr.GetItems(index, count)).Select(Model => Model.ToDTO()); var page = new ChampionPageDTO { Data = champs, Index = index, Count = count, - TotalCount = 100 + TotalCount = nbChampions }; return Ok(page); } From 8331dfec7cab4cea41e4d3053b2008de1015abf9 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 16:14:08 +0100 Subject: [PATCH 28/34] add put bio --- Sources/apiLOL/Controllers/ControllerChampions.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 1c36c13..17add29 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,7 +24,7 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get(int index = 0, int count = 10) + public async Task Get([FromQuery]int index = 0, int count = 10, string nom="") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom // Possible de faire une classe PageRequest pour gérer les paramètres index et count @@ -32,7 +32,6 @@ namespace apiLOL.Controllers int nbChampions = await data.ChampionsMgr.GetNbItems(); _logger.LogInformation($"Nombre de champions : {nbChampions}"); - //var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); var champs = (await data.ChampionsMgr.GetItems(index, count)).Select(Model => Model.ToDTO()); var page = new ChampionPageDTO @@ -69,9 +68,12 @@ namespace apiLOL.Controllers } // PUT api//5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) + [HttpPut("{name}")] + public async Task Put( string name, string bio) { + var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); + champs.Bio = bio; + return Ok(champs.ToDTO()); } // DELETE api//5 From eef6707273ca2b4f2d0f6b3e88eea1eed7227829 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Fri, 24 Feb 2023 16:15:01 +0100 Subject: [PATCH 29/34] Supp weather + versionning sur champions --- .../apiLOL/Controllers/ControllerChampions.cs | 10 ++++-- .../Controllers/WeatherForecastController.cs | 33 ------------------- Sources/apiLOL/WeatherForecast.cs | 13 -------- Sources/apiLOL/apiLOL.csproj | 1 + 4 files changed, 9 insertions(+), 48 deletions(-) delete mode 100644 Sources/apiLOL/Controllers/WeatherForecastController.cs delete mode 100644 Sources/apiLOL/WeatherForecast.cs diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 242abe6..faf99f0 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -8,13 +8,14 @@ using static StubLib.StubData; namespace apiLOL.Controllers { [ApiController] - [Route("api/[controller]")] + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("1.0")] + public class ControllerChampions : Controller { private readonly IDataManager data; private readonly ILogger _logger; - public ControllerChampions(IDataManager manager, ILogger log) { data = manager; @@ -24,6 +25,7 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] + [MapToApiVersion("1.0")] public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom @@ -47,6 +49,7 @@ namespace apiLOL.Controllers // GET api//Charle [HttpGet] [Route("{name}")] + [MapToApiVersion("2.0")] public async Task GetChampion(string name) { _logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}"); @@ -57,6 +60,7 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] + [MapToApiVersion("1.0")] public async Task Post(ChampionDTO champDTO) { _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); @@ -68,12 +72,14 @@ namespace apiLOL.Controllers // PUT api//5 [HttpPut("{id}")] + [MapToApiVersion("1.0")] public void Put(int id, [FromBody] string value) { } // DELETE api//5 [HttpDelete("{name}")] + [MapToApiVersion("1.0")] public async void Delete(String name) { var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); diff --git a/Sources/apiLOL/Controllers/WeatherForecastController.cs b/Sources/apiLOL/Controllers/WeatherForecastController.cs deleted file mode 100644 index c8e4063..0000000 --- a/Sources/apiLOL/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace apiLOL.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 _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable 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(); - } - } -} \ No newline at end of file diff --git a/Sources/apiLOL/WeatherForecast.cs b/Sources/apiLOL/WeatherForecast.cs deleted file mode 100644 index e380cd6..0000000 --- a/Sources/apiLOL/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace apiLOL -{ - 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; } - } -} \ No newline at end of file diff --git a/Sources/apiLOL/apiLOL.csproj b/Sources/apiLOL/apiLOL.csproj index 82733d5..b90f766 100644 --- a/Sources/apiLOL/apiLOL.csproj +++ b/Sources/apiLOL/apiLOL.csproj @@ -7,6 +7,7 @@ + From 94c54499bf9be11efbb44a3e0ce6e86c7bcaa105 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 16:18:57 +0100 Subject: [PATCH 30/34] add log to put --- Sources/apiLOL/Controllers/ControllerChampions.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 17add29..1feacd7 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -71,6 +71,8 @@ namespace apiLOL.Controllers [HttpPut("{name}")] public async Task Put( string name, string bio) { + _logger.LogInformation($"methode Put de ControllerChampions appelée avec le paramètre name: {name} et bio: {bio}"); + var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); champs.Bio = bio; return Ok(champs.ToDTO()); From 050c8461f26fa966b6929bdbfb4ea6d5ba2b131a Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Fri, 24 Feb 2023 16:23:28 +0100 Subject: [PATCH 31/34] versionning --- Sources/apiLOL/Controllers/ControllerChampions.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 93d2270..dcd6754 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -1,14 +1,11 @@ using Microsoft.AspNetCore.Mvc; using Model; -using StubLib; -using System.Xml.Linq; -using static StubLib.StubData; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace apiLOL.Controllers { [ApiController] - [Route("api/v{version:apiVersion}/[controller]")] + [Route("api/v1/[controller]")] [ApiVersion("1.0")] public class ControllerChampions : Controller @@ -25,7 +22,6 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - [MapToApiVersion("1.0")] public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom @@ -50,7 +46,6 @@ namespace apiLOL.Controllers // GET api//Charle [HttpGet] [Route("{name}")] - [MapToApiVersion("2.0")] public async Task GetChampion(string name) { _logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}"); @@ -61,7 +56,6 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] - [MapToApiVersion("1.0")] public async Task Post(ChampionDTO champDTO) { _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); @@ -73,7 +67,6 @@ namespace apiLOL.Controllers // PUT api//5 [HttpPut("{name}")] - [MapToApiVersion("1.0")] public async Task Put(string name, string bio) { var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); @@ -83,7 +76,6 @@ namespace apiLOL.Controllers // DELETE api//5 [HttpDelete("{name}")] - [MapToApiVersion("1.0")] public async void Delete(String name) { var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); From 55e062847e2beebcaf0069e2e2d88328cc7e4d60 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 16:58:37 +0100 Subject: [PATCH 32/34] add test des parametre de l'api --- .../apiLOL/Controllers/ControllerChampions.cs | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 1feacd7..5be9b16 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,7 +24,7 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get([FromQuery]int index = 0, int count = 10, string nom="") + public async Task Get([FromQuery]int index = 0, int count = 10) { //FromQuery permet de filtrer dans la collection de champions en fonction du nom // Possible de faire une classe PageRequest pour gérer les paramètres index et count @@ -51,8 +51,15 @@ namespace apiLOL.Controllers public async Task GetChampion(string name) { _logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}"); - var champs = (await data.ChampionsMgr.GetItemsByName(name,0,1)).First(); - return Ok(champs.ToDTO()); + try + { + var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)); + return Ok(champs.First().ToDTO()); + } + catch + { + return BadRequest("erreur de nom de champion"); + } } @@ -73,17 +80,32 @@ namespace apiLOL.Controllers { _logger.LogInformation($"methode Put de ControllerChampions appelée avec le paramètre name: {name} et bio: {bio}"); - var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); - champs.Bio = bio; - return Ok(champs.ToDTO()); + try + { + var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); + champs.Bio = bio; + return Ok(champs.ToDTO()); + } + catch + { + return BadRequest("erreur de nom de champion"); + } } // DELETE api//5 [HttpDelete("{name}")] - public async void Delete(String name) + public async Task Delete(String name) { - var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); - data.ChampionsMgr.DeleteItem(champ); + try + { + var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); + data.ChampionsMgr.DeleteItem(champ); + return Ok(champ.ToDTO()); + } + catch + { + return BadRequest("erreur de nom de champion"); + } } } From cce59a0adfb3a3d99c5ed2d92d5eaa9e9be47fc9 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 17:06:53 +0100 Subject: [PATCH 33/34] modif mapper --- Sources/apiLOL/ChampionMapper.cs | 6 ++---- .../apiLOL/Controllers/ControllerChampions.cs | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Sources/apiLOL/ChampionMapper.cs b/Sources/apiLOL/ChampionMapper.cs index 4a27adf..a7009ab 100644 --- a/Sources/apiLOL/ChampionMapper.cs +++ b/Sources/apiLOL/ChampionMapper.cs @@ -4,10 +4,8 @@ namespace apiLOL { public static class ChampionMapper { - public static ChampionDTO ToDTO(this Champion champion) - { - return new ChampionDTO(champion.Name, champion.Bio); - } + public static ChampionDTO ToDTO(this Champion champion) => new ChampionDTO(champion.Name, champion.Bio); + public static Champion ToModel(this ChampionDTO championDTO) { diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 8243e03..18bb600 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -66,10 +66,19 @@ namespace apiLOL.Controllers public async Task Post(ChampionDTO champDTO) { _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); - Champion tmp = champDTO.ToModel(); - Champion champion = await data.ChampionsMgr.AddItem(tmp); - ChampionDTO dtoChamp = champion.ToDTO(); - return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp); + + + try + { + Champion tmp = champDTO.ToModel(); + Champion champion = await data.ChampionsMgr.AddItem(tmp); + ChampionDTO dtoChamp = champion.ToDTO(); + return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp); + } + catch + { + return BadRequest("le champion existe deja"); + } } // PUT api//5 From 019c8366b02e7b277997660b8e83a6bf157138e7 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Fri, 24 Feb 2023 17:09:03 +0100 Subject: [PATCH 34/34] Modif test unitaire --- Sources/TestUnitaire/TestAPILol.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Sources/TestUnitaire/TestAPILol.cs b/Sources/TestUnitaire/TestAPILol.cs index 02dbdee..e819972 100644 --- a/Sources/TestUnitaire/TestAPILol.cs +++ b/Sources/TestUnitaire/TestAPILol.cs @@ -1,6 +1,8 @@ using apiLOL; using apiLOL.Controllers; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using StubLib; namespace TestUnitaire @@ -8,14 +10,15 @@ namespace TestUnitaire public class TestAPILol { [Theory] - [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] - [InlineData("Ahri", "Ahri est un champion de League of Legends")] - [InlineData("Akali", "Akali est un champion de League of Legends")] + [InlineData("Beatrice", "sdfsdfd")] + [InlineData("Maurice", "Ahri est un champion de League of Legends")] + [InlineData("Loupiotte", "Akali est un champion de League of Legends")] public async Task TestPostChampion(string name, string bio) { // Arrange var data = new StubData(); - var controller = new ControllerChampions(new StubData()); + var logger = new NullLogger(); + var controller = new ControllerChampions(data, logger); var champDTO = new ChampionDTO(name, bio); // Act @@ -30,14 +33,15 @@ namespace TestUnitaire [Theory] - [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] - [InlineData("Ahri", "Ahri est un champion de League of Legends")] - [InlineData("Akali", "Akali est un champion de League of Legends")] + [InlineData("Beatrice", "Aatrox est un champion de League of Legends")] + [InlineData("Maurice", "Ahri est un champion de League of Legends")] + [InlineData("Loupiotte", "Akali est un champion de League of Legends")] public async Task TestGetChampion(string name, string bio) { // Arrange var data = new StubData(); - var controller = new ControllerChampions(new StubData()); + var logger = new NullLogger(); + var controller = new ControllerChampions(data, logger); var champDTO = new ChampionDTO(name, bio); // Act