From ca2f9f36a813ee6f11a3a9266e736ae781d6af2f Mon Sep 17 00:00:00 2001 From: "jeremy.ducourthial" Date: Sun, 14 Jan 2024 14:44:00 +0100 Subject: [PATCH] fix : pagination avec Api --- Blazor/Blazor/Pages/Admins/Administrators.razor.cs | 4 ++-- Blazor/Blazor/Pages/Chapters/Chapters.razor.cs | 4 ++-- Blazor/Blazor/Pages/Players/Players.razor.cs | 4 ++-- Blazor/Blazor/Pages/Questions/Questions.razor.cs | 4 ++-- Blazor/Blazor/ViewClasses/Administrator.cs | 1 + Blazor/Blazor/ViewClasses/Chapter.cs | 1 + Blazor/Blazor/ViewClasses/Player.cs | 2 +- Blazor/Blazor/ViewClasses/Question.cs | 3 +-- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Blazor/Blazor/Pages/Admins/Administrators.razor.cs b/Blazor/Blazor/Pages/Admins/Administrators.razor.cs index 75b8fbd..fc9d6bc 100644 --- a/Blazor/Blazor/Pages/Admins/Administrators.razor.cs +++ b/Blazor/Blazor/Pages/Admins/Administrators.razor.cs @@ -47,12 +47,12 @@ public partial class Administrators int page = ((e.Page - 1) * e.PageSize) / 10 + 1; // Envoyez une requête à l'API pour récupérer les questions de la page actuelle - var response = await Http.GetFromJsonAsync(API.API_URL + "administrators/" + API.TOKEN + $"?page={page}"); + var response = await Http.GetFromJsonAsync(API.API_URL + "all/administrators/" + API.TOKEN + "/" + page); if (!e.CancellationToken.IsCancellationRequested && response != null) { administrators = new List(response); // an actual data for the current page - totalItem = administrators.Count; + totalItem = response[0].total_administrators; } } diff --git a/Blazor/Blazor/Pages/Chapters/Chapters.razor.cs b/Blazor/Blazor/Pages/Chapters/Chapters.razor.cs index 65c33b0..517d0e8 100644 --- a/Blazor/Blazor/Pages/Chapters/Chapters.razor.cs +++ b/Blazor/Blazor/Pages/Chapters/Chapters.razor.cs @@ -81,12 +81,12 @@ public partial class Chapters int page = ((e.Page - 1) * e.PageSize) / 10 + 1; // Envoyez une requête à l'API pour récupérer les questions de la page actuelle - var response = await Http.GetFromJsonAsync(API.API_URL + "chapters/" + API.TOKEN + $"?page={page}"); + var response = await Http.GetFromJsonAsync(API.API_URL + "all/chapters/" + API.TOKEN + "/" + page); if (!e.CancellationToken.IsCancellationRequested) { chapters = new List(response); // an actual data for the current page - totalChapter = chapters.Count; + totalChapter = response[0].total_chapters; } } } diff --git a/Blazor/Blazor/Pages/Players/Players.razor.cs b/Blazor/Blazor/Pages/Players/Players.razor.cs index b63eb82..4b047dc 100644 --- a/Blazor/Blazor/Pages/Players/Players.razor.cs +++ b/Blazor/Blazor/Pages/Players/Players.razor.cs @@ -82,12 +82,12 @@ public partial class Players int page = ((e.Page - 1) * e.PageSize) / 10 + 1; // Envoyez une requête à l'API pour récupérer les questions de la page actuelle - var response = await Http.GetFromJsonAsync(API.API_URL + "players/" + API.TOKEN + $"?page={page}"); + var response = await Http.GetFromJsonAsync(API.API_URL + "all/players/" + API.TOKEN + "/" + page); if (!e.CancellationToken.IsCancellationRequested) { players = new List(response); // an actual data for the current page - totalPlayer = players.Count; + totalPlayer = response[0].total_players; ; } } } diff --git a/Blazor/Blazor/Pages/Questions/Questions.razor.cs b/Blazor/Blazor/Pages/Questions/Questions.razor.cs index 6ad0be9..865bde5 100644 --- a/Blazor/Blazor/Pages/Questions/Questions.razor.cs +++ b/Blazor/Blazor/Pages/Questions/Questions.razor.cs @@ -88,7 +88,7 @@ public partial class Questions int page = ((e.Page - 1) * e.PageSize)/10 + 1; // Envoyez une requête à l'API pour récupérer les questions de la page actuelle - var response = await Http.GetFromJsonAsync(API.API_URL + "questions/" + API.TOKEN + $"?page={page}"); + var response = await Http.GetFromJsonAsync(API.API_URL + "all/questions/" + API.TOKEN + "/" + page); if (!e.CancellationToken.IsCancellationRequested && response != null) { @@ -101,7 +101,7 @@ public partial class Questions } questions = selectedQuestions; - totalQuestion = questions.Count; + totalQuestion = response[0].total_questions; } } diff --git a/Blazor/Blazor/ViewClasses/Administrator.cs b/Blazor/Blazor/ViewClasses/Administrator.cs index 93a5ceb..85b5969 100644 --- a/Blazor/Blazor/ViewClasses/Administrator.cs +++ b/Blazor/Blazor/ViewClasses/Administrator.cs @@ -5,5 +5,6 @@ public class Administrator public int Id { get; set; } public string Username { get; set; } public string HashedPassword { get; set; } + public int total_administrators { get; set; } } diff --git a/Blazor/Blazor/ViewClasses/Chapter.cs b/Blazor/Blazor/ViewClasses/Chapter.cs index 942eb72..b61f0e1 100644 --- a/Blazor/Blazor/ViewClasses/Chapter.cs +++ b/Blazor/Blazor/ViewClasses/Chapter.cs @@ -4,4 +4,5 @@ public class Chapter { public int Id { get; set; } public string Name { get; set; } + public int total_chapters { get; set; } } diff --git a/Blazor/Blazor/ViewClasses/Player.cs b/Blazor/Blazor/ViewClasses/Player.cs index 8ea29fd..ec95461 100644 --- a/Blazor/Blazor/ViewClasses/Player.cs +++ b/Blazor/Blazor/ViewClasses/Player.cs @@ -5,5 +5,5 @@ public class Player public int Id { get; set; } public string Nickname { get; set; } public string HashedPassword { get; set; } - + public int total_players { get; set; } } diff --git a/Blazor/Blazor/ViewClasses/Question.cs b/Blazor/Blazor/ViewClasses/Question.cs index 4ba3f58..50ca24a 100644 --- a/Blazor/Blazor/ViewClasses/Question.cs +++ b/Blazor/Blazor/ViewClasses/Question.cs @@ -17,6 +17,5 @@ public class Question public int IdAnswerGood { get; set; } public int A_id { get; set; } public string A_content { get; set; } - - + public int total_questions { get; set;} }