From 4b4b0495fa1015ff278fb77781e955d2631cd5e1 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 18 Mar 2025 14:39:31 +0100 Subject: [PATCH] ajout methodes extentions ToDto() --- WF_EF_Api/DTO/ResultsDTO.cs | 16 --- WF_EF_Api/DTO/SourceDTO.cs | 2 +- WF_EF_Api/DTO/UserDTO.cs | 2 +- WF_EF_Api/Dto2Entities/Dto2Entities.csproj | 14 ++ WF_EF_Api/Dto2Entities/Extention.cs | 149 +++++++++++++++++++++ WF_EF_Api/Entity/LangEnum.cs | 3 +- WF_EF_Api/Entity/Quote.cs | 6 + WF_EF_Api/Entity/RecordQuiz.cs | 17 --- WF_EF_Api/StubApi/UserService.cs | 42 +++--- WF_EF_Api/WF_EF_Api.sln | 20 +-- 10 files changed, 201 insertions(+), 70 deletions(-) delete mode 100644 WF_EF_Api/DTO/ResultsDTO.cs create mode 100644 WF_EF_Api/Dto2Entities/Dto2Entities.csproj create mode 100644 WF_EF_Api/Dto2Entities/Extention.cs delete mode 100644 WF_EF_Api/Entity/RecordQuiz.cs diff --git a/WF_EF_Api/DTO/ResultsDTO.cs b/WF_EF_Api/DTO/ResultsDTO.cs deleted file mode 100644 index de28b59..0000000 --- a/WF_EF_Api/DTO/ResultsDTO.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DTO -{ - public class ResultsDTO - { - public int IdQuiz { get; set; } - public int IdUser { get; set; } - public int Time { get; set; } - public int NbPoint { get; set; } - } -} diff --git a/WF_EF_Api/DTO/SourceDTO.cs b/WF_EF_Api/DTO/SourceDTO.cs index 9db4871..fbb40b7 100644 --- a/WF_EF_Api/DTO/SourceDTO.cs +++ b/WF_EF_Api/DTO/SourceDTO.cs @@ -10,7 +10,7 @@ namespace DTO { public int Id { get; set; } public string Title { get; set; } - public DateTime Date { get; set; } + public int Date { get; set; } public TypeSrcEnumDTO Type { get; set; } } } diff --git a/WF_EF_Api/DTO/UserDTO.cs b/WF_EF_Api/DTO/UserDTO.cs index 672cde3..a01494b 100644 --- a/WF_EF_Api/DTO/UserDTO.cs +++ b/WF_EF_Api/DTO/UserDTO.cs @@ -6,7 +6,7 @@ public string Pseudo { get; set; } public string Password { get; set; } public string Email { get; set; } - public string Years { get; set; } + public DateTime date { get; set; } public string ImageProfil { get; set; } } } diff --git a/WF_EF_Api/Dto2Entities/Dto2Entities.csproj b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj new file mode 100644 index 0000000..beed701 --- /dev/null +++ b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs new file mode 100644 index 0000000..62ed743 --- /dev/null +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Entity; +using DTO; +using System.Reflection.Metadata; + +namespace Dto2Entities +{ + public static class Extention + { + // --------------------------- ToDto --------------------------- \\ + + public static CharacterDTO ToDto(this Character item) + { + CharacterDTO character = new CharacterDTO(); + character.Id = item.Id; + character.Name = item.Name; + character.imagePath = item.Images.ImgPath; + return character; + } + + public static CommentaryDTO ToDto(this Commentary item) + { + CommentaryDTO commentary = new CommentaryDTO(); + commentary.Id = item.Id; + commentary.Date = item.DateCommentary; + commentary.Comment = item.Comment; + commentary.User = item.Users.UserName; + commentary.ImagePath = item.Users.Images.ImgPath; + return commentary; + } + + // Surement a refaire car Faoirite Entity modifier sur branche EF + public static FavoriteDTO ToDto(this Favorite item) + { + FavoriteDTO favorite = new FavoriteDTO(); + favorite.IdUser = item.IdUsers; + favorite.IdQuote = item.IdQuote; + return favorite; + } + + public static ImageDTO ToDto(this Images item) + { + ImageDTO image = new ImageDTO(); + image.IdImage = item.Id; + image.ImagePath = item.ImgPath; + return image; + } + + public static QuestionDTO ToDto(this Question item) + { + QuestionDTO question = new QuestionDTO(); + question.Id = item.Id; + question.Question = item.Text; + question.AnswerA = item.AnswerA; + question.AnswerB = item.AnswerB; + question.AnswerC = item.AnswerC; + question.AnswerD = item.AnswerD; + question.CorrectAnswer = item.CorrectAnswer; + return question; + } + + public static QuizDTO ToDto(this Quiz item) + { + QuizDTO quiz = new QuizDTO(); + quiz.Id = item.Id; + quiz.NbQuestion = item.NbQuestion; + quiz.Title = item.Title; + quiz.ImagePath = item.Images.ImgPath; + return quiz; + } + + // Surement a refaire car QuizQuestion Entity modifier sur branche EF + public static QuizQuestionDTO ToDto(this QuizQuestion item) + { + QuizQuestionDTO quizQuestion = new QuizQuestionDTO(); + quizQuestion.IdQuiz = item.IdQuiz; + quizQuestion.IdQuestion = item.IdQuestion; + return quizQuestion; + } + + public static QuoteDTO ToDto(this Quote item) + { + QuoteDTO quote = new QuoteDTO(); + quote.Id = item.Id; + quote.Content = item.Content; + quote.DateSource = item.Source.Year; + quote.Character = item.Character.Name; + quote.TitleSource = item.Source.Title; + quote.Langage = item.Langage.ToDto(); + quote.ImagePath = item.Character.Images.ImgPath; + quote.Like = item.Likes; + quote.Type = item.Source.TypeSrc.ToDto(); + return quote; + } + + public static SourceDTO ToDto(this Source item) + { + SourceDTO source = new SourceDTO(); + source.Id = item.Id; + source.Date = item.Year; + source.Title = item.Title; + source.Type = item.TypeSrc.ToDto(); + return source; + } + + public static UserDTO ToDto(this Users item) + { + UserDTO user = new UserDTO(); + user.Id = item.Id; + user.Pseudo = item.UserName; + user.Password = item.Password; + user.Email = item.Email; + user.date = item.Created; + user.ImageProfil = item.Images.ImgPath; + return user; + } + + public static TypeLangageDTO ToDto(this LangEnum item) + { + switch (item) + { + case LangEnum.vf: return TypeLangageDTO.vf; + case LangEnum.vo: return TypeLangageDTO.vo; + case LangEnum.ve: return TypeLangageDTO.ve; + default: return TypeLangageDTO.vo; + } + } + + public static TypeSrcEnumDTO ToDto(this TypeSrcEnum item) + { + switch (item) + { + case TypeSrcEnum.movie: return TypeSrcEnumDTO.movie; + case TypeSrcEnum.book: return TypeSrcEnumDTO.book; + case TypeSrcEnum.series: return TypeSrcEnumDTO.serie; + case TypeSrcEnum.videogame: return TypeSrcEnumDTO.videogame; + default: return TypeSrcEnumDTO.movie; + } + } + + // --------------------------- ToEntity --------------------------- \\ + + + } +} diff --git a/WF_EF_Api/Entity/LangEnum.cs b/WF_EF_Api/Entity/LangEnum.cs index 3f8f2a1..dd70bb1 100644 --- a/WF_EF_Api/Entity/LangEnum.cs +++ b/WF_EF_Api/Entity/LangEnum.cs @@ -9,6 +9,7 @@ namespace Entity public enum LangEnum { vo, - vf + vf, + ve } } diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs index adc1dd8..5cd144a 100644 --- a/WF_EF_Api/Entity/Quote.cs +++ b/WF_EF_Api/Entity/Quote.cs @@ -39,6 +39,12 @@ namespace Entity [ForeignKey(nameof(Users))] public int IdUsersPropose { get; set; } + public Users? User { get; set; } = null!; + + public Source Source { get; set; } = null!; + + public Character Character { get; set; } = null!; + public ICollection DailyQuotes { get; set; } = new List(); public ICollection commentaries { get; set; } = new List(); diff --git a/WF_EF_Api/Entity/RecordQuiz.cs b/WF_EF_Api/Entity/RecordQuiz.cs deleted file mode 100644 index 4a6a689..0000000 --- a/WF_EF_Api/Entity/RecordQuiz.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Entity -{ - // Peut etre enlever car inutiliser - public class RecordQuiz - { - public int IdUsers { get; set; } - public int IdQuiz { get; set; } - public int NbPoint { get; set; } - public int TimeQuiz { get; set; } - } -} diff --git a/WF_EF_Api/StubApi/UserService.cs b/WF_EF_Api/StubApi/UserService.cs index 7fd167a..4ce870b 100644 --- a/WF_EF_Api/StubApi/UserService.cs +++ b/WF_EF_Api/StubApi/UserService.cs @@ -10,26 +10,26 @@ namespace StubApi { _users = new List { - new UserDTO { Id = 1, Pseudo = "dev", Password = "1234", Email = "testeur@example.com", Years = "2023", ImageProfil = "https://image_profil_1" }, - new UserDTO { Id = 2, Pseudo = "admin", Password = "admin123", Email = "admin@example.com", Years = "2024", ImageProfil = "https://image_profil_2" }, - new UserDTO { Id = 3, Pseudo = "user123", Password = "password123", Email = "user123@example.com", Years = "2022", ImageProfil = "https://image_profil_3" }, - new UserDTO { Id = 4, Pseudo = "testuser", Password = "testpass", Email = "testuser@example.com", Years = "2025", ImageProfil = "https://image_profil_4" }, - new UserDTO { Id = 5, Pseudo = "johnDoe", Password = "john123", Email = "johndoe@example.com", Years = "2021", ImageProfil = "https://image_profil_5" }, - new UserDTO { Id = 6, Pseudo = "janedoe", Password = "jane123", Email = "janedoe@example.com", Years = "2023", ImageProfil = "https://image_profil_6" }, - new UserDTO { Id = 7, Pseudo = "mark_smith", Password = "mark1234", Email = "marks@example.com", Years = "2022", ImageProfil = "https://image_profil_7" }, - new UserDTO { Id = 8, Pseudo = "alice", Password = "alicepass", Email = "alice@example.com", Years = "2024", ImageProfil = "https://image_profil_8" }, - new UserDTO { Id = 9, Pseudo = "bob_lee", Password = "bob123", Email = "bob@example.com", Years = "2021", ImageProfil = "https://image_profil_9" }, - new UserDTO { Id = 10, Pseudo = "lucas", Password = "lucaspass", Email = "lucas@example.com", Years = "2023", ImageProfil = "https://image_profil_10" }, - new UserDTO { Id = 11, Pseudo = "emily", Password = "emily2024", Email = "emily@example.com", Years = "2022", ImageProfil = "https://image_profil_11" }, - new UserDTO { Id = 12, Pseudo = "chris", Password = "chris1234", Email = "chris@example.com", Years = "2024", ImageProfil = "https://image_profil_12" }, - new UserDTO { Id = 13, Pseudo = "susan", Password = "susan123", Email = "susan@example.com", Years = "2023", ImageProfil = "https://image_profil_13" }, - new UserDTO { Id = 14, Pseudo = "michael", Password = "michael2025", Email = "michael@example.com", Years = "2022", ImageProfil = "https://image_profil_14" }, - new UserDTO { Id = 15, Pseudo = "olivia", Password = "olivia2024", Email = "olivia@example.com", Years = "2024", ImageProfil = "https://image_profil_15" }, - new UserDTO { Id = 16, Pseudo = "david", Password = "david123", Email = "david@example.com", Years = "2021", ImageProfil = "https://image_profil_16" }, - new UserDTO { Id = 17, Pseudo = "laura", Password = "laura456", Email = "laura@example.com", Years = "2023", ImageProfil = "https://image_profil_17" }, - new UserDTO { Id = 18, Pseudo = "steve", Password = "steve789", Email = "steve@example.com", Years = "2022", ImageProfil = "https://image_profil_18" }, - new UserDTO { Id = 19, Pseudo = "tina", Password = "tina321", Email = "tina@example.com", Years = "2024", ImageProfil = "https://image_profil_19" }, - new UserDTO { Id = 20, Pseudo = "peter", Password = "peter123", Email = "peter@example.com", Years = "2025", ImageProfil = "https://image_profil_20" } + new UserDTO { Id = 1, Pseudo = "dev", Password = "1234", Email = "testeur@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_1" }, + new UserDTO { Id = 2, Pseudo = "admin", Password = "admin123", Email = "admin@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_2" }, + new UserDTO { Id = 3, Pseudo = "user123", Password = "password123", Email = "user123@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_3" }, + new UserDTO { Id = 4, Pseudo = "testuser", Password = "testpass", Email = "testuser@example.com", date = new DateTime(2024,1,1), ImageProfil = "https://image_profil_4" }, + new UserDTO { Id = 5, Pseudo = "johnDoe", Password = "john123", Email = "johndoe@example.com", date = new DateTime(2021,1,1), ImageProfil = "https://image_profil_5" }, + new UserDTO { Id = 6, Pseudo = "janedoe", Password = "jane123", Email = "janedoe@example.com", date = new DateTime(2023,1,1), ImageProfil = "https://image_profil_6" }, + new UserDTO { Id = 7, Pseudo = "mark_smith", Password = "mark1234", Email = "marks@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_7" }, + new UserDTO { Id = 8, Pseudo = "alice", Password = "alicepass", Email = "alice@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_8" }, + new UserDTO { Id = 9, Pseudo = "bob_lee", Password = "bob123", Email = "bob@example.com", date = new DateTime(2021,1,1), ImageProfil = "https://image_profil_9" }, + new UserDTO { Id = 10, Pseudo = "lucas", Password = "lucaspass", Email = "lucas@example.com", date = new DateTime(2023,1,1), ImageProfil = "https://image_profil_10" }, + new UserDTO { Id = 11, Pseudo = "emily", Password = "emily2024", Email = "emily@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_11" }, + new UserDTO { Id = 12, Pseudo = "chris", Password = "chris1234", Email = "chris@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_12" }, + new UserDTO { Id = 13, Pseudo = "susan", Password = "susan123", Email = "susan@example.com", date = new DateTime(2023,1,1), ImageProfil = "https://image_profil_13" }, + new UserDTO { Id = 14, Pseudo = "michael", Password = "michael2025", Email = "michael@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_14" }, + new UserDTO { Id = 15, Pseudo = "olivia", Password = "olivia2024", Email = "olivia@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_15" }, + new UserDTO { Id = 16, Pseudo = "david", Password = "david123", Email = "david@example.com", date = new DateTime(2021,1,1), ImageProfil = "https://image_profil_16" }, + new UserDTO { Id = 17, Pseudo = "laura", Password = "laura456", Email = "laura@example.com", date = new DateTime(2023,1,1), ImageProfil = "https://image_profil_17" }, + new UserDTO { Id = 18, Pseudo = "steve", Password = "steve789", Email = "steve@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_18" }, + new UserDTO { Id = 19, Pseudo = "tina", Password = "tina321", Email = "tina@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_19" }, + new UserDTO { Id = 20, Pseudo = "peter", Password = "peter123", Email = "peter@example.com", date = new DateTime(2024,1,1), ImageProfil = "https://image_profil_20" } }; } @@ -111,7 +111,7 @@ namespace StubApi existingUser.Pseudo = user.Pseudo; existingUser.Password = user.Password; existingUser.Email = user.Email; - existingUser.Years = user.Years; + existingUser.date = user.date; existingUser.ImageProfil = user.ImageProfil; return existingUser; } diff --git a/WF_EF_Api/WF_EF_Api.sln b/WF_EF_Api/WF_EF_Api.sln index 3942dd1..2fc3a9e 100644 --- a/WF_EF_Api/WF_EF_Api.sln +++ b/WF_EF_Api/WF_EF_Api.sln @@ -15,17 +15,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubbedContextLib", "Stubbe EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestModel2Entities", "TestModel2Entities\TestModel2Entities.csproj", "{2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model2Entities", "Model2entities\Model2Entities.csproj", "{4A1CBA3D-C798-4E19-865F-39F919F1205A}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnitTest", "XUnitTest\XUnitTest.csproj", "{48002CA2-7CFF-4077-90CF-392476320CE3}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WfApi", "WfApi\WfApi.csproj", "{D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{708875DC-7ED1-4FD1-9321-3E00B2E7709B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubApi", "StubApi\StubApi.csproj", "{4C5F324C-28C3-4153-B402-A07B099C24C6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubApi", "StubApi\StubApi.csproj", "{4C5F324C-28C3-4153-B402-A07B099C24C6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{99F43B70-4143-4807-9EE7-B8A799B1E702}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{99F43B70-4143-4807-9EE7-B8A799B1E702}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dto2Entities", "Dto2Entities\Dto2Entities.csproj", "{08194729-E222-4C9A-B860-D944225B8895}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -57,10 +55,6 @@ Global {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.Build.0 = Release|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.Build.0 = Release|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Debug|Any CPU.Build.0 = Debug|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -69,10 +63,6 @@ Global {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.Build.0 = Release|Any CPU - {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.Build.0 = Release|Any CPU {4C5F324C-28C3-4153-B402-A07B099C24C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4C5F324C-28C3-4153-B402-A07B099C24C6}.Debug|Any CPU.Build.0 = Debug|Any CPU {4C5F324C-28C3-4153-B402-A07B099C24C6}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -81,6 +71,10 @@ Global {99F43B70-4143-4807-9EE7-B8A799B1E702}.Debug|Any CPU.Build.0 = Debug|Any CPU {99F43B70-4143-4807-9EE7-B8A799B1E702}.Release|Any CPU.ActiveCfg = Release|Any CPU {99F43B70-4143-4807-9EE7-B8A799B1E702}.Release|Any CPU.Build.0 = Release|Any CPU + {08194729-E222-4C9A-B860-D944225B8895}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {08194729-E222-4C9A-B860-D944225B8895}.Debug|Any CPU.Build.0 = Debug|Any CPU + {08194729-E222-4C9A-B860-D944225B8895}.Release|Any CPU.ActiveCfg = Release|Any CPU + {08194729-E222-4C9A-B860-D944225B8895}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE