From 27016668bde8f5cb633e7a7ada0225a2abf268bc Mon Sep 17 00:00:00 2001 From: tomivt Date: Mon, 10 Feb 2025 11:22:51 +0100 Subject: [PATCH] Code Smells from Pages/Edit --- .../WF-WebAdmin/Converter/QuoteExtension.cs | 2 +- WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor | 16 ++--- WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs | 61 +++++++++++-------- .../WF-WebAdmin/Service/IQuoteService.cs | 6 +- .../WF-WebAdmin/Service/QuoteServiceLocal.cs | 10 +-- .../WF-WebAdmin/Service/QuoteServiceStub.cs | 6 +- 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs index 35239e4..451f027 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs @@ -4,7 +4,7 @@ namespace WF_WebAdmin.Converter { public class QuoteExtension { - public QuoteDto QuoteToDTO(Quote q) + public QuoteDto QuoteToDTO(Quote? q) { QuoteDto quote = new QuoteDto(q.Id, q.Content, q.Like, q.Langue, q.IsValid,null, null,q.Charac,null,q.TitleSrc,q.DateSrc,null,q.UserProposition,null,q.ImgPath); return quote; diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor index edb3822..85e5e44 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor @@ -3,29 +3,29 @@

Editer

- +

@@ -37,23 +37,23 @@ namespace WF_WebAdmin.Pages protected override async Task OnInitializedAsync() { // Fetch the quote data based on the provided ID. - q = await quoteService.getOnequote(Id); + Q = await quoteService.getOnequote(Id); // Populate the quoteModel with the data from the retrieved quote. - quoteModel.Content = q.Content; - quoteModel.Langue = q.Langue; - quoteModel.Charac = q.Charac; - quoteModel.TitleSrc = q.TitleSrc; - quoteModel.Id = q.Id; - quoteModel.Like = q.Like; - quoteModel.ImgPath = q.ImgPath; - quoteModel.DateSrc = q.DateSrc; - quoteModel.UserProposition = q.UserProposition; - quoteModel.IsValid = q.IsValid; + _quoteModel.Content = Q.Content; + _quoteModel.Langue = Q.Langue; + _quoteModel.Charac = Q.Charac; + _quoteModel.TitleSrc = Q.TitleSrc; + _quoteModel.Id = Q.Id; + _quoteModel.Like = Q.Like; + _quoteModel.ImgPath = Q.ImgPath; + _quoteModel.DateSrc = Q.DateSrc; + _quoteModel.UserProposition = Q.UserProposition; + _quoteModel.IsValid = Q.IsValid; // Fetch additional data related to the quote, such as character and source. - charac = await quoteService.getChar(); - src = await quoteService.getSrc(); + _charac = await quoteService.getChar(); + _src = await quoteService.getSrc(); } /// @@ -64,15 +64,22 @@ namespace WF_WebAdmin.Pages /// protected async Task HandleValidSubmit() { + if (Q == null) + { + LoggerSaveStub.Log(Logger, LogLevel.Error, "Quote is null."); + return; + } + // Update the properties of the selected quote (`q`) with the data from `quoteModel`. - LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the quote {q.Content}"); - q.Content = quoteModel.Content; - q.Langue = quoteModel.Langue; - q.TitleSrc = quoteModel.TitleSrc; - q.Charac = quoteModel.Charac; + LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the quote {Q.Content}"); + + Q.Content = _quoteModel.Content ?? "Content"; + Q.Langue = _quoteModel.Langue ?? "EN"; + Q.TitleSrc = _quoteModel.TitleSrc ?? "Something"; + Q.Charac = _quoteModel.Charac ?? "Someone"; // Call the quote service to update the quote in the data source. - await quoteService.updateQuote(q); + await quoteService.updateQuote(Q); // Navigate to the "modifquote" page after updating the quote. NavigationManager.NavigateTo("modifquote"); @@ -87,13 +94,13 @@ namespace WF_WebAdmin.Pages /// /// The selected language ("fr" or "en") passed to the method. /// The checked value (unused in this method but may be used for other purposes). - private void OnlangChange(string item, object checkedValue) + private void OnlangChange(string item) { // Check if the selected language is either "fr" or "en" if (item == "fr" || item == "en") { // Update the Langue property of the quoteModel with the selected language - quoteModel.Langue = item; + _quoteModel.Langue = item; } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs b/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs index 6a4103f..dd2a8d0 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs @@ -8,15 +8,15 @@ namespace WF_WebAdmin.Service public Task removeQuote(Quote quote); - public Task validQuote(Quote quote); + public Task validQuote(Quote? quote); - public Task updateQuote(Quote quote); + public Task updateQuote(Quote? quote); public Task> getAllQuote(); public Task> getSomeQuote(int nb, int page); - public Task getOnequote(int id); + public Task getOnequote(int id); public Task> reserchQuote(string reserch, List argument); diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs index 1ac999a..7a2352a 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs @@ -21,7 +21,7 @@ namespace WF_WebAdmin.Service /// After successfully inserting the quote, the corresponding is returned to the caller. /// Error handling is in place to catch any issues during the database insertion process, with the exception message logged in case of failure. /// - public async Task AddQuoteAsync(Quote quote) + public async Task AddQuoteAsync(Quote? quote) { QuoteExtension extension = new QuoteExtension(); QuoteDto quoteDTO = extension.QuoteToDTO(quote); @@ -85,7 +85,7 @@ namespace WF_WebAdmin.Service /// it currently only converts the quote to a DTO and does not actually perform any database removal operation. /// You may need to implement additional logic to remove the quote from the database. /// - public Task RemoveQuote(Quote quote) + public Task RemoveQuote(Quote? quote) { QuoteExtension extension = new QuoteExtension(); QuoteDto quoteDTO = extension.QuoteToDTO(quote); @@ -107,7 +107,7 @@ namespace WF_WebAdmin.Service /// If you intend to validate the quote (e.g., updating its status in a database), you will need to implement /// the actual validation logic separately. /// - public Task validQuote(Quote quote) + public Task validQuote(Quote? quote) { QuoteExtension extension = new QuoteExtension(); QuoteDto quoteDto = extension.QuoteToDTO(quote); @@ -129,7 +129,7 @@ namespace WF_WebAdmin.Service /// If you intend to update the quote (e.g., modifying the quote in a database or data source), /// you will need to implement the actual update logic separately. /// - public Task updateQuote(Quote quote) + public Task updateQuote(Quote? quote) { QuoteExtension extension = new QuoteExtension(); QuoteDto quoteDTO = extension.QuoteToDTO(quote); @@ -175,7 +175,7 @@ namespace WF_WebAdmin.Service throw new NotImplementedException(); } - public Task getOnequote(int id) + public Task getOnequote(int id) { throw new NotImplementedException(); } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs index 52747ad..a0f211f 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 Task validQuote(Quote quote) + public Task validQuote(Quote? quote) { throw new NotImplementedException(); } @@ -88,7 +88,7 @@ namespace WF_WebAdmin.Service; /// with the values from the provided `quote` object. After updating the quote, the method saves the updated list back to the JSON file /// using . If the quote with the specified `Id` is not found, no action is taken. /// - public async Task updateQuote(Quote quote) + public async Task updateQuote(Quote? quote) { var data = await getAllQuote(); var q = data.FirstOrDefault(p => p.Id == quote.Id); @@ -166,7 +166,7 @@ namespace WF_WebAdmin.Service; /// This method retrieves all quotes using the method and searches for the quote that matches the provided `id`. /// If a matching quote is found, it returns that quote; otherwise, it returns `null`. /// - public async Task getOnequote(int id) + public async Task getOnequote(int id) { var data = await getAllQuote(); var q = data.FirstOrDefault(p => p.Id == id);