From 6aff34e98317550f293ebdb9825e775f94992a64 Mon Sep 17 00:00:00 2001 From: tomivt Date: Sat, 8 Feb 2025 22:08:42 +0100 Subject: [PATCH 1/2] Code Smells from Model --- WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs | 7 +++---- WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs | 15 --------------- WF-WebAdmin/WF-WebAdmin/Model/User.cs | 4 ++-- WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs | 4 ++-- 4 files changed, 7 insertions(+), 23 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs b/WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs index 9c8b0ae..e4b7df8 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/LoggerSaveStub.cs @@ -12,13 +12,12 @@ namespace WF_WebAdmin.Model { public static partial class LoggerSaveStub { - public static void Log(ILogger logs,LogLevel logLevel,string message) + public static void Log(ILogger logs, LogLevel logLevel, string message, params object[] args) { - ILogsService logsService = new LogsServiceStub(); - logsService.addLogs( new Logs( logLevel , message ) ); + logsService.addLogs(new Logs(logLevel, string.Format(message, args))); - logs.Log(logLevel, message ); + logs.Log(logLevel, message, args); } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs b/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs index af6691a..4b5de4f 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs @@ -12,19 +12,6 @@ namespace WF_WebAdmin.Model public bool IsValid { get; set; } public string UserProposition { get; set; } - public Quiz(int id, string question, string answerA, string answerB, string answerC, string answerD, string cAnswer, bool isValid, string userProposition) - { - Id = id; - Question = question; - AnswerA = answerA; - AnswerB = answerB; - AnswerC = answerC; - AnswerD = answerD; - CAnswer = cAnswer; - IsValid = isValid; - UserProposition = userProposition; - } - public Quiz(int id, string question, string answerA, string answerB, string answerC, string answerD, string cAnswer) { Id = id; @@ -38,7 +25,5 @@ namespace WF_WebAdmin.Model UserProposition = "Admin"; } - public Quiz() {} - } } \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Model/User.cs b/WF-WebAdmin/WF-WebAdmin/Model/User.cs index 5916a3f..1b8d7a5 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/User.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/User.cs @@ -4,8 +4,8 @@ { public int Id { get; set; } public string? Image { get; set; } - public string Name { get; set; } - public string Email { get; set; } + public string? Name { get; set; } + public string? Email { get; set; } public DateTime DateCreation { get; set; } public Boolean IsAdmin { get; set; } diff --git a/WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs b/WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs index 99c0121..74a4820 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs @@ -5,9 +5,9 @@ namespace WF_WebAdmin.Model { public int Id { get; set; } public string? Image { get; set; } - public string Name { get; set;} + public string? Name { get; set;} public Boolean IsAdmin { get; set; } - public string Mdp { get; set; } + public string? Mdp { get; set; } public UserLogin(int id,string image, string name, bool isAdmin, string mdp) { Id = id; From 4be846cd0564ad5f88f5808513e2a6373f68120d Mon Sep 17 00:00:00 2001 From: tomivt Date: Sat, 8 Feb 2025 22:15:30 +0100 Subject: [PATCH 2/2] Code Smells from Converter --- .../WF-WebAdmin/Converter/CommentaryDto.cs | 2 +- .../Converter/CommentaryExtension.cs | 10 +++--- .../WF-WebAdmin/Converter/DailyQuoteDto.cs | 4 +-- .../Converter/DailyQuoteExtension.cs | 4 +-- WF-WebAdmin/WF-WebAdmin/Converter/QuoteDto.cs | 4 +-- .../WF-WebAdmin/Converter/QuoteExtension.cs | 6 ++-- WF-WebAdmin/WF-WebAdmin/Converter/UserDto.cs | 4 +-- .../WF-WebAdmin/Converter/UserExtension.cs | 8 ++--- .../Service/CommentaryServiceStub.cs | 2 +- .../WF-WebAdmin/Service/QuoteServiceLocal.cs | 36 +++++++++---------- 10 files changed, 40 insertions(+), 40 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/CommentaryDto.cs b/WF-WebAdmin/WF-WebAdmin/Converter/CommentaryDto.cs index 1ef4973..9bba523 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/CommentaryDto.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/CommentaryDto.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace WF_WebAdmin.Converter { - public class CommentaryDTO + public class CommentaryDto { [JsonPropertyName("id_comment")] public int Id { get; set; } diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/CommentaryExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/CommentaryExtension.cs index 3e0dfb2..10ab464 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/CommentaryExtension.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/CommentaryExtension.cs @@ -1,12 +1,12 @@ using System; 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 Commentary ToModel(this CommentaryDTO dto) + public static Commentary ToModel(this CommentaryDto dto) { 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, IdUser = model.IdUser, diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteDto.cs b/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteDto.cs index 0fb7042..5def23c 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteDto.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteDto.cs @@ -1,10 +1,10 @@ namespace WF_WebAdmin.Converter { - public class DailyQuoteDTO + public class DailyQuoteDto { private int Id { get; set; } - public DailyQuoteDTO(int id) + public DailyQuoteDto(int id) { this.Id = id; } diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteExtension.cs index 63ec57e..85f24d5 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteExtension.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteExtension.cs @@ -4,9 +4,9 @@ namespace WF_WebAdmin.Converter { 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; } } diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDto.cs b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDto.cs index fc3e969..6e97418 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDto.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDto.cs @@ -3,7 +3,7 @@ using System; namespace WF_WebAdmin.Converter { - public class QuoteDTO + public class QuoteDto { public int Id { get; set; } public string Content { get; set; } @@ -21,7 +21,7 @@ namespace WF_WebAdmin.Converter public int? IdImg { 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.Content = content; diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs index a7bd57f..35239e4 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs @@ -4,13 +4,13 @@ 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); + 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; } - 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); return quote; diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/UserDto.cs b/WF-WebAdmin/WF-WebAdmin/Converter/UserDto.cs index a7eb8b8..258a3ac 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/UserDto.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/UserDto.cs @@ -2,7 +2,7 @@ namespace WF_WebAdmin.Converter { - public class UserDTO + public class UserDto { public string Image { get; set; } public string Name { get; set; } @@ -12,7 +12,7 @@ namespace WF_WebAdmin.Converter public Boolean IsAdmin { get; set; } public List? 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; diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/UserExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/UserExtension.cs index ebcf0e4..cbdd18b 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/UserExtension.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/UserExtension.cs @@ -4,15 +4,15 @@ namespace WF_WebAdmin.Converter { 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; } - 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; } } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/CommentaryServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/CommentaryServiceStub.cs index d1a57ae..c0c8244 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/CommentaryServiceStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/CommentaryServiceStub.cs @@ -21,7 +21,7 @@ namespace WF_WebAdmin.Service } var json = await File.ReadAllTextAsync(_jsonFilePath); - var dtoList = JsonSerializer.Deserialize>(json) ?? new List(); + var dtoList = JsonSerializer.Deserialize>(json) ?? new List(); var comments = dtoList.ConvertAll(dto => dto.ToModel()); diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs index 0afa4ab..1b71866 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs @@ -11,20 +11,20 @@ namespace WF_WebAdmin.Service /// - /// Asynchronously adds a new quote to the database and returns the corresponding . + /// Asynchronously adds a new quote to the database and returns the corresponding . /// /// The object to be added to the database. - /// A task representing the asynchronous operation, with a result containing the added quote's data. + /// A task representing the asynchronous operation, with a result containing the added quote's data. /// - /// This method converts the provided object into a using . + /// This method converts the provided object into a using . /// 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 is returned to the caller. + /// 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); + QuoteDto quoteDTO = extension.QuoteToDTO(quote); // Utilisation de NpgsqlConnection pour PostgreSQL using (var connection = new NpgsqlConnection(_connectionString)) @@ -75,12 +75,12 @@ namespace WF_WebAdmin.Service /// - /// Asynchronously handles the removal of a quote and returns the corresponding . + /// Asynchronously handles the removal of a quote and returns the corresponding . /// /// The object to be removed. - /// A task representing the asynchronous operation, with a result corresponding to the removed quote. + /// A task representing the asynchronous operation, with a result corresponding to the removed quote. /// - /// This method takes a object, converts it into a using the + /// This method takes a object, converts it into a using the /// , 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. /// 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) { 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 Task.FromResult(quoteDTO); @@ -96,12 +96,12 @@ namespace WF_WebAdmin.Service /// - /// Asynchronously validates a quote and returns the corresponding . + /// Asynchronously validates a quote and returns the corresponding . /// /// The object to be validated. - /// A task representing the asynchronous operation, with a result corresponding to the validated quote. + /// A task representing the asynchronous operation, with a result corresponding to the validated quote. /// - /// This method takes a object, converts it into a using the + /// This method takes a object, converts it into a using the /// , 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. /// 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) { 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); @@ -118,12 +118,12 @@ namespace WF_WebAdmin.Service /// - /// Asynchronously updates a quote and returns the corresponding . + /// Asynchronously updates a quote and returns the corresponding . /// /// The object to be updated. - /// A task representing the asynchronous operation, with a result corresponding to the updated quote. + /// A task representing the asynchronous operation, with a result corresponding to the updated quote. /// - /// This method takes a object, converts it into a using the + /// This method takes a object, converts it into a using the /// , 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. /// 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) { 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 Task.FromResult(quoteDTO);