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 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;

@ -3,29 +3,29 @@
<h3>Editer</h3>
<EditForm Model="@quoteModel" OnValidSubmit="@HandleValidSubmit">
<EditForm Model="@_quoteModel" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label for="display-cit">
Citation:
<InputText id="display-cit" @bind-Value="quoteModel.Content" />
<InputText id="display-cit" @bind-Value="_quoteModel.Content" />
</label>
</p>
<p>
<label for="lang">
Langue:
<input name="lang" type="radio" @onchange="@(e => OnlangChange("fr", e.Value))" /> fr
<input name="lang" type="radio" @onchange="@(e => OnlangChange("en", e.Value))" /> en
<input name="lang" type="radio" @onchange="@(e => OnlangChange("fr"))" /> fr
<input name="lang" type="radio" @onchange="@(e => OnlangChange("en"))" /> en
</label>
</p>
<p>
<label for="charac">
<InputSelect id="charac" @bind-Value="quoteModel.Charac">
@foreach (Character display in charac)
<InputSelect id="charac" @bind-Value="_quoteModel.Charac">
@foreach (Character display in _charac)
{
<option value="@display.caracter">@display.caracter (ID: @display.id_caracter)</option>
}
@ -35,8 +35,8 @@
<p>
<label for="src">
<InputSelect id="src" @bind-Value="quoteModel.TitleSrc">
@foreach (Source display in src)
<InputSelect id="src" @bind-Value="_quoteModel.TitleSrc">
@foreach (Source display in _src)
{
<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; }
[Inject]
private IQuoteService quoteService { get; set; }
private IQuoteService? quoteService { get; set; }
[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>
@ -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();
}
/// <summary>
@ -64,15 +64,22 @@ namespace WF_WebAdmin.Pages
/// </summary>
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
/// </summary>
/// <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>
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;
}
}
}

@ -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<List<Quote>> getAllQuote();
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);

@ -21,7 +21,7 @@ namespace WF_WebAdmin.Service
/// 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.
/// </remarks>
public async Task<QuoteDto> AddQuoteAsync(Quote quote)
public async Task<QuoteDto> 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.
/// </remarks>
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.
/// </remarks>
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.
/// </remarks>
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<Quote> getOnequote(int id)
public Task<Quote?> getOnequote(int id)
{
throw new NotImplementedException();
}

@ -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 <see cref="saveQuoteJson"/>. If the quote with the specified `Id` is not found, no action is taken.
/// </remarks>
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 <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`.
/// </remarks>
public async Task<Quote> getOnequote(int id)
public async Task<Quote?> getOnequote(int id)
{
var data = await getAllQuote();
var q = data.FirstOrDefault(p => p.Id == id);

Loading…
Cancel
Save