Code Smells from Pages/Edit
continuous-integration/drone/push Build is passing Details

master
tomivt 2 months ago
parent ccf7e35f39
commit 27016668bd

@ -4,7 +4,7 @@ namespace WF_WebAdmin.Converter
{ {
public class QuoteExtension 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); 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; return quote;

@ -3,29 +3,29 @@
<h3>Editer</h3> <h3>Editer</h3>
<EditForm Model="@quoteModel" OnValidSubmit="@HandleValidSubmit"> <EditForm Model="@_quoteModel" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator /> <DataAnnotationsValidator />
<ValidationSummary /> <ValidationSummary />
<p> <p>
<label for="display-cit"> <label for="display-cit">
Citation: Citation:
<InputText id="display-cit" @bind-Value="quoteModel.Content" /> <InputText id="display-cit" @bind-Value="_quoteModel.Content" />
</label> </label>
</p> </p>
<p> <p>
<label for="lang"> <label for="lang">
Langue: Langue:
<input name="lang" type="radio" @onchange="@(e => OnlangChange("fr", e.Value))" /> fr <input name="lang" type="radio" @onchange="@(e => OnlangChange("fr"))" /> fr
<input name="lang" type="radio" @onchange="@(e => OnlangChange("en", e.Value))" /> en <input name="lang" type="radio" @onchange="@(e => OnlangChange("en"))" /> en
</label> </label>
</p> </p>
<p> <p>
<label for="charac"> <label for="charac">
<InputSelect id="charac" @bind-Value="quoteModel.Charac"> <InputSelect id="charac" @bind-Value="_quoteModel.Charac">
@foreach (Character display in charac) @foreach (Character display in _charac)
{ {
<option value="@display.caracter">@display.caracter (ID: @display.id_caracter)</option> <option value="@display.caracter">@display.caracter (ID: @display.id_caracter)</option>
} }
@ -35,8 +35,8 @@
<p> <p>
<label for="src"> <label for="src">
<InputSelect id="src" @bind-Value="quoteModel.TitleSrc"> <InputSelect id="src" @bind-Value="_quoteModel.TitleSrc">
@foreach (Source display in src) @foreach (Source display in _src)
{ {
<option value="@display.title">@display.title (ID: @display.id_source)</option> <option value="@display.title">@display.title (ID: @display.id_source)</option>
} }

@ -14,18 +14,18 @@ namespace WF_WebAdmin.Pages
public ILogger<Edit>? Logger { get; set; } public ILogger<Edit>? Logger { get; set; }
[Inject] [Inject]
private IQuoteService quoteService { get; set; } private IQuoteService? quoteService { get; set; }
[Inject] [Inject]
public NavigationManager NavigationManager { get; set; } public NavigationManager? NavigationManager { get; set; }
private Quote q{ get; set; } private Quote? Q { get; set; }
private QuoteModel quoteModel = new(); private QuoteModel _quoteModel = new();
private List<Character> charac = new List<Character>(); private List<Character> _charac = new List<Character>();
private List<Source> src = new List<Source>(); private List<Source> _src = new List<Source>();
/// <summary> /// <summary>
@ -37,23 +37,23 @@ namespace WF_WebAdmin.Pages
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
// Fetch the quote data based on the provided ID. // 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. // Populate the quoteModel with the data from the retrieved quote.
quoteModel.Content = q.Content; _quoteModel.Content = Q.Content;
quoteModel.Langue = q.Langue; _quoteModel.Langue = Q.Langue;
quoteModel.Charac = q.Charac; _quoteModel.Charac = Q.Charac;
quoteModel.TitleSrc = q.TitleSrc; _quoteModel.TitleSrc = Q.TitleSrc;
quoteModel.Id = q.Id; _quoteModel.Id = Q.Id;
quoteModel.Like = q.Like; _quoteModel.Like = Q.Like;
quoteModel.ImgPath = q.ImgPath; _quoteModel.ImgPath = Q.ImgPath;
quoteModel.DateSrc = q.DateSrc; _quoteModel.DateSrc = Q.DateSrc;
quoteModel.UserProposition = q.UserProposition; _quoteModel.UserProposition = Q.UserProposition;
quoteModel.IsValid = q.IsValid; _quoteModel.IsValid = Q.IsValid;
// Fetch additional data related to the quote, such as character and source. // Fetch additional data related to the quote, such as character and source.
charac = await quoteService.getChar(); _charac = await quoteService.getChar();
src = await quoteService.getSrc(); _src = await quoteService.getSrc();
} }
/// <summary> /// <summary>
@ -64,15 +64,22 @@ namespace WF_WebAdmin.Pages
/// </summary> /// </summary>
protected async Task HandleValidSubmit() 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`. // Update the properties of the selected quote (`q`) with the data from `quoteModel`.
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the quote {q.Content}"); LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the quote {Q.Content}");
q.Content = quoteModel.Content;
q.Langue = quoteModel.Langue; Q.Content = _quoteModel.Content ?? "Content";
q.TitleSrc = quoteModel.TitleSrc; Q.Langue = _quoteModel.Langue ?? "EN";
q.Charac = quoteModel.Charac; Q.TitleSrc = _quoteModel.TitleSrc ?? "Something";
Q.Charac = _quoteModel.Charac ?? "Someone";
// Call the quote service to update the quote in the data source. // 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. // Navigate to the "modifquote" page after updating the quote.
NavigationManager.NavigateTo("modifquote"); NavigationManager.NavigateTo("modifquote");
@ -87,13 +94,13 @@ namespace WF_WebAdmin.Pages
/// </summary> /// </summary>
/// <param name="item">The selected language ("fr" or "en") passed to the method.</param> /// <param name="item">The selected language ("fr" or "en") passed to the method.</param>
/// <param name="checkedValue">The checked value (unused in this method but may be used for other purposes).</param> /// <param name="checkedValue">The checked value (unused in this method but may be used for other purposes).</param>
private void OnlangChange(string item, object checkedValue) private void OnlangChange(string item)
{ {
// Check if the selected language is either "fr" or "en" // Check if the selected language is either "fr" or "en"
if (item == "fr" || item == "en") if (item == "fr" || item == "en")
{ {
// Update the Langue property of the quoteModel with the selected language // Update the Langue property of the quoteModel with the selected language
quoteModel.Langue = item; _quoteModel.Langue = item;
} }
} }
} }

@ -8,15 +8,15 @@ namespace WF_WebAdmin.Service
public Task removeQuote(Quote quote); 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<List<Quote>> getAllQuote(); public Task<List<Quote>> getAllQuote();
public Task<List<Quote>> getSomeQuote(int nb, int page); public Task<List<Quote>> getSomeQuote(int nb, int page);
public Task<Quote> getOnequote(int id); public Task<Quote?> getOnequote(int id);
public Task<List<Quote>> reserchQuote(string reserch, List<string> argument); public Task<List<Quote>> reserchQuote(string reserch, List<string> argument);

@ -21,7 +21,7 @@ namespace WF_WebAdmin.Service
/// After successfully inserting the quote, the corresponding <see cref="QuoteDto"/> is returned to the caller. /// After successfully inserting the quote, the corresponding <see cref="QuoteDto"/> 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. /// Error handling is in place to catch any issues during the database insertion process, with the exception message logged in case of failure.
/// </remarks> /// </remarks>
public async Task<QuoteDto> AddQuoteAsync(Quote quote) public async Task<QuoteDto> AddQuoteAsync(Quote? quote)
{ {
QuoteExtension extension = new QuoteExtension(); QuoteExtension extension = new QuoteExtension();
QuoteDto quoteDTO = extension.QuoteToDTO(quote); 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. /// 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. /// You may need to implement additional logic to remove the quote from the database.
/// </remarks> /// </remarks>
public Task RemoveQuote(Quote quote) public Task RemoveQuote(Quote? quote)
{ {
QuoteExtension extension = new QuoteExtension(); QuoteExtension extension = new QuoteExtension();
QuoteDto quoteDTO = extension.QuoteToDTO(quote); 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 /// 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. /// the actual validation logic separately.
/// </remarks> /// </remarks>
public Task validQuote(Quote quote) public Task validQuote(Quote? quote)
{ {
QuoteExtension extension = new QuoteExtension(); QuoteExtension extension = new QuoteExtension();
QuoteDto quoteDto = extension.QuoteToDTO(quote); 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), /// 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. /// you will need to implement the actual update logic separately.
/// </remarks> /// </remarks>
public Task updateQuote(Quote quote) public Task updateQuote(Quote? quote)
{ {
QuoteExtension extension = new QuoteExtension(); QuoteExtension extension = new QuoteExtension();
QuoteDto quoteDTO = extension.QuoteToDTO(quote); QuoteDto quoteDTO = extension.QuoteToDTO(quote);
@ -175,7 +175,7 @@ namespace WF_WebAdmin.Service
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<Quote> getOnequote(int id) public Task<Quote?> getOnequote(int id)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

@ -71,7 +71,7 @@ namespace WF_WebAdmin.Service;
} }
public Task validQuote(Quote quote) public Task validQuote(Quote? quote)
{ {
throw new NotImplementedException(); 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 /// with the values from the provided `quote` object. After updating the quote, the method saves the updated list back to the JSON file
/// using <see cref="saveQuoteJson"/>. If the quote with the specified `Id` is not found, no action is taken. /// using <see cref="saveQuoteJson"/>. If the quote with the specified `Id` is not found, no action is taken.
/// </remarks> /// </remarks>
public async Task updateQuote(Quote quote) public async Task updateQuote(Quote? quote)
{ {
var data = await getAllQuote(); var data = await getAllQuote();
var q = data.FirstOrDefault(p => p.Id == quote.Id); var q = data.FirstOrDefault(p => p.Id == quote.Id);
@ -166,7 +166,7 @@ namespace WF_WebAdmin.Service;
/// This method retrieves all quotes using the <see cref="getAllQuote"/> method and searches for the quote that matches the provided `id`. /// This method retrieves all quotes using the <see cref="getAllQuote"/> 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`. /// If a matching quote is found, it returns that quote; otherwise, it returns `null`.
/// </remarks> /// </remarks>
public async Task<Quote> getOnequote(int id) public async Task<Quote?> getOnequote(int id)
{ {
var data = await getAllQuote(); var data = await getAllQuote();
var q = data.FirstOrDefault(p => p.Id == id); var q = data.FirstOrDefault(p => p.Id == id);

Loading…
Cancel
Save