From 0bead3de61ca56e29aa8ce065677e838da8a2f2e Mon Sep 17 00:00:00 2001 From: tomivt Date: Sat, 8 Feb 2025 23:57:09 +0100 Subject: [PATCH] Code Smells from Service --- .../WF-WebAdmin/Service/LogsServiceStub.cs | 6 +++--- .../WF-WebAdmin/Service/QuizServiceStub.cs | 16 +++++++-------- .../WF-WebAdmin/Service/QuoteServiceLocal.cs | 6 +++--- .../WF-WebAdmin/Service/QuoteServiceStub.cs | 20 +++++++++---------- .../WF-WebAdmin/Service/UserServiceStub.cs | 14 +++++++------ 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Service/LogsServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/LogsServiceStub.cs index d933ed0..798df2d 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/LogsServiceStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/LogsServiceStub.cs @@ -37,7 +37,7 @@ namespace WF_WebAdmin.Service } - public async Task getNbLogs() + public Task getNbLogs() { throw new NotImplementedException(); } @@ -45,9 +45,9 @@ namespace WF_WebAdmin.Service public async Task> getSomeLogs(int nb, int page) { var logs = await getAllLogs(); - if ((page - 1) * nb + nb > logs.Count()) + if ((page - 1) * nb + nb > logs.Count) { - return logs.GetRange(logs.Count() - nb, nb); + return logs.GetRange(logs.Count - nb, nb); } return logs.GetRange((page - 1) * nb, nb); diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuizServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuizServiceStub.cs index 07914c1..bdbd507 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/QuizServiceStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuizServiceStub.cs @@ -134,7 +134,7 @@ public class QuizServiceStub: IQuizService public async Task> getQuizzesToValidate() { var quizzes = await getQuizzes(); - return quizzes.Where(quiz => quiz.IsValid == false).ToList(); + return quizzes.Where(quiz => !quiz.IsValid).ToList(); } @@ -151,11 +151,11 @@ public class QuizServiceStub: IQuizService { var data = await getQuizzes(); var q = data.FirstOrDefault(p => p.Id == id); - if (q != null) + if (q == null) { - return q; + throw new KeyNotFoundException($"Quiz with ID {id} not found."); } - return null; + return q; } /// @@ -173,13 +173,13 @@ public class QuizServiceStub: IQuizService public async Task> getSommeQuiz(int nb, int page) { var data = await getQuizzes(); - if ((page - 1) * nb + nb > data.Count()) + if ((page - 1) * nb + nb > data.Count) { - if (nb > data.Count()) + if (nb > data.Count) { - return data.GetRange(0, data.Count() - 1); + return data.GetRange(0, data.Count - 1); } - return data.GetRange(data.Count() - nb, nb); + return data.GetRange(data.Count - nb, nb); } return data.GetRange((page - 1) * nb, nb); } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs index 1b71866..1ac999a 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs @@ -38,7 +38,7 @@ namespace WF_WebAdmin.Service /* - // Ajouter des paramètres à la commande + Ajouter des paramètres à la commande command.Parameters.AddWithValue("@content", quote.Content); command.Parameters.AddWithValue("@langue", quote.Langue); command.Parameters.AddWithValue("@reason", "À vérifier"); // Vous pouvez changer ça si nécessaire @@ -110,10 +110,10 @@ namespace WF_WebAdmin.Service public Task validQuote(Quote quote) { QuoteExtension extension = new QuoteExtension(); - QuoteDto quoteDTO = extension.QuoteToDTO(quote); + QuoteDto quoteDto = extension.QuoteToDTO(quote); // Return the DTO as the result of this asynchronous operation (though no validation logic is currently implemented) - return Task.FromResult(quoteDTO); + return Task.FromResult(quoteDto); } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs index c66e4cf..52747ad 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs @@ -71,7 +71,7 @@ namespace WF_WebAdmin.Service; } - public async Task validQuote(Quote quote) + public Task validQuote(Quote quote) { throw new NotImplementedException(); } @@ -170,15 +170,15 @@ namespace WF_WebAdmin.Service; { var data = await getAllQuote(); var q = data.FirstOrDefault(p => p.Id == id); - if (q != null) + if (q == null) { - return q; + throw new KeyNotFoundException($"Quote with ID {id} not found."); } - return null; + return q; } - public async Task> reserchQuote(string reserch, List argument) + public Task> reserchQuote(string reserch, List argument) { throw new NotImplementedException(); } @@ -196,7 +196,7 @@ namespace WF_WebAdmin.Service; public async Task> getAllQuoteInvalid() { var quotes = await getAllQuote(); - quotes = quotes.Where(q => q.IsValid == false).ToList(); + quotes = quotes.Where(q => !q.IsValid).ToList(); return quotes; } @@ -218,13 +218,13 @@ namespace WF_WebAdmin.Service; public async Task> getSomeQuoteInvalid(int nb, int page) { var quotes = await getAllQuoteInvalid(); - if ((page - 1) * nb + nb > quotes.Count()) + if ((page - 1) * nb + nb > quotes.Count) { - if (nb > quotes.Count()) + if (nb > quotes.Count) { - return quotes.GetRange(0, quotes.Count()); + return quotes.GetRange(0, quotes.Count); } - return quotes.GetRange(quotes.Count() - nb, nb); + return quotes.GetRange(quotes.Count - nb, nb); } return quotes.GetRange((page - 1) * nb, nb); } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs index 53770a3..d4ca0fd 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs @@ -116,9 +116,9 @@ public class UserServiceStub : IUserService public async Task> getSomeUser(int nb, int page) { var users = await getAllUser(); - if ((page - 1) * nb + nb > users.Count()) + if ((page - 1) * nb + nb > users.Count) { - return users.GetRange(users.Count() - nb, nb); + return users.GetRange(users.Count - nb, nb); } return users.GetRange((page - 1) * nb, nb); } @@ -137,12 +137,14 @@ public class UserServiceStub : IUserService public async Task getOneUser(int id) { var data = await getAllUser(); - var u = data.FirstOrDefault(p => p.Id == id); - if (u != null) + var user = data.FirstOrDefault(p => p.Id == id); + + if (user == null) { - return u; + throw new KeyNotFoundException($"User with ID {id} not found."); } - return null; + + return user; }