From 76791a0e27fba3112675d41543e578f03382a532 Mon Sep 17 00:00:00 2001 From: masapountz Date: Mon, 19 Feb 2024 10:01:59 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=203=20Mapper=20(Inquiry,InquiryTable?= =?UTF-8?q?,Solution)=20+=20Ajout=20classes=20m=C3=A9tier=20correspondante?= =?UTF-8?q?s=20+=20DTO=20(Peut-=C3=AAtre=20revoir=20les=20informations=20?= =?UTF-8?q?=C3=A0=20garder)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLudeoDB/InquiryEntity.cs | 12 +++++- .../EntityFramework/SQLudeoDB/LessonEntity.cs | 10 ++--- API_SQLuedo/Model/Business/Inquiry.cs | 22 +++++++++- API_SQLuedo/Model/Business/InquiryTable.cs | 32 +++++++++++++++ API_SQLuedo/Model/Business/Solution.cs | 40 +++++++++++++++++++ API_SQLuedo/Model/DTO/InquiryDTO.cs | 23 ++++++++++- API_SQLuedo/Model/DTO/InquiryTableDTO.cs | 29 ++++++++++++++ API_SQLuedo/Model/DTO/SolutionDTO.cs | 40 +++++++++++++++++++ API_SQLuedo/Model/Mappers/IMapper.cs | 17 -------- API_SQLuedo/Model/Mappers/InquiryMapper.cs | 23 +++-------- .../Model/Mappers/InquiryTableMapper.cs | 23 +++++++++++ API_SQLuedo/Model/Mappers/SolutionMapper.cs | 18 +++++++++ API_SQLuedo/Model/Mappers/UserMapper.cs | 9 +++++ 13 files changed, 256 insertions(+), 42 deletions(-) create mode 100644 API_SQLuedo/Model/Business/InquiryTable.cs create mode 100644 API_SQLuedo/Model/Business/Solution.cs create mode 100644 API_SQLuedo/Model/DTO/InquiryTableDTO.cs create mode 100644 API_SQLuedo/Model/DTO/SolutionDTO.cs delete mode 100644 API_SQLuedo/Model/Mappers/IMapper.cs create mode 100644 API_SQLuedo/Model/Mappers/InquiryTableMapper.cs create mode 100644 API_SQLuedo/Model/Mappers/SolutionMapper.cs diff --git a/API_SQLuedo/EntityFramework/SQLudeoDB/InquiryEntity.cs b/API_SQLuedo/EntityFramework/SQLudeoDB/InquiryEntity.cs index b3f18b9..48b9edd 100644 --- a/API_SQLuedo/EntityFramework/SQLudeoDB/InquiryEntity.cs +++ b/API_SQLuedo/EntityFramework/SQLudeoDB/InquiryEntity.cs @@ -8,7 +8,7 @@ namespace Entities.SQLudeoDB { public class InquiryEntity { - public int Id { get; set; } + public int Id { get; } public string Title { get; set; } public string Description { get; set; } public bool IsUser { get; set; } @@ -25,5 +25,15 @@ namespace Entities.SQLudeoDB Database = database; InquiryTable = inquiryTable; } + + public InquiryEntity(string title, string description, bool isUser, InquiryTableEntity database, SolutionEntity inquiryTable) + { + Id = 0; + Title = title; + Description = description; + IsUser = isUser; + Database = database; + InquiryTable = inquiryTable; + } } } diff --git a/API_SQLuedo/EntityFramework/SQLudeoDB/LessonEntity.cs b/API_SQLuedo/EntityFramework/SQLudeoDB/LessonEntity.cs index 02cc9ee..bd869f3 100644 --- a/API_SQLuedo/EntityFramework/SQLudeoDB/LessonEntity.cs +++ b/API_SQLuedo/EntityFramework/SQLudeoDB/LessonEntity.cs @@ -9,22 +9,22 @@ namespace Entities.SQLudeoDB public class LessonEntity { public int Id { get; set; } - public string Titla { get; set; } + public string Title { get; set; } public string LastPublisher { get; set; } public DateOnly LastEdit { get; set; } public LessonEntity() { } - public LessonEntity(int id, string titla, string lastPublisher, DateOnly lastEdit) + public LessonEntity(int id, string title, string lastPublisher, DateOnly lastEdit) { Id = id; - Titla = titla; + Title = title; LastPublisher = lastPublisher; LastEdit = lastEdit; } - public LessonEntity(string titla, string lastPublisher, DateOnly lastEdit) + public LessonEntity(string title, string lastPublisher, DateOnly lastEdit) { - Titla = titla; + Title = title; LastPublisher = lastPublisher; LastEdit = lastEdit; } diff --git a/API_SQLuedo/Model/Business/Inquiry.cs b/API_SQLuedo/Model/Business/Inquiry.cs index e867bd0..77c8fe0 100644 --- a/API_SQLuedo/Model/Business/Inquiry.cs +++ b/API_SQLuedo/Model/Business/Inquiry.cs @@ -1,5 +1,7 @@ -using System; +using Entities.SQLudeoDB; +using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,5 +10,23 @@ namespace Model.Business { public class Inquiry { + public int Id { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public bool IsUser { get; set; } + public InquiryTable Database { get; set; } + public Solution InquiryTable { get; set; } + + public Inquiry() { } + + public Inquiry(int id, string title, string description, bool isUser, InquiryTable database, Solution inquiryTable) + { + Id = id; + Title = title; + Description = description; + IsUser = isUser; + Database = database; + InquiryTable = inquiryTable; + } } } diff --git a/API_SQLuedo/Model/Business/InquiryTable.cs b/API_SQLuedo/Model/Business/InquiryTable.cs new file mode 100644 index 0000000..99b1169 --- /dev/null +++ b/API_SQLuedo/Model/Business/InquiryTable.cs @@ -0,0 +1,32 @@ +using Entities.SQLudeoDB; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.Business +{ + public class InquiryTable + { + public int OwnerId { get; set; } + public Inquiry Owner { get; set; } + public string DatabaseName { get; set; } + public string ConnectionInfo { get; set; } + + public InquiryTable() { } + public InquiryTable(int inquiryId, string databaseName, string connectionInfo) + { + OwnerId = inquiryId; + DatabaseName = databaseName; + ConnectionInfo = connectionInfo; + } + + public InquiryTable(Inquiry owner, string databaseName, string connectionInfo) + { + Owner = owner; + DatabaseName = databaseName; + ConnectionInfo = connectionInfo; + } + } +} diff --git a/API_SQLuedo/Model/Business/Solution.cs b/API_SQLuedo/Model/Business/Solution.cs new file mode 100644 index 0000000..d09b7e7 --- /dev/null +++ b/API_SQLuedo/Model/Business/Solution.cs @@ -0,0 +1,40 @@ +using Entities.SQLudeoDB; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.Business +{ + public class Solution + { + public int OwnerId { get; set; } + public Inquiry Owner { get; set; } + public string MurdererFirstName { get; set; } + public string MurdererLastName { get; set; } + public string MurderPlace { get; set; } + public string MurderWeapon { get; set; } + public string Explanation { get; set; } + public Solution() { } + public Solution(int ownerId, Inquiry owner, string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon, string explanation) + { + OwnerId = ownerId; + Owner = owner; + MurdererFirstName = murdererFirstName; + MurdererLastName = murdererLastName; + MurderPlace = murderPlace; + MurderWeapon = murderWeapon; + Explanation = explanation; + } + public Solution(Inquiry owner, string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon, string explanation) + { + Owner = owner; + MurdererFirstName = murdererFirstName; + MurdererLastName = murdererLastName; + MurderPlace = murderPlace; + MurderWeapon = murderWeapon; + Explanation = explanation; + } + } +} diff --git a/API_SQLuedo/Model/DTO/InquiryDTO.cs b/API_SQLuedo/Model/DTO/InquiryDTO.cs index f4060db..27e3841 100644 --- a/API_SQLuedo/Model/DTO/InquiryDTO.cs +++ b/API_SQLuedo/Model/DTO/InquiryDTO.cs @@ -1,4 +1,5 @@ -using System; +using Entities.SQLudeoDB; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +9,25 @@ namespace Model.DTO { public class InquiryDTO { + public int Id { get;} + + public string Title { get; set; } + + public string Description { get; set; } + + public bool IsUser { get; set; } + + public InquiryTableDTO Database { get; set; } + public SolutionEntityDTO InquiryTable { get; set; } + + public InquiryDTO(int id, string title, string description, bool isUser, InquiryTableDTO database, SolutionEntityDTO inquiryTable) + { + Id = id; + Title = title; + Description = description; + IsUser = isUser; + Database = database; + InquiryTable = inquiryTable; + } } } diff --git a/API_SQLuedo/Model/DTO/InquiryTableDTO.cs b/API_SQLuedo/Model/DTO/InquiryTableDTO.cs new file mode 100644 index 0000000..20b342f --- /dev/null +++ b/API_SQLuedo/Model/DTO/InquiryTableDTO.cs @@ -0,0 +1,29 @@ +using Model.Business; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.DTO +{ + public class InquiryTableDTO + { + private Inquiry owner; + + public int OwnerId { get; set; } + public InquiryDTO Owner { get; set; } + public string DatabaseName { get; set; } + public string ConnectionInfo { get; set; } + + public InquiryTableDTO() { } + + public InquiryTableDTO(int ownerId, InquiryDTO owner, string databaseName, string connectionInfo) + { + OwnerId = ownerId; + Owner = owner; + DatabaseName = databaseName; + ConnectionInfo = connectionInfo; + } + } +} diff --git a/API_SQLuedo/Model/DTO/SolutionDTO.cs b/API_SQLuedo/Model/DTO/SolutionDTO.cs new file mode 100644 index 0000000..7ec656a --- /dev/null +++ b/API_SQLuedo/Model/DTO/SolutionDTO.cs @@ -0,0 +1,40 @@ +using Model.Business; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.DTO +{ + public class SolutionDTO + { + public int OwnerId { get; set; } + public InquiryDTO Owner { get; set; } + public string MurdererFirstName { get; set; } + public string MurdererLastName { get; set; } + public string MurderPlace { get; set; } + public string MurderWeapon { get; set; } + public string Explanation { get; set; } + public SolutionDTO() { } + public SolutionDTO(int ownerId, InquiryDTO owner, string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon, string explanation) + { + OwnerId = ownerId; + Owner = owner; + MurdererFirstName = murdererFirstName; + MurdererLastName = murdererLastName; + MurderPlace = murderPlace; + MurderWeapon = murderWeapon; + Explanation = explanation; + } + public SolutionDTO(InquiryDTO owner, string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon, string explanation) + { + Owner = owner; + MurdererFirstName = murdererFirstName; + MurdererLastName = murdererLastName; + MurderPlace = murderPlace; + MurderWeapon = murderWeapon; + Explanation = explanation; + } + } +} diff --git a/API_SQLuedo/Model/Mappers/IMapper.cs b/API_SQLuedo/Model/Mappers/IMapper.cs deleted file mode 100644 index 01790e5..0000000 --- a/API_SQLuedo/Model/Mappers/IMapper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices.ObjectiveC; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Mappers -{ - public interface IMapper - { - public Object FromEntityToModel(object o); - public Object FromModelToDTO(object o); - public Object FromDTOToModel(object o); - public Object FromModelToEntity(object o); - } -} diff --git a/API_SQLuedo/Model/Mappers/InquiryMapper.cs b/API_SQLuedo/Model/Mappers/InquiryMapper.cs index c4e916e..cb43278 100644 --- a/API_SQLuedo/Model/Mappers/InquiryMapper.cs +++ b/API_SQLuedo/Model/Mappers/InquiryMapper.cs @@ -3,29 +3,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Entities.SQLudeoDB; +using Model.Business; +using Model.DTO; namespace Model.Mappers { - public class InquiryMapper + public static class InquiryMapper { - public object FromDTOToModel() + public static Inquiry FromDTOToModel(this InquiryDTO InqDto) { - throw new NotImplementedException(); + return new Inquiry(InqDto.Id,InqDto.Title,InqDto.Description,InqDto.IsUser,InqDto.Database.FromDTOToModel(),InqDto.InquiryTable.FromDTOToModel()); } - public object FromEntityToModel() - { - throw new NotImplementedException(); - } - - public object FromModelToDTO() - { - throw new NotImplementedException(); - } - - public object FromModelToEntity() - { - throw new NotImplementedException(); - } } } diff --git a/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs b/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs new file mode 100644 index 0000000..71e62d6 --- /dev/null +++ b/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs @@ -0,0 +1,23 @@ +using Model.Business; +using Model.DTO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.Mappers +{ + public static class InquiryTableMapper + { + public static InquiryTable FromDTOToModel(this InquiryTableDTO InqTDto) + { + return new InquiryTable(InqTDto.OwnerId, InqTDto.ConnectionInfo, InqTDto.DatabaseName); + } + + public static InquiryTableDTO FromModelToDTO(this InquiryTable InqT) + { + return new InquiryTableDTO(InqT.OwnerId, InqT.Owner, InqT.DatabaseName, InqT.ConnectionInfo); + } + } +} diff --git a/API_SQLuedo/Model/Mappers/SolutionMapper.cs b/API_SQLuedo/Model/Mappers/SolutionMapper.cs new file mode 100644 index 0000000..0041921 --- /dev/null +++ b/API_SQLuedo/Model/Mappers/SolutionMapper.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model.Business; +using Model.DTO; + +namespace Model.Mappers +{ + public static class SolutionMapper + { + public static Solution FromDTOToModel(this SolutionDTO dto) + { + return new Solution(dto.OwnerId,dto.Owner.FromDTOToModel(),dto.MurdererFirstName,dto.MurdererLastName,dto.MurderPlace,dto.MurderWeapon,dto.Explanation); + } + } +} diff --git a/API_SQLuedo/Model/Mappers/UserMapper.cs b/API_SQLuedo/Model/Mappers/UserMapper.cs index d62cad7..4dd916b 100644 --- a/API_SQLuedo/Model/Mappers/UserMapper.cs +++ b/API_SQLuedo/Model/Mappers/UserMapper.cs @@ -10,11 +10,19 @@ namespace Model.Mappers { return new User(dto.Id, dto.Username, dto.Password, dto.Email, dto.IsAdmin); } + public static UserEntity FromDTOToEntity(this UserDTO dto) + { + return new UserEntity(dto.Id, dto.Username, dto.Password, dto.Email, dto.IsAdmin); + } public static User FromEntityToModel(this UserEntity entity) { return new User(entity.Id, entity.Username, entity.Password, entity.Email, entity.IsAdmin); } + public static UserDTO FromEntityToDTO(this UserEntity entity) + { + return new UserDTO(entity.Id, entity.Username, entity.Password, entity.Email, entity.IsAdmin); + } public static UserDTO FromModelToDTO(this User user) { @@ -25,5 +33,6 @@ namespace Model.Mappers { return new UserEntity(user.Id, user.Username, user.Password, user.Email, user.IsAdmin); } + } }