diff --git a/README.md b/README.md index ddcef7e..55dfd0d 100644 --- a/README.md +++ b/README.md @@ -60,15 +60,16 @@ L'application devrait se lancer automatiquement dans votre navigateur par défau # Blazor Apps (30 points) 🟨 En cours / ✅ Fait / ❌ Pas fait

+ ✅ Mise en place d'une page de visualisation des données avec pagination (2 points)
✅ Page d'ajout d'un élement avec validation (2 point)
✅ Page d'édition d'un élement avec validation (2 point)
✅ Supression d'un élement avec une confirmation (2 point)
-🟨 Composant complexe (5 point)
+✅ Composant complexe (5 point)
🟨 Use API (Get / Insert / Update / Delete) (3 point)
✅ Utilisation IOC & DI (4 point)
✅ Localisation & Globalisation (au moins deux langues) (1 point)
-❌ Utilisation de la configuration (1 point)
+❓ Utilisation de la configuration (1 point)
✅ Logs (2 point)
🟨 Propreté du code (Vous pouvez vous servir de sonarqube) (2 point)
✅ IHM (Design global, placement des boutons, ...) (2 point)
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/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; diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/CommentaryChart.razor b/WF-WebAdmin/WF-WebAdmin/Pages/CommentaryChart.razor index e2ea783..11a470a 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/CommentaryChart.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/CommentaryChart.razor @@ -1,17 +1,37 @@ @page "/commentary-chart" -@using MudBlazor - - -

Statistiques des Commentaires - Année @SelectedYear

+

Nombre de commentaires par mois

- - @foreach (var year in AvailableYears) + + +@code { + private int Index = -1; + private List Series = new(); + private string[] XAxisLabels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + + [Inject] private WF_WebAdmin.Service.ICommentaryService CommentaryService { get; set; } = default!; + + protected override async Task OnInitializedAsync() + { + var comments = await CommentaryService.GetCommentsAsync(); + var groupedData = comments.GroupBy(c => c.DateCreation.Month) + .OrderBy(g => g.Key) + .Select(g => new { Month = g.Key - 1, Value = g.Count() }) + .ToList(); + + double[] data = new double[12]; + foreach (var item in groupedData) + { + data[item.Month] = item.Value; + } + + Series = new List + { + new ChartSeries { - @year + Name = "", + Data = data } - - - -
-
+ }; + } +} \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/CommentaryChart.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/CommentaryChart.razor.cs deleted file mode 100644 index b41d4c6..0000000 --- a/WF-WebAdmin/WF-WebAdmin/Pages/CommentaryChart.razor.cs +++ /dev/null @@ -1,72 +0,0 @@ -using Microsoft.AspNetCore.Components; -using MudBlazor; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading.Tasks; -using WF_WebAdmin.Model; -using WF_WebAdmin.Service; - -namespace WF_WebAdmin.Pages -{ - public partial class CommentaryChart : ComponentBase - { - [Inject] public ICommentaryService CommentaryService { get; set; } = default!; - - public List Labels { get; set; } = new(); - public List ChartData { get; set; } = new(); - public List AvailableYears { get; set; } = new(); - public int SelectedYear { get; set; } - - private List AllComments = new(); - - protected override async Task OnInitializedAsync() - { - // Charger tous les commentaires - AllComments = await CommentaryService.GetCommentsAsync(); - - if (!AllComments.Any()) - { - Labels = new List { "Aucun commentaire" }; - ChartData = new List { new double[] { 0 } }; - return; - } - - AvailableYears = AllComments - .Select(c => c.DateCreation.Year) - .Distinct() - .OrderBy(y => y) - .ToList(); - - SelectedYear = AvailableYears.Max(); - - UpdateChartData(SelectedYear); - } - - private void UpdateChartData(int newYear) - { - SelectedYear = newYear; - - var filteredComments = AllComments - .Where(c => c.DateCreation.Year == SelectedYear) - .ToList(); - - if (!filteredComments.Any()) - { - Labels = new List { "Aucun commentaire" }; - ChartData = new List { new double[] { 0 } }; - return; - } - - var grouped = Enumerable.Range(1, 12) - .ToDictionary( - month => new DateTime(SelectedYear, month, 1).ToString("MMMM", CultureInfo.InvariantCulture), - month => filteredComments.Count(c => c.DateCreation.Month == month) - ); - - Labels = grouped.Keys.ToList(); - ChartData = new List { grouped.Values.Select(v => (double)v).ToArray() }; - } - } -} 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); diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor index a9174b8..d4b5b54 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor +++ b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor @@ -2,65 +2,66 @@ @inject UserLogin uLogin -