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

master
tomivt 2 months ago
parent 6aff34e983
commit 4be846cd05

@ -3,7 +3,7 @@ using System.Text.Json.Serialization;
namespace WF_WebAdmin.Converter namespace WF_WebAdmin.Converter
{ {
public class CommentaryDTO public class CommentaryDto
{ {
[JsonPropertyName("id_comment")] [JsonPropertyName("id_comment")]
public int Id { get; set; } public int Id { get; set; }

@ -1,12 +1,12 @@
using System; using System;
using System.Globalization; using System.Globalization;
using WF_WebAdmin.Converter; using WF_WebAdmin.Model;
namespace WF_WebAdmin.Model namespace WF_WebAdmin.Converter
{ {
public static class CommentaryExtensions public static class CommentaryExtensions
{ {
public static Commentary ToModel(this CommentaryDTO dto) public static Commentary ToModel(this CommentaryDto dto)
{ {
DateTime parsedDate = DateTime.MinValue; DateTime parsedDate = DateTime.MinValue;
@ -32,9 +32,9 @@ namespace WF_WebAdmin.Model
}; };
} }
public static CommentaryDTO ToDTO(this Commentary model) public static CommentaryDto ToDTO(this Commentary model)
{ {
return new CommentaryDTO return new CommentaryDto
{ {
Id = model.Id, Id = model.Id,
IdUser = model.IdUser, IdUser = model.IdUser,

@ -1,10 +1,10 @@
namespace WF_WebAdmin.Converter namespace WF_WebAdmin.Converter
{ {
public class DailyQuoteDTO public class DailyQuoteDto
{ {
private int Id { get; set; } private int Id { get; set; }
public DailyQuoteDTO(int id) public DailyQuoteDto(int id)
{ {
this.Id = id; this.Id = id;
} }

@ -4,9 +4,9 @@ namespace WF_WebAdmin.Converter
{ {
public class DailyQuoteExtension public class DailyQuoteExtension
{ {
public DailyQuoteDTO DailyQuoteToDTO(DailyQuote dq) public DailyQuoteDto DailyQuoteToDto(DailyQuote dq)
{ {
DailyQuoteDTO dailyQuote = new DailyQuoteDTO(dq.Id); DailyQuoteDto dailyQuote = new DailyQuoteDto(dq.Id);
return dailyQuote; return dailyQuote;
} }
} }

@ -3,7 +3,7 @@ using System;
namespace WF_WebAdmin.Converter namespace WF_WebAdmin.Converter
{ {
public class QuoteDTO public class QuoteDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string Content { get; set; } public string Content { get; set; }
@ -21,7 +21,7 @@ namespace WF_WebAdmin.Converter
public int? IdImg { get; set; } public int? IdImg { get; set; }
public string ImgPath { get; set; } public string ImgPath { get; set; }
public QuoteDTO(int id_quote,string content,int likes,string langue,bool isValide,string? reason,int? id_caracter,string name_charac,int? id_source,string title,DateTime date,int? id_user_verif,string name_user ,int? id_img,string img_path) public QuoteDto(int id_quote,string content,int likes,string langue,bool isValide,string? reason,int? id_caracter,string name_charac,int? id_source,string title,DateTime date,int? id_user_verif,string name_user ,int? id_img,string img_path)
{ {
this.Id = id_quote; this.Id = id_quote;
this.Content = content; this.Content = content;

@ -4,13 +4,13 @@ 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;
} }
public Quote DTOToQuote(QuoteDTO q) public Quote DTOToQuote(QuoteDto q)
{ {
Quote quote = new Quote(q.Id, q.Content,q.NameCharac,q.ImgPath,q.TitleSrc,q.DateSrc,q.Likes,q.Langue,q.NameUser,q.IsValide); Quote quote = new Quote(q.Id, q.Content,q.NameCharac,q.ImgPath,q.TitleSrc,q.DateSrc,q.Likes,q.Langue,q.NameUser,q.IsValide);
return quote; return quote;

@ -2,7 +2,7 @@
namespace WF_WebAdmin.Converter namespace WF_WebAdmin.Converter
{ {
public class UserDTO public class UserDto
{ {
public string Image { get; set; } public string Image { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -12,7 +12,7 @@ namespace WF_WebAdmin.Converter
public Boolean IsAdmin { get; set; } public Boolean IsAdmin { get; set; }
public List<Commentary>? Comments { get; set; } public List<Commentary>? Comments { get; set; }
public UserDTO(string image, string name, string email, DateTime dateCreation) public UserDto(string image, string name, string email, DateTime dateCreation)
{ {
this.Image = image; this.Image = image;

@ -4,15 +4,15 @@ namespace WF_WebAdmin.Converter
{ {
public class UserExtension public class UserExtension
{ {
public User UserToDTO(UserDTO u) public User UserToDto(UserDto u)
{ {
User user = new User(u.Image, u.Name, u.Email, u.DateCreation,u.IsAdmin); var user = new User(u.Image, u.Name, u.Email, u.DateCreation,u.IsAdmin);
return user; return user;
} }
public UserDTO DTOToUser(User u) public UserDto DtoToUser(User u)
{ {
UserDTO user = new UserDTO(u.Image, u.Name, u.Email, u.DateCreation); var user = new UserDto(u.Image ?? "default.png", u.Name ?? "Bob", u.Email ?? "bob@mail.com", u.DateCreation);
return user; return user;
} }
} }

@ -21,7 +21,7 @@ namespace WF_WebAdmin.Service
} }
var json = await File.ReadAllTextAsync(_jsonFilePath); var json = await File.ReadAllTextAsync(_jsonFilePath);
var dtoList = JsonSerializer.Deserialize<List<CommentaryDTO>>(json) ?? new List<CommentaryDTO>(); var dtoList = JsonSerializer.Deserialize<List<CommentaryDto>>(json) ?? new List<CommentaryDto>();
var comments = dtoList.ConvertAll(dto => dto.ToModel()); var comments = dtoList.ConvertAll(dto => dto.ToModel());

@ -11,20 +11,20 @@ namespace WF_WebAdmin.Service
/// <summary> /// <summary>
/// Asynchronously adds a new quote to the database and returns the corresponding <see cref="QuoteDTO"/>. /// Asynchronously adds a new quote to the database and returns the corresponding <see cref="QuoteDto"/>.
/// </summary> /// </summary>
/// <param name="quote">The <see cref="Quote"/> object to be added to the database.</param> /// <param name="quote">The <see cref="Quote"/> object to be added to the database.</param>
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result containing the added quote's data.</returns> /// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDto"/> result containing the added quote's data.</returns>
/// <remarks> /// <remarks>
/// This method converts the provided <see cref="Quote"/> object into a <see cref="QuoteDTO"/> using <see cref="QuoteExtension"/>. /// This method converts the provided <see cref="Quote"/> object into a <see cref="QuoteDto"/> using <see cref="QuoteExtension"/>.
/// It then inserts the quote into the PostgreSQL database using a parameterized SQL query with the help of Npgsql. /// It then inserts the quote into the PostgreSQL database using a parameterized SQL query with the help of Npgsql.
/// 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);
// Utilisation de NpgsqlConnection pour PostgreSQL // Utilisation de NpgsqlConnection pour PostgreSQL
using (var connection = new NpgsqlConnection(_connectionString)) using (var connection = new NpgsqlConnection(_connectionString))
@ -75,12 +75,12 @@ namespace WF_WebAdmin.Service
/// <summary> /// <summary>
/// Asynchronously handles the removal of a quote and returns the corresponding <see cref="QuoteDTO"/>. /// Asynchronously handles the removal of a quote and returns the corresponding <see cref="QuoteDto"/>.
/// </summary> /// </summary>
/// <param name="quote">The <see cref="Quote"/> object to be removed.</param> /// <param name="quote">The <see cref="Quote"/> object to be removed.</param>
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the removed quote.</returns> /// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDto"/> result corresponding to the removed quote.</returns>
/// <remarks> /// <remarks>
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the /// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDto"/> using the
/// <see cref="QuoteExtension"/>, and then returns the DTO. Note that while this function is named `RemoveQuote`, /// <see cref="QuoteExtension"/>, and then returns the DTO. Note that while this function is named `RemoveQuote`,
/// 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.
@ -88,7 +88,7 @@ namespace WF_WebAdmin.Service
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);
// Return the DTO as the result of this asynchronous operation (though no removal logic is currently implemented) // Return the DTO as the result of this asynchronous operation (though no removal logic is currently implemented)
return Task.FromResult(quoteDTO); return Task.FromResult(quoteDTO);
@ -96,12 +96,12 @@ namespace WF_WebAdmin.Service
/// <summary> /// <summary>
/// Asynchronously validates a quote and returns the corresponding <see cref="QuoteDTO"/>. /// Asynchronously validates a quote and returns the corresponding <see cref="QuoteDto"/>.
/// </summary> /// </summary>
/// <param name="quote">The <see cref="Quote"/> object to be validated.</param> /// <param name="quote">The <see cref="Quote"/> object to be validated.</param>
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the validated quote.</returns> /// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDto"/> result corresponding to the validated quote.</returns>
/// <remarks> /// <remarks>
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the /// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDto"/> using the
/// <see cref="QuoteExtension"/>, and returns the DTO. The method is named `validQuote`, but currently, it only /// <see cref="QuoteExtension"/>, and returns the DTO. The method is named `validQuote`, but currently, it only
/// converts the quote into a DTO and does not perform any actual validation logic. /// converts the quote into a DTO and does not perform any actual validation logic.
/// 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
@ -110,7 +110,7 @@ namespace WF_WebAdmin.Service
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);
// Return the DTO as the result of this asynchronous operation (though no validation logic is currently implemented) // 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);
@ -118,12 +118,12 @@ namespace WF_WebAdmin.Service
/// <summary> /// <summary>
/// Asynchronously updates a quote and returns the corresponding <see cref="QuoteDTO"/>. /// Asynchronously updates a quote and returns the corresponding <see cref="QuoteDto"/>.
/// </summary> /// </summary>
/// <param name="quote">The <see cref="Quote"/> object to be updated.</param> /// <param name="quote">The <see cref="Quote"/> object to be updated.</param>
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the updated quote.</returns> /// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDto"/> result corresponding to the updated quote.</returns>
/// <remarks> /// <remarks>
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the /// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDto"/> using the
/// <see cref="QuoteExtension"/>, and returns the DTO. The method is named `updateQuote`, but currently, it only /// <see cref="QuoteExtension"/>, and returns the DTO. The method is named `updateQuote`, but currently, it only
/// converts the quote into a DTO and does not perform any actual update logic. /// converts the quote into a DTO and does not perform any actual update logic.
/// 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),
@ -132,7 +132,7 @@ namespace WF_WebAdmin.Service
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);
// Return the DTO as the result of this asynchronous operation (though no update logic is currently implemented) // Return the DTO as the result of this asynchronous operation (though no update logic is currently implemented)
return Task.FromResult(quoteDTO); return Task.FromResult(quoteDTO);

Loading…
Cancel
Save