From d21cd47e8c6fed84bbca1569be97546c9f6ba302 Mon Sep 17 00:00:00 2001 From: "Jade.VAN_BRABANDT" Date: Mon, 8 Jan 2024 18:01:12 +0100 Subject: [PATCH] refactor : code smells --- Blazor/Blazor/Pages/Admins/AddAdministrator.razor.cs | 2 +- Blazor/Blazor/Pages/Admins/Administrators.razor.cs | 4 ++-- Blazor/Blazor/Pages/Chapters/AddChapter.razor.cs | 2 +- Blazor/Blazor/Pages/Chapters/Chapters.razor.cs | 4 ++-- Blazor/Blazor/Pages/Players/AddPlayer.razor.cs | 2 +- Blazor/Blazor/Pages/Players/Players.razor.cs | 4 ++-- Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs | 2 +- Blazor/Blazor/Pages/Questions/Questions.razor.cs | 4 ++-- Blazor/Blazor/Services/DataLocalService.cs | 10 +++++----- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Blazor/Blazor/Pages/Admins/AddAdministrator.razor.cs b/Blazor/Blazor/Pages/Admins/AddAdministrator.razor.cs index 7c69f7b..e4dac7d 100644 --- a/Blazor/Blazor/Pages/Admins/AddAdministrator.razor.cs +++ b/Blazor/Blazor/Pages/Admins/AddAdministrator.razor.cs @@ -32,7 +32,7 @@ namespace Blazor.Pages.Admins var formContent = new FormUrlEncodedContent(formData); - string apiUri = API.API_URL+"add/administrator"+"/"+API.TOKEN; + string apiUri = API.API_URL+"add/administrator/"+API.TOKEN; using (var httpClient = new HttpClient()) { diff --git a/Blazor/Blazor/Pages/Admins/Administrators.razor.cs b/Blazor/Blazor/Pages/Admins/Administrators.razor.cs index f17bdd1..5fd9ec7 100644 --- a/Blazor/Blazor/Pages/Admins/Administrators.razor.cs +++ b/Blazor/Blazor/Pages/Admins/Administrators.razor.cs @@ -44,7 +44,7 @@ public partial class Administrators } // When you use a real API, we use this follow code - var response = Http.GetFromJsonAsync(API.API_URL+"administrators"+"/"+API.TOKEN).Result; + var response = Http.GetFromJsonAsync(API.API_URL+"administrators/"+API.TOKEN).Result; if (!e.CancellationToken.IsCancellationRequested) { @@ -53,7 +53,7 @@ public partial class Administrators var currentData = await LocalStorage.GetItemAsync("data"); if (currentData == null || currentData.Length != administrators.Count) { - var originalData = Http.GetFromJsonAsync(API.API_URL + "administrators" + "/" + API.TOKEN).Result; + var originalData = Http.GetFromJsonAsync(API.API_URL + "administrators/" + API.TOKEN).Result; await LocalStorage.SetItemAsync("data", originalData); } } diff --git a/Blazor/Blazor/Pages/Chapters/AddChapter.razor.cs b/Blazor/Blazor/Pages/Chapters/AddChapter.razor.cs index 0e9b032..5389c76 100644 --- a/Blazor/Blazor/Pages/Chapters/AddChapter.razor.cs +++ b/Blazor/Blazor/Pages/Chapters/AddChapter.razor.cs @@ -29,7 +29,7 @@ public partial class AddChapter var formContent = new FormUrlEncodedContent(formData); - string apiUri = API.API_URL+"add/chapter"+"/"+API.TOKEN; + string apiUri = API.API_URL+"add/chapter/"+API.TOKEN; using (var httpClient = new HttpClient()) { diff --git a/Blazor/Blazor/Pages/Chapters/Chapters.razor.cs b/Blazor/Blazor/Pages/Chapters/Chapters.razor.cs index 4bb105b..473f408 100644 --- a/Blazor/Blazor/Pages/Chapters/Chapters.razor.cs +++ b/Blazor/Blazor/Pages/Chapters/Chapters.razor.cs @@ -92,7 +92,7 @@ public partial class Chapters return; } - var response = Http.GetFromJsonAsync(API.API_URL+"chapters"+"/"+API.TOKEN).Result; + var response = Http.GetFromJsonAsync(API.API_URL+"chapters/"+API.TOKEN).Result; if (!e.CancellationToken.IsCancellationRequested) { @@ -101,7 +101,7 @@ public partial class Chapters var currentData = await LocalStorage.GetItemAsync("data"); if (currentData == null || currentData.Length != chapters.Count) { - var originalData = Http.GetFromJsonAsync(API.API_URL+"chapters"+"/"+API.TOKEN).Result; + var originalData = Http.GetFromJsonAsync(API.API_URL+"chapters/"+API.TOKEN).Result; await LocalStorage.SetItemAsync("data", originalData); } } diff --git a/Blazor/Blazor/Pages/Players/AddPlayer.razor.cs b/Blazor/Blazor/Pages/Players/AddPlayer.razor.cs index 432f606..ca75be7 100644 --- a/Blazor/Blazor/Pages/Players/AddPlayer.razor.cs +++ b/Blazor/Blazor/Pages/Players/AddPlayer.razor.cs @@ -27,7 +27,7 @@ namespace Blazor.Pages.Players var formContent = new FormUrlEncodedContent(formData); - string apiUri =API.API_URL+"add/player"+"/"+API.TOKEN; + string apiUri =API.API_URL+"add/player/"+API.TOKEN; using (var httpClient = new HttpClient()) { diff --git a/Blazor/Blazor/Pages/Players/Players.razor.cs b/Blazor/Blazor/Pages/Players/Players.razor.cs index 2920a25..69ec5e4 100644 --- a/Blazor/Blazor/Pages/Players/Players.razor.cs +++ b/Blazor/Blazor/Pages/Players/Players.razor.cs @@ -87,7 +87,7 @@ public partial class Players return; } - var response = Http.GetFromJsonAsync(API.API_URL+"players"+"/"+API.TOKEN).Result; + var response = Http.GetFromJsonAsync(API.API_URL+"players/"+API.TOKEN).Result; if (!e.CancellationToken.IsCancellationRequested) { @@ -96,7 +96,7 @@ public partial class Players var currentData = await LocalStorage.GetItemAsync("data"); if (currentData == null || currentData.Length != players.Count) { - var originalData = Http.GetFromJsonAsync(API.API_URL+"players"+"/"+API.TOKEN).Result; + var originalData = Http.GetFromJsonAsync(API.API_URL+"players/"+API.TOKEN).Result; await LocalStorage.SetItemAsync("data", originalData); } } diff --git a/Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs b/Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs index 91eaca1..5667193 100644 --- a/Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs +++ b/Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs @@ -31,7 +31,7 @@ namespace Blazor.Pages.Questions var formContent = new FormUrlEncodedContent(formData); - string apiUri = API.API_URL+"add/administrator"+"/"+API.TOKEN; + string apiUri = API.API_URL+"add/administrator/"+API.TOKEN; using (var httpClient = new HttpClient()) { diff --git a/Blazor/Blazor/Pages/Questions/Questions.razor.cs b/Blazor/Blazor/Pages/Questions/Questions.razor.cs index 73e6d4e..03f416e 100644 --- a/Blazor/Blazor/Pages/Questions/Questions.razor.cs +++ b/Blazor/Blazor/Pages/Questions/Questions.razor.cs @@ -114,7 +114,7 @@ public partial class Questions private async Task Export() { StringBuilder sb = new StringBuilder(); - HttpResponseMessage response = await Http.GetAsync(API.API_URL+"questionsExport"+"/"+API.TOKEN); + HttpResponseMessage response = await Http.GetAsync(API.API_URL+"questionsExport/"+API.TOKEN); var json = await response.Content.ReadAsStringAsync(); using (var jsonFile = ChoJSONReader.LoadText(json)) { @@ -174,7 +174,7 @@ public partial class Questions } var formContent = new FormUrlEncodedContent(formData); - apiUri = API.API_URL+"add/questions"+"/"+API.TOKEN; + apiUri = API.API_URL+"add/questions/"+API.TOKEN; response = await Http.PostAsync(apiUri, formContent); diff --git a/Blazor/Blazor/Services/DataLocalService.cs b/Blazor/Blazor/Services/DataLocalService.cs index c424361..f0d761b 100644 --- a/Blazor/Blazor/Services/DataLocalService.cs +++ b/Blazor/Blazor/Services/DataLocalService.cs @@ -27,7 +27,7 @@ namespace Blazor.Services public async Task GetById(int id) { // Get the current data - var currentData = _http.GetFromJsonAsync>(API.API_URL+"chapters"+"/"+API.TOKEN).Result; + var currentData = _http.GetFromJsonAsync>(API.API_URL+"chapters/"+API.TOKEN).Result; // Get the chapter int the list var chapter = currentData.FirstOrDefault(w => w.Id == id); @@ -87,7 +87,7 @@ namespace Blazor.Services { // Get the current data //var currentData = await _localStorage.GetItemAsync>("data"); - var currentData = _http.GetFromJsonAsync>(API.API_URL+"chapters"+"/"+API.TOKEN).Result; + var currentData = _http.GetFromJsonAsync>(API.API_URL+"chapters/"+API.TOKEN).Result; // Get the chapter int the list var chapter = currentData.FirstOrDefault(w => w.Id == id); @@ -134,7 +134,7 @@ namespace Blazor.Services public async Task GetAdminById(int id) { // Get the current data - var currentData = _http.GetFromJsonAsync>(API.API_URL+"administrators"+"/"+API.TOKEN).Result; + var currentData = _http.GetFromJsonAsync>(API.API_URL+"administrators/"+API.TOKEN).Result; // Get the admin int the list var admin = currentData.FirstOrDefault(w => w.Id == id); @@ -227,7 +227,7 @@ namespace Blazor.Services public async Task GetQuestionById(int id) { // Get the current data - var currentData = _http.GetFromJsonAsync>(API.API_URL+"questions"+"/"+API.TOKEN).Result; + var currentData = _http.GetFromJsonAsync>(API.API_URL+"questions/"+API.TOKEN).Result; // Get the question int the list var question = currentData.FirstOrDefault(w => w.Q_id == id); @@ -319,7 +319,7 @@ namespace Blazor.Services public async Task GetPlayerById(int id) { // Get the current data - var currentData = _http.GetFromJsonAsync>(API.API_URL+"players"+"/"+API.TOKEN).Result; + var currentData = _http.GetFromJsonAsync>(API.API_URL+"players/"+API.TOKEN).Result; // Get the player in the list var player = currentData.FirstOrDefault(w => w.Id == id);