From c1f549bf3ec7d6a0d7b4bde9e8707c6b3351bbdf Mon Sep 17 00:00:00 2001 From: clchieu Date: Tue, 27 Feb 2024 21:07:53 +0100 Subject: [PATCH 01/11] =?UTF-8?q?Ajout=20de=20la=20partie=20stub=20s=C3=A9?= =?UTF-8?q?par=C3=A9e=20du=20projet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_SQLuedo/API_SQLuedo.sln | 6 +++ API_SQLuedo/DbContextLib/UserDbContext.cs | 31 ------------ .../StubbedContextLib/StubbedContext.cs | 50 +++++++++++++++++++ .../StubbedContextLib.csproj | 13 +++++ 4 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 API_SQLuedo/StubbedContextLib/StubbedContext.cs create mode 100644 API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj diff --git a/API_SQLuedo/API_SQLuedo.sln b/API_SQLuedo/API_SQLuedo.sln index 58f87a2..fbefbe6 100644 --- a/API_SQLuedo/API_SQLuedo.sln +++ b/API_SQLuedo/API_SQLuedo.sln @@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Servic EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleAPI", "TestConsoleAPI\TestConsoleAPI.csproj", "{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{B64941C9-0550-4C47-89B6-396F6DB0486D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,6 +59,10 @@ Global {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.Build.0 = Release|Any CPU + {B64941C9-0550-4C47-89B6-396F6DB0486D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B64941C9-0550-4C47-89B6-396F6DB0486D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B64941C9-0550-4C47-89B6-396F6DB0486D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B64941C9-0550-4C47-89B6-396F6DB0486D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/API_SQLuedo/DbContextLib/UserDbContext.cs b/API_SQLuedo/DbContextLib/UserDbContext.cs index 019d33c..487359a 100644 --- a/API_SQLuedo/DbContextLib/UserDbContext.cs +++ b/API_SQLuedo/DbContextLib/UserDbContext.cs @@ -32,37 +32,6 @@ namespace DbContextLib protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().ToTable("user"); - modelBuilder.Entity().HasData( - new UserEntity(1, "johnny", Convert.ToBase64String(KeyDerivation.Pbkdf2( - password: "motdepasse", - salt: RandomNumberGenerator.GetBytes(128 / 8), - prf: KeyDerivationPrf.HMACSHA256, - iterationCount: 100000, - numBytesRequested: 256 / 8)), "Johnny.RATTON@etu.uca.fr", true), - new UserEntity(2, "maxime", Convert.ToBase64String(KeyDerivation.Pbkdf2( - password: "motdepasse", - salt: RandomNumberGenerator.GetBytes(128 / 8), - prf: KeyDerivationPrf.HMACSHA256, - iterationCount: 100000, - numBytesRequested: 256 / 8)), "Maxime.SAPOUNTZIS@etu.uca.fr", true), - new UserEntity(3, "clement", Convert.ToBase64String(KeyDerivation.Pbkdf2( - password: "motdepasse", - salt: RandomNumberGenerator.GetBytes(128 / 8), - prf: KeyDerivationPrf.HMACSHA256, - iterationCount: 100000, - numBytesRequested: 256 / 8)), "Clement.CHIEU@etu.uca.fr", true), - new UserEntity(4, "erwan", Convert.ToBase64String(KeyDerivation.Pbkdf2( - password: "motdepasse", - salt: RandomNumberGenerator.GetBytes(128 / 8), - prf: KeyDerivationPrf.HMACSHA256, - iterationCount: 100000, - numBytesRequested: 256 / 8)), "Erwan.MENAGER@etu.uca.fr", true), - new UserEntity(5, "victor", Convert.ToBase64String(KeyDerivation.Pbkdf2( - password: "motdepasse", - salt: RandomNumberGenerator.GetBytes(128 / 8), - prf: KeyDerivationPrf.HMACSHA256, - iterationCount: 100000, - numBytesRequested: 256 / 8)), "Victor.GABORIT@etu.uca.fr", true)); modelBuilder.Entity().HasKey(c => c.LessonId); modelBuilder.Entity().HasKey(c => c.LessonPartId); modelBuilder.Entity().HasKey(s => s.UserId); diff --git a/API_SQLuedo/StubbedContextLib/StubbedContext.cs b/API_SQLuedo/StubbedContextLib/StubbedContext.cs new file mode 100644 index 0000000..52a845f --- /dev/null +++ b/API_SQLuedo/StubbedContextLib/StubbedContext.cs @@ -0,0 +1,50 @@ +using System.Security.Cryptography; +using DbContextLib; +using Entities.SQLuedoDB; +using Microsoft.AspNetCore.Cryptography.KeyDerivation; +using Microsoft.EntityFrameworkCore; + +namespace StubbedContextLib; + +public class StubbedContext : UserDbContext +{ + public StubbedContext(DbContextOptions options) : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + modelBuilder.Entity().HasData( + new UserEntity(1, "johnny", Convert.ToBase64String(KeyDerivation.Pbkdf2( + password: "motdepasse", + salt: RandomNumberGenerator.GetBytes(128 / 8), + prf: KeyDerivationPrf.HMACSHA256, + iterationCount: 100000, + numBytesRequested: 256 / 8)), "Johnny.RATTON@etu.uca.fr", true), + new UserEntity(2, "maxime", Convert.ToBase64String(KeyDerivation.Pbkdf2( + password: "motdepasse", + salt: RandomNumberGenerator.GetBytes(128 / 8), + prf: KeyDerivationPrf.HMACSHA256, + iterationCount: 100000, + numBytesRequested: 256 / 8)), "Maxime.SAPOUNTZIS@etu.uca.fr", true), + new UserEntity(3, "clement", Convert.ToBase64String(KeyDerivation.Pbkdf2( + password: "motdepasse", + salt: RandomNumberGenerator.GetBytes(128 / 8), + prf: KeyDerivationPrf.HMACSHA256, + iterationCount: 100000, + numBytesRequested: 256 / 8)), "Clement.CHIEU@etu.uca.fr", true), + new UserEntity(4, "erwan", Convert.ToBase64String(KeyDerivation.Pbkdf2( + password: "motdepasse", + salt: RandomNumberGenerator.GetBytes(128 / 8), + prf: KeyDerivationPrf.HMACSHA256, + iterationCount: 100000, + numBytesRequested: 256 / 8)), "Erwan.MENAGER@etu.uca.fr", true), + new UserEntity(5, "victor", Convert.ToBase64String(KeyDerivation.Pbkdf2( + password: "motdepasse", + salt: RandomNumberGenerator.GetBytes(128 / 8), + prf: KeyDerivationPrf.HMACSHA256, + iterationCount: 100000, + numBytesRequested: 256 / 8)), "Victor.GABORIT@etu.uca.fr", true)); + } +} \ No newline at end of file diff --git a/API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj b/API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj new file mode 100644 index 0000000..19a69a6 --- /dev/null +++ b/API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + From 375af949e71622b173de57b1b92c3f69e794ebcb Mon Sep 17 00:00:00 2001 From: clchieu Date: Tue, 27 Feb 2024 21:08:39 +0100 Subject: [PATCH 02/11] Suppression des using inutiles --- API_SQLuedo/DbContextLib/UserDbContext.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/API_SQLuedo/DbContextLib/UserDbContext.cs b/API_SQLuedo/DbContextLib/UserDbContext.cs index 487359a..9e0b150 100644 --- a/API_SQLuedo/DbContextLib/UserDbContext.cs +++ b/API_SQLuedo/DbContextLib/UserDbContext.cs @@ -1,8 +1,6 @@ using Entities.SQLuedoDB; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.AspNetCore.Cryptography.KeyDerivation; using Microsoft.EntityFrameworkCore; -using System.Security.Cryptography; using Microsoft.AspNetCore.Identity; namespace DbContextLib From ecdd8c8f5618623ef99dc892f649accf5d77fa48 Mon Sep 17 00:00:00 2001 From: clchieu Date: Tue, 27 Feb 2024 21:14:57 +0100 Subject: [PATCH 03/11] =?UTF-8?q?D=C3=A9placement=20des=20dto=20et=20suppr?= =?UTF-8?q?ession=20d'une=20couche=20de=20hi=C3=A9rarchie=20inutile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../API/Controllers/InquiriesController.cs | 17 +++++++------ API_SQLuedo/API/Controllers/UserController.cs | 14 +++++------ API_SQLuedo/API_SQLuedo.sln | 6 +++++ .../{Model/DTO => Dto}/BlackListDTO.cs | 8 +------ .../{Model/DTO => Dto}/ContentLessonDTO.cs | 10 +------- API_SQLuedo/Dto/Dto.csproj | 9 +++++++ API_SQLuedo/{Model/DTO => Dto}/InquiryDTO.cs | 9 +------ .../{Model/DTO => Dto}/InquiryTableDTO.cs | 9 +------ API_SQLuedo/{Model/DTO => Dto}/LessonDTO.cs | 8 +------ API_SQLuedo/{Model/DTO => Dto}/NotepadDTO.cs | 8 +------ .../{Model/DTO => Dto}/ParagraphDTO.cs | 8 +------ API_SQLuedo/{Model/DTO => Dto}/SolutionDTO.cs | 9 +------ API_SQLuedo/{Model/DTO => Dto}/SuccessDTO.cs | 8 +------ API_SQLuedo/{Model/DTO => Dto}/UserDTO.cs | 8 +------ .../{SQLuedoDB => }/BlackListEntity.cs | 0 .../{SQLuedoDB => }/ContentLessonEntity.cs | 0 .../{SQLuedoDB => }/InquiryEntity.cs | 0 .../{SQLuedoDB => }/InquiryTableEntity.cs | 0 .../{SQLuedoDB => }/LessonEntity.cs | 0 .../{SQLuedoDB => }/NotepadEntity.cs | 0 .../{SQLuedoDB => }/ParagraphEntity.cs | 0 .../{SQLuedoDB => }/SolutionEntity.cs | 0 .../{SQLuedoDB => }/SuccessEntity.cs | 0 .../{SQLuedoDB => }/UserEntity.cs | 0 API_SQLuedo/Model/Mappers/BlackListMapper.cs | 2 +- .../Model/Mappers/ContentLessonMapper.cs | 1 + API_SQLuedo/Model/Mappers/InquiryMapper.cs | 2 +- .../Model/Mappers/InquiryTableMapper.cs | 2 +- API_SQLuedo/Model/Mappers/LessonMapper.cs | 2 +- API_SQLuedo/Model/Mappers/NotepadMapper.cs | 2 +- API_SQLuedo/Model/Mappers/ParagraphMapper.cs | 3 ++- API_SQLuedo/Model/Mappers/SolutionMapper.cs | 2 +- API_SQLuedo/Model/Mappers/SuccessMapper.cs | 2 +- API_SQLuedo/Model/Mappers/UserMapper.cs | 4 ++-- API_SQLuedo/Model/Model.csproj | 1 + API_SQLuedo/Services/IDataService.cs | 4 ++-- API_SQLuedo/Services/UserDataService.cs | 24 +++++++++---------- API_SQLuedo/TestConsoleAPI/Program.cs | 2 +- 38 files changed, 68 insertions(+), 116 deletions(-) rename API_SQLuedo/{Model/DTO => Dto}/BlackListDTO.cs (68%) rename API_SQLuedo/{Model/DTO => Dto}/ContentLessonDTO.cs (56%) create mode 100644 API_SQLuedo/Dto/Dto.csproj rename API_SQLuedo/{Model/DTO => Dto}/InquiryDTO.cs (78%) rename API_SQLuedo/{Model/DTO => Dto}/InquiryTableDTO.cs (73%) rename API_SQLuedo/{Model/DTO => Dto}/LessonDTO.cs (83%) rename API_SQLuedo/{Model/DTO => Dto}/NotepadDTO.cs (81%) rename API_SQLuedo/{Model/DTO => Dto}/ParagraphDTO.cs (86%) rename API_SQLuedo/{Model/DTO => Dto}/SolutionDTO.cs (87%) rename API_SQLuedo/{Model/DTO => Dto}/SuccessDTO.cs (73%) rename API_SQLuedo/{Model/DTO => Dto}/UserDTO.cs (86%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/BlackListEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/ContentLessonEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/InquiryEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/InquiryTableEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/LessonEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/NotepadEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/ParagraphEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/SolutionEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/SuccessEntity.cs (100%) rename API_SQLuedo/EntityFramework/{SQLuedoDB => }/UserEntity.cs (100%) diff --git a/API_SQLuedo/API/Controllers/InquiriesController.cs b/API_SQLuedo/API/Controllers/InquiriesController.cs index e42d14e..c1d8210 100644 --- a/API_SQLuedo/API/Controllers/InquiriesController.cs +++ b/API_SQLuedo/API/Controllers/InquiriesController.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Model.DTO; using Services; namespace API.Controllers @@ -21,9 +20,9 @@ namespace API.Controllers [HttpGet("inquiries/{page}/{number}")] public IActionResult GetInquiries(int page, int number) - { + { var nbInquiry = _inquiryDataService.GetInquiries(page, number).Count(); - if (nbInquiry == 0) + if (nbInquiry == 0) { _logger.LogError("[ERREUR] Aucune enquête trouvé."); return StatusCode(204); @@ -34,13 +33,13 @@ namespace API.Controllers [HttpGet("inquiry/id/{id}")] public IActionResult GetInquiryById(int id) - { + { try { _logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id); return Ok(_inquiryDataService.GetInquiryById(id)); - } - catch (ArgumentException) + } + catch (ArgumentException) { _logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id); return NotFound(); @@ -49,13 +48,13 @@ namespace API.Controllers [HttpGet("inquiry/title/{title}")] public IActionResult GetInquiryByTitle(string title) - { + { try { _logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title); return Ok(_inquiryDataService.GetInquiryByTitle(title)); - } - catch (ArgumentException) + } + catch (ArgumentException) { _logger.LogError("[ERREUR] Aucune enquête trouvée avec le titre {title}.", title); return NotFound(); diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index 6d2e9d6..2eb4be4 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -1,9 +1,9 @@ using DbContextLib; +using Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Model.Business; -using Model.DTO; using Services; namespace API.Controllers @@ -14,8 +14,8 @@ namespace API.Controllers [ApiController] public class UserController : Controller { - private IDataService _userDataService; - + private IDataService _userDataService; + private readonly ILogger _logger; public UserController(IDataService userDataService, ILogger logger) @@ -85,9 +85,9 @@ namespace API.Controllers [HttpPost] public IActionResult CreateUser([FromBody]UserDTO dto) { - if (dto.Username == null || dto.Password == null || dto.Email == null) - { - return BadRequest(); + if (dto.Username == null || dto.Password == null || dto.Email == null) + { + return BadRequest(); } // return Ok(_userDataService.CreateUser(username, password, email, isAdmin)); _logger.LogInformation("[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}", dto.Username, dto.Password, dto.Email, dto.IsAdmin); @@ -98,7 +98,7 @@ namespace API.Controllers public IActionResult UpdateUser(int id, [FromBody] UserDTO userDTO) { if(id != userDTO.Id) - { + { _logger.LogError("[ERREUR] Problème ID - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id); return BadRequest(); } diff --git a/API_SQLuedo/API_SQLuedo.sln b/API_SQLuedo/API_SQLuedo.sln index fbefbe6..a02afdd 100644 --- a/API_SQLuedo/API_SQLuedo.sln +++ b/API_SQLuedo/API_SQLuedo.sln @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleAPI", "TestConso EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{B64941C9-0550-4C47-89B6-396F6DB0486D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dto", "Dto\Dto.csproj", "{9682CA6B-2380-463B-B6BC-17C3B9E992C8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -63,6 +65,10 @@ Global {B64941C9-0550-4C47-89B6-396F6DB0486D}.Debug|Any CPU.Build.0 = Debug|Any CPU {B64941C9-0550-4C47-89B6-396F6DB0486D}.Release|Any CPU.ActiveCfg = Release|Any CPU {B64941C9-0550-4C47-89B6-396F6DB0486D}.Release|Any CPU.Build.0 = Release|Any CPU + {9682CA6B-2380-463B-B6BC-17C3B9E992C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9682CA6B-2380-463B-B6BC-17C3B9E992C8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9682CA6B-2380-463B-B6BC-17C3B9E992C8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9682CA6B-2380-463B-B6BC-17C3B9E992C8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/API_SQLuedo/Model/DTO/BlackListDTO.cs b/API_SQLuedo/Dto/BlackListDTO.cs similarity index 68% rename from API_SQLuedo/Model/DTO/BlackListDTO.cs rename to API_SQLuedo/Dto/BlackListDTO.cs index 2ecfcaf..e614e70 100644 --- a/API_SQLuedo/Model/DTO/BlackListDTO.cs +++ b/API_SQLuedo/Dto/BlackListDTO.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class BlackListDTO { diff --git a/API_SQLuedo/Model/DTO/ContentLessonDTO.cs b/API_SQLuedo/Dto/ContentLessonDTO.cs similarity index 56% rename from API_SQLuedo/Model/DTO/ContentLessonDTO.cs rename to API_SQLuedo/Dto/ContentLessonDTO.cs index 966509c..ef844e7 100644 --- a/API_SQLuedo/Model/DTO/ContentLessonDTO.cs +++ b/API_SQLuedo/Dto/ContentLessonDTO.cs @@ -1,12 +1,4 @@ -using Entities.SQLuedoDB; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace Dto { public class ContentLessonDTO { diff --git a/API_SQLuedo/Dto/Dto.csproj b/API_SQLuedo/Dto/Dto.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/API_SQLuedo/Dto/Dto.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/API_SQLuedo/Model/DTO/InquiryDTO.cs b/API_SQLuedo/Dto/InquiryDTO.cs similarity index 78% rename from API_SQLuedo/Model/DTO/InquiryDTO.cs rename to API_SQLuedo/Dto/InquiryDTO.cs index 8060ef3..a1e438f 100644 --- a/API_SQLuedo/Model/DTO/InquiryDTO.cs +++ b/API_SQLuedo/Dto/InquiryDTO.cs @@ -1,11 +1,4 @@ -using Entities.SQLuedoDB; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class InquiryDTO { diff --git a/API_SQLuedo/Model/DTO/InquiryTableDTO.cs b/API_SQLuedo/Dto/InquiryTableDTO.cs similarity index 73% rename from API_SQLuedo/Model/DTO/InquiryTableDTO.cs rename to API_SQLuedo/Dto/InquiryTableDTO.cs index e08ecda..ce28216 100644 --- a/API_SQLuedo/Model/DTO/InquiryTableDTO.cs +++ b/API_SQLuedo/Dto/InquiryTableDTO.cs @@ -1,11 +1,4 @@ -using Model.Business; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class InquiryTableDTO { diff --git a/API_SQLuedo/Model/DTO/LessonDTO.cs b/API_SQLuedo/Dto/LessonDTO.cs similarity index 83% rename from API_SQLuedo/Model/DTO/LessonDTO.cs rename to API_SQLuedo/Dto/LessonDTO.cs index 8680d98..70983ff 100644 --- a/API_SQLuedo/Model/DTO/LessonDTO.cs +++ b/API_SQLuedo/Dto/LessonDTO.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class LessonDTO { diff --git a/API_SQLuedo/Model/DTO/NotepadDTO.cs b/API_SQLuedo/Dto/NotepadDTO.cs similarity index 81% rename from API_SQLuedo/Model/DTO/NotepadDTO.cs rename to API_SQLuedo/Dto/NotepadDTO.cs index e3fd9c9..3e86998 100644 --- a/API_SQLuedo/Model/DTO/NotepadDTO.cs +++ b/API_SQLuedo/Dto/NotepadDTO.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class NotepadDTO { diff --git a/API_SQLuedo/Model/DTO/ParagraphDTO.cs b/API_SQLuedo/Dto/ParagraphDTO.cs similarity index 86% rename from API_SQLuedo/Model/DTO/ParagraphDTO.cs rename to API_SQLuedo/Dto/ParagraphDTO.cs index e6a3442..c203c9c 100644 --- a/API_SQLuedo/Model/DTO/ParagraphDTO.cs +++ b/API_SQLuedo/Dto/ParagraphDTO.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class ParagraphDTO { diff --git a/API_SQLuedo/Model/DTO/SolutionDTO.cs b/API_SQLuedo/Dto/SolutionDTO.cs similarity index 87% rename from API_SQLuedo/Model/DTO/SolutionDTO.cs rename to API_SQLuedo/Dto/SolutionDTO.cs index 50e1e84..a775fd6 100644 --- a/API_SQLuedo/Model/DTO/SolutionDTO.cs +++ b/API_SQLuedo/Dto/SolutionDTO.cs @@ -1,11 +1,4 @@ -using Model.Business; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class SolutionDTO { diff --git a/API_SQLuedo/Model/DTO/SuccessDTO.cs b/API_SQLuedo/Dto/SuccessDTO.cs similarity index 73% rename from API_SQLuedo/Model/DTO/SuccessDTO.cs rename to API_SQLuedo/Dto/SuccessDTO.cs index 924117a..ad3fcb3 100644 --- a/API_SQLuedo/Model/DTO/SuccessDTO.cs +++ b/API_SQLuedo/Dto/SuccessDTO.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class SuccessDTO { diff --git a/API_SQLuedo/Model/DTO/UserDTO.cs b/API_SQLuedo/Dto/UserDTO.cs similarity index 86% rename from API_SQLuedo/Model/DTO/UserDTO.cs rename to API_SQLuedo/Dto/UserDTO.cs index 06aa236..9a96905 100644 --- a/API_SQLuedo/Model/DTO/UserDTO.cs +++ b/API_SQLuedo/Dto/UserDTO.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.DTO +namespace Dto { public class UserDTO { diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/BlackListEntity.cs b/API_SQLuedo/EntityFramework/BlackListEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/BlackListEntity.cs rename to API_SQLuedo/EntityFramework/BlackListEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/ContentLessonEntity.cs b/API_SQLuedo/EntityFramework/ContentLessonEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/ContentLessonEntity.cs rename to API_SQLuedo/EntityFramework/ContentLessonEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/InquiryEntity.cs b/API_SQLuedo/EntityFramework/InquiryEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/InquiryEntity.cs rename to API_SQLuedo/EntityFramework/InquiryEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/InquiryTableEntity.cs b/API_SQLuedo/EntityFramework/InquiryTableEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/InquiryTableEntity.cs rename to API_SQLuedo/EntityFramework/InquiryTableEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/LessonEntity.cs b/API_SQLuedo/EntityFramework/LessonEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/LessonEntity.cs rename to API_SQLuedo/EntityFramework/LessonEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/NotepadEntity.cs b/API_SQLuedo/EntityFramework/NotepadEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/NotepadEntity.cs rename to API_SQLuedo/EntityFramework/NotepadEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/ParagraphEntity.cs b/API_SQLuedo/EntityFramework/ParagraphEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/ParagraphEntity.cs rename to API_SQLuedo/EntityFramework/ParagraphEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/SolutionEntity.cs b/API_SQLuedo/EntityFramework/SolutionEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/SolutionEntity.cs rename to API_SQLuedo/EntityFramework/SolutionEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/SuccessEntity.cs b/API_SQLuedo/EntityFramework/SuccessEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/SuccessEntity.cs rename to API_SQLuedo/EntityFramework/SuccessEntity.cs diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/UserEntity.cs b/API_SQLuedo/EntityFramework/UserEntity.cs similarity index 100% rename from API_SQLuedo/EntityFramework/SQLuedoDB/UserEntity.cs rename to API_SQLuedo/EntityFramework/UserEntity.cs diff --git a/API_SQLuedo/Model/Mappers/BlackListMapper.cs b/API_SQLuedo/Model/Mappers/BlackListMapper.cs index 8f6f52d..4ada8c5 100644 --- a/API_SQLuedo/Model/Mappers/BlackListMapper.cs +++ b/API_SQLuedo/Model/Mappers/BlackListMapper.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; using Model.Business; -using Model.DTO; namespace Model.Mappers { diff --git a/API_SQLuedo/Model/Mappers/ContentLessonMapper.cs b/API_SQLuedo/Model/Mappers/ContentLessonMapper.cs index f568070..4084b0b 100644 --- a/API_SQLuedo/Model/Mappers/ContentLessonMapper.cs +++ b/API_SQLuedo/Model/Mappers/ContentLessonMapper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; using Model.Business; diff --git a/API_SQLuedo/Model/Mappers/InquiryMapper.cs b/API_SQLuedo/Model/Mappers/InquiryMapper.cs index a26ef45..e6d30d4 100644 --- a/API_SQLuedo/Model/Mappers/InquiryMapper.cs +++ b/API_SQLuedo/Model/Mappers/InquiryMapper.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; using Model.Business; -using Model.DTO; namespace Model.Mappers { diff --git a/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs b/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs index 234aa35..b1c9d55 100644 --- a/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs +++ b/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs @@ -1,10 +1,10 @@ using Model.Business; -using Model.DTO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; namespace Model.Mappers diff --git a/API_SQLuedo/Model/Mappers/LessonMapper.cs b/API_SQLuedo/Model/Mappers/LessonMapper.cs index 1ca4094..f33dd25 100644 --- a/API_SQLuedo/Model/Mappers/LessonMapper.cs +++ b/API_SQLuedo/Model/Mappers/LessonMapper.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; using Model.Business; -using Model.DTO; namespace Model.Mappers { diff --git a/API_SQLuedo/Model/Mappers/NotepadMapper.cs b/API_SQLuedo/Model/Mappers/NotepadMapper.cs index f19109b..2984220 100644 --- a/API_SQLuedo/Model/Mappers/NotepadMapper.cs +++ b/API_SQLuedo/Model/Mappers/NotepadMapper.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; using Model.Business; -using Model.DTO; namespace Model.Mappers { diff --git a/API_SQLuedo/Model/Mappers/ParagraphMapper.cs b/API_SQLuedo/Model/Mappers/ParagraphMapper.cs index 5d1928c..0ce3d02 100644 --- a/API_SQLuedo/Model/Mappers/ParagraphMapper.cs +++ b/API_SQLuedo/Model/Mappers/ParagraphMapper.cs @@ -3,9 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; using Model.Business; -using Model.DTO; + namespace Model.Mappers { public static class ParagraphMapper diff --git a/API_SQLuedo/Model/Mappers/SolutionMapper.cs b/API_SQLuedo/Model/Mappers/SolutionMapper.cs index a464be8..6afd56b 100644 --- a/API_SQLuedo/Model/Mappers/SolutionMapper.cs +++ b/API_SQLuedo/Model/Mappers/SolutionMapper.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; using Model.Business; -using Model.DTO; namespace Model.Mappers { diff --git a/API_SQLuedo/Model/Mappers/SuccessMapper.cs b/API_SQLuedo/Model/Mappers/SuccessMapper.cs index 04f56b3..9db8e9f 100644 --- a/API_SQLuedo/Model/Mappers/SuccessMapper.cs +++ b/API_SQLuedo/Model/Mappers/SuccessMapper.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Entities.SQLuedoDB; using Model.Business; -using Model.DTO; namespace Model.Mappers { diff --git a/API_SQLuedo/Model/Mappers/UserMapper.cs b/API_SQLuedo/Model/Mappers/UserMapper.cs index 68d80a0..ab2dda5 100644 --- a/API_SQLuedo/Model/Mappers/UserMapper.cs +++ b/API_SQLuedo/Model/Mappers/UserMapper.cs @@ -1,6 +1,6 @@ -using Entities.SQLuedoDB; +using Dto; +using Entities.SQLuedoDB; using Model.Business; -using Model.DTO; namespace Model.Mappers { diff --git a/API_SQLuedo/Model/Model.csproj b/API_SQLuedo/Model/Model.csproj index 6e81eea..73abdcf 100644 --- a/API_SQLuedo/Model/Model.csproj +++ b/API_SQLuedo/Model/Model.csproj @@ -20,6 +20,7 @@ + diff --git a/API_SQLuedo/Services/IDataService.cs b/API_SQLuedo/Services/IDataService.cs index a3faad9..1f81b09 100644 --- a/API_SQLuedo/Services/IDataService.cs +++ b/API_SQLuedo/Services/IDataService.cs @@ -1,5 +1,5 @@ -using Model.Business; -using Model.DTO; +using Dto; +using Model.Business; namespace Services { diff --git a/API_SQLuedo/Services/UserDataService.cs b/API_SQLuedo/Services/UserDataService.cs index ddaa3e6..1a8fdff 100644 --- a/API_SQLuedo/Services/UserDataService.cs +++ b/API_SQLuedo/Services/UserDataService.cs @@ -1,10 +1,10 @@ using DbContextLib; -using Model.DTO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Dto; using Model.Mappers; using Model.Business; using Microsoft.EntityFrameworkCore; @@ -92,16 +92,16 @@ namespace Services public IEnumerable GetInquiries(int page, int number) { throw new NotImplementedException(); - } - - public InquiryDTO GetInquiryById(int id) - { - throw new NotImplementedException(); - } - - public InquiryDTO GetInquiryByTitle(string title) - { - throw new NotImplementedException(); - } + } + + public InquiryDTO GetInquiryById(int id) + { + throw new NotImplementedException(); + } + + public InquiryDTO GetInquiryByTitle(string title) + { + throw new NotImplementedException(); + } } } diff --git a/API_SQLuedo/TestConsoleAPI/Program.cs b/API_SQLuedo/TestConsoleAPI/Program.cs index 651de21..9d83c32 100644 --- a/API_SQLuedo/TestConsoleAPI/Program.cs +++ b/API_SQLuedo/TestConsoleAPI/Program.cs @@ -2,12 +2,12 @@ using API.Controllers; using DbContextLib; +using Dto; using Microsoft.AspNetCore.Mvc; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Model.DTO; using Services; var connection = new SqliteConnection("DataSource=:memory:"); From 5c133445a542a298b924bb28d0b39132dd4b4003 Mon Sep 17 00:00:00 2001 From: clchieu Date: Tue, 27 Feb 2024 21:26:52 +0100 Subject: [PATCH 04/11] =?UTF-8?q?:building=5Fconstruction:S=C3=A9paration?= =?UTF-8?q?=20des=20dto,=20model=20et=20mapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_SQLuedo/API/Controllers/UserController.cs | 5 +--- API_SQLuedo/API_SQLuedo.sln | 8 ++++- API_SQLuedo/DbContextLib/UserDbContext.cs | 2 +- .../EntityFramework/BlackListEntity.cs | 2 +- .../EntityFramework/ContentLessonEntity.cs | 11 ++----- API_SQLuedo/EntityFramework/InquiryEntity.cs | 8 +---- .../EntityFramework/InquiryTableEntity.cs | 6 ++-- API_SQLuedo/EntityFramework/LessonEntity.cs | 8 +---- API_SQLuedo/EntityFramework/NotepadEntity.cs | 9 ++---- .../EntityFramework/ParagraphEntity.cs | 2 +- API_SQLuedo/EntityFramework/SolutionEntity.cs | 7 ++--- API_SQLuedo/EntityFramework/SuccessEntity.cs | 10 ++----- API_SQLuedo/EntityFramework/UserEntity.cs | 2 +- API_SQLuedo/Model/{Business => }/BlackList.cs | 8 +---- .../Model/{Business => }/ContentLesson.cs | 10 +------ API_SQLuedo/Model/{Business => }/Inquiry.cs | 10 +------ .../Model/{Business => }/InquiryTable.cs | 9 +----- API_SQLuedo/Model/{Business => }/Lesson.cs | 8 +---- API_SQLuedo/Model/Model.csproj | 28 ++++-------------- API_SQLuedo/Model/{Business => }/Notepad.cs | 10 +------ API_SQLuedo/Model/{Business => }/Paragraph.cs | 8 +---- API_SQLuedo/Model/{Business => }/Solution.cs | 9 +----- API_SQLuedo/Model/{Business => }/Success.cs | 10 +------ API_SQLuedo/Model/{Business => }/User.cs | 2 +- .../BlackListMapper.cs | 13 +++------ .../ContentLessonMapper.cs | 13 +++------ .../InquiryMapper.cs | 13 +++------ .../InquiryTableMapper.cs | 13 +++------ .../LessonMapper.cs | 13 +++------ .../ModelToEntities/ModelToEntities.csproj | 29 +++++++++++++++++++ .../NotepadMapper.cs | 13 +++------ .../ParagraphMapper.cs | 13 +++------ .../SolutionMapper.cs | 13 +++------ .../SuccessMapper.cs | 13 +++------ .../Mappers => ModelToEntities}/UserMapper.cs | 6 ++-- API_SQLuedo/Services/IDataService.cs | 2 +- API_SQLuedo/Services/Services.csproj | 2 +- API_SQLuedo/Services/UserDataService.cs | 8 +---- .../StubbedContextLib/StubbedContext.cs | 2 +- .../TestConsoleAPI/TestConsoleAPI.csproj | 2 +- 40 files changed, 114 insertions(+), 246 deletions(-) rename API_SQLuedo/Model/{Business => }/BlackList.cs (67%) rename API_SQLuedo/Model/{Business => }/ContentLesson.cs (56%) rename API_SQLuedo/Model/{Business => }/Inquiry.cs (76%) rename API_SQLuedo/Model/{Business => }/InquiryTable.cs (72%) rename API_SQLuedo/Model/{Business => }/Lesson.cs (83%) rename API_SQLuedo/Model/{Business => }/Notepad.cs (73%) rename API_SQLuedo/Model/{Business => }/Paragraph.cs (86%) rename API_SQLuedo/Model/{Business => }/Solution.cs (87%) rename API_SQLuedo/Model/{Business => }/Success.cs (63%) rename API_SQLuedo/Model/{Business => }/User.cs (93%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/BlackListMapper.cs (83%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/ContentLessonMapper.cs (83%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/InquiryMapper.cs (88%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/InquiryTableMapper.cs (86%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/LessonMapper.cs (84%) create mode 100644 API_SQLuedo/ModelToEntities/ModelToEntities.csproj rename API_SQLuedo/{Model/Mappers => ModelToEntities}/NotepadMapper.cs (85%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/ParagraphMapper.cs (86%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/SolutionMapper.cs (88%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/SuccessMapper.cs (85%) rename API_SQLuedo/{Model/Mappers => ModelToEntities}/UserMapper.cs (94%) diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index 2eb4be4..505fb4f 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -1,9 +1,6 @@ -using DbContextLib; -using Dto; +using Dto; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Model.Business; using Services; namespace API.Controllers diff --git a/API_SQLuedo/API_SQLuedo.sln b/API_SQLuedo/API_SQLuedo.sln index a02afdd..85e6314 100644 --- a/API_SQLuedo/API_SQLuedo.sln +++ b/API_SQLuedo/API_SQLuedo.sln @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{6 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "EntityFramework\Entities.csproj", "{6D079CDA-C000-4833-98A0-D07D153EA264}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{ADCC427D-A3CD-431C-A90B-F9369C4584E8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelToEntities", "ModelToEntities\ModelToEntities.csproj", "{ADCC427D-A3CD-431C-A90B-F9369C4584E8}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{17025B90-8B2A-49E9-97D3-1A84A208DF50}" EndProject @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "Stubbe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dto", "Dto\Dto.csproj", "{9682CA6B-2380-463B-B6BC-17C3B9E992C8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{EDDA59D4-BD38-46BF-8292-26A47187B76F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -69,6 +71,10 @@ Global {9682CA6B-2380-463B-B6BC-17C3B9E992C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {9682CA6B-2380-463B-B6BC-17C3B9E992C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {9682CA6B-2380-463B-B6BC-17C3B9E992C8}.Release|Any CPU.Build.0 = Release|Any CPU + {EDDA59D4-BD38-46BF-8292-26A47187B76F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDDA59D4-BD38-46BF-8292-26A47187B76F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDDA59D4-BD38-46BF-8292-26A47187B76F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDDA59D4-BD38-46BF-8292-26A47187B76F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/API_SQLuedo/DbContextLib/UserDbContext.cs b/API_SQLuedo/DbContextLib/UserDbContext.cs index 9e0b150..a3956bb 100644 --- a/API_SQLuedo/DbContextLib/UserDbContext.cs +++ b/API_SQLuedo/DbContextLib/UserDbContext.cs @@ -1,4 +1,4 @@ -using Entities.SQLuedoDB; +using Entities; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Identity; diff --git a/API_SQLuedo/EntityFramework/BlackListEntity.cs b/API_SQLuedo/EntityFramework/BlackListEntity.cs index a1cb718..bcc8c6d 100644 --- a/API_SQLuedo/EntityFramework/BlackListEntity.cs +++ b/API_SQLuedo/EntityFramework/BlackListEntity.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Entities.SQLuedoDB +namespace Entities { public class BlackListEntity { diff --git a/API_SQLuedo/EntityFramework/ContentLessonEntity.cs b/API_SQLuedo/EntityFramework/ContentLessonEntity.cs index 2778c16..414fef6 100644 --- a/API_SQLuedo/EntityFramework/ContentLessonEntity.cs +++ b/API_SQLuedo/EntityFramework/ContentLessonEntity.cs @@ -1,13 +1,6 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; +using System.ComponentModel.DataAnnotations.Schema; -namespace Entities.SQLuedoDB +namespace Entities { public class ContentLessonEntity { diff --git a/API_SQLuedo/EntityFramework/InquiryEntity.cs b/API_SQLuedo/EntityFramework/InquiryEntity.cs index 4d73630..e311db5 100644 --- a/API_SQLuedo/EntityFramework/InquiryEntity.cs +++ b/API_SQLuedo/EntityFramework/InquiryEntity.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Entities.SQLuedoDB +namespace Entities { public class InquiryEntity { diff --git a/API_SQLuedo/EntityFramework/InquiryTableEntity.cs b/API_SQLuedo/EntityFramework/InquiryTableEntity.cs index 155398b..bc3f0e0 100644 --- a/API_SQLuedo/EntityFramework/InquiryTableEntity.cs +++ b/API_SQLuedo/EntityFramework/InquiryTableEntity.cs @@ -1,7 +1,7 @@ -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; -namespace Entities.SQLuedoDB +namespace Entities { public class InquiryTableEntity { diff --git a/API_SQLuedo/EntityFramework/LessonEntity.cs b/API_SQLuedo/EntityFramework/LessonEntity.cs index 623eb1b..af3986b 100644 --- a/API_SQLuedo/EntityFramework/LessonEntity.cs +++ b/API_SQLuedo/EntityFramework/LessonEntity.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Entities.SQLuedoDB +namespace Entities { public class LessonEntity { diff --git a/API_SQLuedo/EntityFramework/NotepadEntity.cs b/API_SQLuedo/EntityFramework/NotepadEntity.cs index f20c498..69226d2 100644 --- a/API_SQLuedo/EntityFramework/NotepadEntity.cs +++ b/API_SQLuedo/EntityFramework/NotepadEntity.cs @@ -1,11 +1,6 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations.Schema; -namespace Entities.SQLuedoDB +namespace Entities { public class NotepadEntity { diff --git a/API_SQLuedo/EntityFramework/ParagraphEntity.cs b/API_SQLuedo/EntityFramework/ParagraphEntity.cs index d83e27c..65bd2cb 100644 --- a/API_SQLuedo/EntityFramework/ParagraphEntity.cs +++ b/API_SQLuedo/EntityFramework/ParagraphEntity.cs @@ -1,4 +1,4 @@ -namespace Entities.SQLuedoDB +namespace Entities { public class ParagraphEntity { diff --git a/API_SQLuedo/EntityFramework/SolutionEntity.cs b/API_SQLuedo/EntityFramework/SolutionEntity.cs index 15879f7..fa15060 100644 --- a/API_SQLuedo/EntityFramework/SolutionEntity.cs +++ b/API_SQLuedo/EntityFramework/SolutionEntity.cs @@ -1,8 +1,7 @@ -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Security.Cryptography.X509Certificates; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; -namespace Entities.SQLuedoDB +namespace Entities { public class SolutionEntity { diff --git a/API_SQLuedo/EntityFramework/SuccessEntity.cs b/API_SQLuedo/EntityFramework/SuccessEntity.cs index 4c06815..81f9e11 100644 --- a/API_SQLuedo/EntityFramework/SuccessEntity.cs +++ b/API_SQLuedo/EntityFramework/SuccessEntity.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations.Schema; -namespace Entities.SQLuedoDB +namespace Entities { public class SuccessEntity { diff --git a/API_SQLuedo/EntityFramework/UserEntity.cs b/API_SQLuedo/EntityFramework/UserEntity.cs index 2de5210..52ed8f8 100644 --- a/API_SQLuedo/EntityFramework/UserEntity.cs +++ b/API_SQLuedo/EntityFramework/UserEntity.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace Entities.SQLuedoDB +namespace Entities { [Table("user")] public class UserEntity diff --git a/API_SQLuedo/Model/Business/BlackList.cs b/API_SQLuedo/Model/BlackList.cs similarity index 67% rename from API_SQLuedo/Model/Business/BlackList.cs rename to API_SQLuedo/Model/BlackList.cs index b7fb84b..a53f1e9 100644 --- a/API_SQLuedo/Model/Business/BlackList.cs +++ b/API_SQLuedo/Model/BlackList.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class BlackList { diff --git a/API_SQLuedo/Model/Business/ContentLesson.cs b/API_SQLuedo/Model/ContentLesson.cs similarity index 56% rename from API_SQLuedo/Model/Business/ContentLesson.cs rename to API_SQLuedo/Model/ContentLesson.cs index 22494db..9ad8e3c 100644 --- a/API_SQLuedo/Model/Business/ContentLesson.cs +++ b/API_SQLuedo/Model/ContentLesson.cs @@ -1,12 +1,4 @@ -using Entities.SQLuedoDB; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class ContentLesson { diff --git a/API_SQLuedo/Model/Business/Inquiry.cs b/API_SQLuedo/Model/Inquiry.cs similarity index 76% rename from API_SQLuedo/Model/Business/Inquiry.cs rename to API_SQLuedo/Model/Inquiry.cs index 316e8eb..05a23c2 100644 --- a/API_SQLuedo/Model/Business/Inquiry.cs +++ b/API_SQLuedo/Model/Inquiry.cs @@ -1,12 +1,4 @@ -using Entities.SQLuedoDB; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class Inquiry { diff --git a/API_SQLuedo/Model/Business/InquiryTable.cs b/API_SQLuedo/Model/InquiryTable.cs similarity index 72% rename from API_SQLuedo/Model/Business/InquiryTable.cs rename to API_SQLuedo/Model/InquiryTable.cs index d8ac992..e75b4fe 100644 --- a/API_SQLuedo/Model/Business/InquiryTable.cs +++ b/API_SQLuedo/Model/InquiryTable.cs @@ -1,11 +1,4 @@ -using Entities.SQLuedoDB; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class InquiryTable { diff --git a/API_SQLuedo/Model/Business/Lesson.cs b/API_SQLuedo/Model/Lesson.cs similarity index 83% rename from API_SQLuedo/Model/Business/Lesson.cs rename to API_SQLuedo/Model/Lesson.cs index 2e2121d..40f16aa 100644 --- a/API_SQLuedo/Model/Business/Lesson.cs +++ b/API_SQLuedo/Model/Lesson.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class Lesson { diff --git a/API_SQLuedo/Model/Model.csproj b/API_SQLuedo/Model/Model.csproj index 73abdcf..3a63532 100644 --- a/API_SQLuedo/Model/Model.csproj +++ b/API_SQLuedo/Model/Model.csproj @@ -1,27 +1,9 @@  - - net8.0 - enable - enable - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - + + net8.0 + enable + enable + diff --git a/API_SQLuedo/Model/Business/Notepad.cs b/API_SQLuedo/Model/Notepad.cs similarity index 73% rename from API_SQLuedo/Model/Business/Notepad.cs rename to API_SQLuedo/Model/Notepad.cs index 177a1d3..7a36862 100644 --- a/API_SQLuedo/Model/Business/Notepad.cs +++ b/API_SQLuedo/Model/Notepad.cs @@ -1,12 +1,4 @@ -using Entities.SQLuedoDB; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class Notepad { diff --git a/API_SQLuedo/Model/Business/Paragraph.cs b/API_SQLuedo/Model/Paragraph.cs similarity index 86% rename from API_SQLuedo/Model/Business/Paragraph.cs rename to API_SQLuedo/Model/Paragraph.cs index 0edb9df..62585d8 100644 --- a/API_SQLuedo/Model/Business/Paragraph.cs +++ b/API_SQLuedo/Model/Paragraph.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class Paragraph { diff --git a/API_SQLuedo/Model/Business/Solution.cs b/API_SQLuedo/Model/Solution.cs similarity index 87% rename from API_SQLuedo/Model/Business/Solution.cs rename to API_SQLuedo/Model/Solution.cs index 4835fa5..fb17dca 100644 --- a/API_SQLuedo/Model/Business/Solution.cs +++ b/API_SQLuedo/Model/Solution.cs @@ -1,11 +1,4 @@ -using Entities.SQLuedoDB; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class Solution { diff --git a/API_SQLuedo/Model/Business/Success.cs b/API_SQLuedo/Model/Success.cs similarity index 63% rename from API_SQLuedo/Model/Business/Success.cs rename to API_SQLuedo/Model/Success.cs index 6e8ff28..1fe54cf 100644 --- a/API_SQLuedo/Model/Business/Success.cs +++ b/API_SQLuedo/Model/Success.cs @@ -1,12 +1,4 @@ -using Entities.SQLuedoDB; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model.Business +namespace ModelToEntities.Business { public class Success { diff --git a/API_SQLuedo/Model/Business/User.cs b/API_SQLuedo/Model/User.cs similarity index 93% rename from API_SQLuedo/Model/Business/User.cs rename to API_SQLuedo/Model/User.cs index cf60046..2ee4ce3 100644 --- a/API_SQLuedo/Model/Business/User.cs +++ b/API_SQLuedo/Model/User.cs @@ -1,4 +1,4 @@ -namespace Model.Business +namespace ModelToEntities.Business { public class User { diff --git a/API_SQLuedo/Model/Mappers/BlackListMapper.cs b/API_SQLuedo/ModelToEntities/BlackListMapper.cs similarity index 83% rename from API_SQLuedo/Model/Mappers/BlackListMapper.cs rename to API_SQLuedo/ModelToEntities/BlackListMapper.cs index 4ada8c5..0eb2392 100644 --- a/API_SQLuedo/Model/Mappers/BlackListMapper.cs +++ b/API_SQLuedo/ModelToEntities/BlackListMapper.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class BlackListMapper { diff --git a/API_SQLuedo/Model/Mappers/ContentLessonMapper.cs b/API_SQLuedo/ModelToEntities/ContentLessonMapper.cs similarity index 83% rename from API_SQLuedo/Model/Mappers/ContentLessonMapper.cs rename to API_SQLuedo/ModelToEntities/ContentLessonMapper.cs index 4084b0b..1cff6d4 100644 --- a/API_SQLuedo/Model/Mappers/ContentLessonMapper.cs +++ b/API_SQLuedo/ModelToEntities/ContentLessonMapper.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class ContentLessonMapper { diff --git a/API_SQLuedo/Model/Mappers/InquiryMapper.cs b/API_SQLuedo/ModelToEntities/InquiryMapper.cs similarity index 88% rename from API_SQLuedo/Model/Mappers/InquiryMapper.cs rename to API_SQLuedo/ModelToEntities/InquiryMapper.cs index e6d30d4..5fc0fe4 100644 --- a/API_SQLuedo/Model/Mappers/InquiryMapper.cs +++ b/API_SQLuedo/ModelToEntities/InquiryMapper.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class InquiryMapper { diff --git a/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs b/API_SQLuedo/ModelToEntities/InquiryTableMapper.cs similarity index 86% rename from API_SQLuedo/Model/Mappers/InquiryTableMapper.cs rename to API_SQLuedo/ModelToEntities/InquiryTableMapper.cs index b1c9d55..5f01925 100644 --- a/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs +++ b/API_SQLuedo/ModelToEntities/InquiryTableMapper.cs @@ -1,13 +1,8 @@ -using Model.Business; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class InquiryTableMapper { diff --git a/API_SQLuedo/Model/Mappers/LessonMapper.cs b/API_SQLuedo/ModelToEntities/LessonMapper.cs similarity index 84% rename from API_SQLuedo/Model/Mappers/LessonMapper.cs rename to API_SQLuedo/ModelToEntities/LessonMapper.cs index f33dd25..9b22858 100644 --- a/API_SQLuedo/Model/Mappers/LessonMapper.cs +++ b/API_SQLuedo/ModelToEntities/LessonMapper.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class LessonMapper { diff --git a/API_SQLuedo/ModelToEntities/ModelToEntities.csproj b/API_SQLuedo/ModelToEntities/ModelToEntities.csproj new file mode 100644 index 0000000..1d0c3c9 --- /dev/null +++ b/API_SQLuedo/ModelToEntities/ModelToEntities.csproj @@ -0,0 +1,29 @@ + + + + net8.0 + enable + enable + ModelToEntities + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/API_SQLuedo/Model/Mappers/NotepadMapper.cs b/API_SQLuedo/ModelToEntities/NotepadMapper.cs similarity index 85% rename from API_SQLuedo/Model/Mappers/NotepadMapper.cs rename to API_SQLuedo/ModelToEntities/NotepadMapper.cs index 2984220..ecb7013 100644 --- a/API_SQLuedo/Model/Mappers/NotepadMapper.cs +++ b/API_SQLuedo/ModelToEntities/NotepadMapper.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class NotepadMapper { diff --git a/API_SQLuedo/Model/Mappers/ParagraphMapper.cs b/API_SQLuedo/ModelToEntities/ParagraphMapper.cs similarity index 86% rename from API_SQLuedo/Model/Mappers/ParagraphMapper.cs rename to API_SQLuedo/ModelToEntities/ParagraphMapper.cs index 0ce3d02..72ddb9c 100644 --- a/API_SQLuedo/Model/Mappers/ParagraphMapper.cs +++ b/API_SQLuedo/ModelToEntities/ParagraphMapper.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class ParagraphMapper { diff --git a/API_SQLuedo/Model/Mappers/SolutionMapper.cs b/API_SQLuedo/ModelToEntities/SolutionMapper.cs similarity index 88% rename from API_SQLuedo/Model/Mappers/SolutionMapper.cs rename to API_SQLuedo/ModelToEntities/SolutionMapper.cs index 6afd56b..cad2024 100644 --- a/API_SQLuedo/Model/Mappers/SolutionMapper.cs +++ b/API_SQLuedo/ModelToEntities/SolutionMapper.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class SolutionMapper { diff --git a/API_SQLuedo/Model/Mappers/SuccessMapper.cs b/API_SQLuedo/ModelToEntities/SuccessMapper.cs similarity index 85% rename from API_SQLuedo/Model/Mappers/SuccessMapper.cs rename to API_SQLuedo/ModelToEntities/SuccessMapper.cs index 9db8e9f..935689a 100644 --- a/API_SQLuedo/Model/Mappers/SuccessMapper.cs +++ b/API_SQLuedo/ModelToEntities/SuccessMapper.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Dto; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class SuccessMapper { diff --git a/API_SQLuedo/Model/Mappers/UserMapper.cs b/API_SQLuedo/ModelToEntities/UserMapper.cs similarity index 94% rename from API_SQLuedo/Model/Mappers/UserMapper.cs rename to API_SQLuedo/ModelToEntities/UserMapper.cs index ab2dda5..940a187 100644 --- a/API_SQLuedo/Model/Mappers/UserMapper.cs +++ b/API_SQLuedo/ModelToEntities/UserMapper.cs @@ -1,8 +1,8 @@ using Dto; -using Entities.SQLuedoDB; -using Model.Business; +using Entities; +using ModelToEntities.Business; -namespace Model.Mappers +namespace ModelToEntities { public static class UserMapper { diff --git a/API_SQLuedo/Services/IDataService.cs b/API_SQLuedo/Services/IDataService.cs index 1f81b09..653a3bc 100644 --- a/API_SQLuedo/Services/IDataService.cs +++ b/API_SQLuedo/Services/IDataService.cs @@ -1,5 +1,5 @@ using Dto; -using Model.Business; +using ModelToEntities.Business; namespace Services { diff --git a/API_SQLuedo/Services/Services.csproj b/API_SQLuedo/Services/Services.csproj index 4eafac0..88af2f2 100644 --- a/API_SQLuedo/Services/Services.csproj +++ b/API_SQLuedo/Services/Services.csproj @@ -22,7 +22,7 @@ - + diff --git a/API_SQLuedo/Services/UserDataService.cs b/API_SQLuedo/Services/UserDataService.cs index 1a8fdff..f0b2a3a 100644 --- a/API_SQLuedo/Services/UserDataService.cs +++ b/API_SQLuedo/Services/UserDataService.cs @@ -1,13 +1,7 @@ using DbContextLib; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Dto; -using Model.Mappers; -using Model.Business; using Microsoft.EntityFrameworkCore; +using ModelToEntities; namespace Services { diff --git a/API_SQLuedo/StubbedContextLib/StubbedContext.cs b/API_SQLuedo/StubbedContextLib/StubbedContext.cs index 52a845f..a833821 100644 --- a/API_SQLuedo/StubbedContextLib/StubbedContext.cs +++ b/API_SQLuedo/StubbedContextLib/StubbedContext.cs @@ -1,6 +1,6 @@ using System.Security.Cryptography; using DbContextLib; -using Entities.SQLuedoDB; +using Entities; using Microsoft.AspNetCore.Cryptography.KeyDerivation; using Microsoft.EntityFrameworkCore; diff --git a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj index c013237..cea8135 100644 --- a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj +++ b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj @@ -14,7 +14,7 @@ - + From ffcf615bfc92b88b49efef54b2785cf6162d5c32 Mon Sep 17 00:00:00 2001 From: clchieu Date: Tue, 27 Feb 2024 21:59:59 +0100 Subject: [PATCH 05/11] :construction: Modification des services --- API_SQLuedo/API/API.csproj | 5 ++- .../API/Controllers/InquiriesController.cs | 18 +++++----- API_SQLuedo/API/Controllers/UserController.cs | 33 ++++++++++--------- API_SQLuedo/API/Program.cs | 8 +++-- API_SQLuedo/API_SQLuedo.sln | 12 +++---- .../{ => Mapper}/BlackListMapper.cs | 0 .../{ => Mapper}/ContentLessonMapper.cs | 0 .../{ => Mapper}/InquiryMapper.cs | 0 .../{ => Mapper}/InquiryTableMapper.cs | 0 .../{ => Mapper}/LessonMapper.cs | 0 .../{ => Mapper}/NotepadMapper.cs | 0 .../{ => Mapper}/ParagraphMapper.cs | 0 .../{ => Mapper}/SolutionMapper.cs | 0 .../{ => Mapper}/SuccessMapper.cs | 0 .../{ => Mapper}/UserMapper.cs | 2 +- .../ModelToEntities/ModelToEntities.csproj | 1 + .../Service/InquiryDataService.cs | 22 +++++++++++++ .../Service}/UserDataService.cs | 27 ++++----------- API_SQLuedo/Services/IDataService.cs | 18 ---------- API_SQLuedo/Services/Services.csproj | 28 ---------------- API_SQLuedo/Shared/IInquiryService.cs | 8 +++++ API_SQLuedo/Shared/IUserService.cs | 12 +++++++ API_SQLuedo/Shared/Shared.csproj | 9 +++++ API_SQLuedo/TestConsoleAPI/Program.cs | 2 +- .../TestConsoleAPI/TestConsoleAPI.csproj | 1 - 25 files changed, 103 insertions(+), 103 deletions(-) rename API_SQLuedo/ModelToEntities/{ => Mapper}/BlackListMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/ContentLessonMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/InquiryMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/InquiryTableMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/LessonMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/NotepadMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/ParagraphMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/SolutionMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/SuccessMapper.cs (100%) rename API_SQLuedo/ModelToEntities/{ => Mapper}/UserMapper.cs (97%) create mode 100644 API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs rename API_SQLuedo/{Services => ModelToEntities/Service}/UserDataService.cs (83%) delete mode 100644 API_SQLuedo/Services/IDataService.cs delete mode 100644 API_SQLuedo/Services/Services.csproj create mode 100644 API_SQLuedo/Shared/IInquiryService.cs create mode 100644 API_SQLuedo/Shared/IUserService.cs create mode 100644 API_SQLuedo/Shared/Shared.csproj diff --git a/API_SQLuedo/API/API.csproj b/API_SQLuedo/API/API.csproj index 822644c..7d09073 100644 --- a/API_SQLuedo/API/API.csproj +++ b/API_SQLuedo/API/API.csproj @@ -25,7 +25,10 @@ - + + + + diff --git a/API_SQLuedo/API/Controllers/InquiriesController.cs b/API_SQLuedo/API/Controllers/InquiriesController.cs index c1d8210..80227f5 100644 --- a/API_SQLuedo/API/Controllers/InquiriesController.cs +++ b/API_SQLuedo/API/Controllers/InquiriesController.cs @@ -1,34 +1,34 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Services; +using Shared; namespace API.Controllers { [Route("api/[controller]")] [Authorize] [ApiController] - public class InquiriesController : Controller + public class InquiriesController : ControllerBase { - private IDataService _inquiryDataService; + private IUserService<> _inquiryUserService; private readonly ILogger _logger; - public InquiriesController(IDataService inquiryDataService) + public InquiriesController(IUserService<> inquiryUserService) { - _inquiryDataService = inquiryDataService; + _inquiryUserService = inquiryUserService; } [HttpGet("inquiries/{page}/{number}")] public IActionResult GetInquiries(int page, int number) { - var nbInquiry = _inquiryDataService.GetInquiries(page, number).Count(); + var nbInquiry = _inquiryUserService.GetInquiries(page, number).Count(); if (nbInquiry == 0) { _logger.LogError("[ERREUR] Aucune enquête trouvé."); return StatusCode(204); } _logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry); - return Ok(_inquiryDataService.GetInquiries(page, number)); + return Ok(_inquiryUserService.GetInquiries(page, number)); } [HttpGet("inquiry/id/{id}")] @@ -37,7 +37,7 @@ namespace API.Controllers try { _logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id); - return Ok(_inquiryDataService.GetInquiryById(id)); + return Ok(_inquiryUserService.GetInquiryById(id)); } catch (ArgumentException) { @@ -52,7 +52,7 @@ namespace API.Controllers try { _logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title); - return Ok(_inquiryDataService.GetInquiryByTitle(title)); + return Ok(_inquiryUserService.GetInquiryByTitle(title)); } catch (ArgumentException) { diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index 505fb4f..5d59627 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -1,7 +1,6 @@ -using Dto; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Services; +using Shared; namespace API.Controllers { @@ -9,29 +8,33 @@ namespace API.Controllers [Authorize] [ApiVersion("1.0")] [ApiController] - public class UserController : Controller + public class UserController : ControllerBase { - private IDataService _userDataService; + private IUserService<> _userUserService; private readonly ILogger _logger; - public UserController(IDataService userDataService, ILogger logger) + public UserController(IUserService<> userUserService, ILogger logger) { - _userDataService = userDataService; + _userUserService = userUserService; _logger = logger; } [HttpGet("users/{page}/{number}")] public IActionResult GetUsers(int page, int number) { - var nbUser = _userDataService.GetUsers(page, number).Count(); + var getUsers = new InClassName(page, number); + _userUserService.GetUsers(getUsers); + var nbUser = getUsers.ReturnValue.Count(); if(nbUser == 0) { _logger.LogError("[ERREUR] Aucun utilisateur trouvé."); return StatusCode(204); } _logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", nbUser); - return Ok(_userDataService.GetUsers(page, number)); + var value = new InClassName(page, number); + _userUserService.GetUsers(value); + return Ok(value.ReturnValue); } [HttpGet("user/id/{id}")] @@ -40,7 +43,7 @@ namespace API.Controllers try { _logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id); - return Ok(_userDataService.GetUserById(id)); + return Ok(_userUserService.GetUserById(id)); } catch (ArgumentException) { _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); @@ -54,7 +57,7 @@ namespace API.Controllers try { _logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username); - return Ok(_userDataService.GetUserByUsername(username)); + return Ok(_userUserService.GetUserByUsername(username)); }catch (ArgumentException) { _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {username}.", username); @@ -66,11 +69,11 @@ namespace API.Controllers [HttpDelete] public IActionResult DeleteUser(int id) { - var success = _userDataService.DeleteUser(id); + var success = _userUserService.DeleteUser(id); if(success) { _logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id); - return Ok(_userDataService.DeleteUser(id)); + return Ok(_userUserService.DeleteUser(id)); } else { _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); @@ -88,7 +91,7 @@ namespace API.Controllers } // return Ok(_userDataService.CreateUser(username, password, email, isAdmin)); _logger.LogInformation("[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}", dto.Username, dto.Password, dto.Email, dto.IsAdmin); - return Created(nameof(GetUsers), _userDataService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin)); + return Created(nameof(GetUsers), _userUserService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin)); } [HttpPut] @@ -107,7 +110,7 @@ namespace API.Controllers if(userDTO != null) { _logger.LogInformation("[INFORMATION] La mise à jour de l'utilsiateur avec l'id {id} a été effectuée", id); - return Ok(_userDataService.UpdateUser(id, userDTO)); + return Ok(_userUserService.UpdateUser(id, userDTO)); } _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); return NotFound(); diff --git a/API_SQLuedo/API/Program.cs b/API_SQLuedo/API/Program.cs index 8630246..9eeab75 100644 --- a/API_SQLuedo/API/Program.cs +++ b/API_SQLuedo/API/Program.cs @@ -1,10 +1,13 @@ using API; using DbContextLib; +using Dto; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; -using Services; +using ModelToEntities.Business; +using ModelToEntities.Service; +using Shared; var builder = WebApplication.CreateBuilder(args); @@ -14,7 +17,8 @@ builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddScoped(); +builder.Services.AddScoped, UserDataService>(); +builder.Services.AddScoped, InquiryDataService>(); builder.Services.AddDbContext(); builder.Services.AddDbContext(options => options.UseInMemoryDatabase("appDb")); builder.Services.AddIdentityApiEndpoints().AddEntityFrameworkStores(); diff --git a/API_SQLuedo/API_SQLuedo.sln b/API_SQLuedo/API_SQLuedo.sln index 85e6314..c6c08b5 100644 --- a/API_SQLuedo/API_SQLuedo.sln +++ b/API_SQLuedo/API_SQLuedo.sln @@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEF", "TestEF\TestEF.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleAPI", "TestConsoleAPI\TestConsoleAPI.csproj", "{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{B64941C9-0550-4C47-89B6-396F6DB0486D}" @@ -25,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dto", "Dto\Dto.csproj", "{9 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{EDDA59D4-BD38-46BF-8292-26A47187B76F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,10 +55,6 @@ Global {BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Debug|Any CPU.Build.0 = Debug|Any CPU {BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Release|Any CPU.ActiveCfg = Release|Any CPU {BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Release|Any CPU.Build.0 = Release|Any CPU - {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.Build.0 = Release|Any CPU {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -75,6 +71,10 @@ Global {EDDA59D4-BD38-46BF-8292-26A47187B76F}.Debug|Any CPU.Build.0 = Debug|Any CPU {EDDA59D4-BD38-46BF-8292-26A47187B76F}.Release|Any CPU.ActiveCfg = Release|Any CPU {EDDA59D4-BD38-46BF-8292-26A47187B76F}.Release|Any CPU.Build.0 = Release|Any CPU + {9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/API_SQLuedo/ModelToEntities/BlackListMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/BlackListMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/BlackListMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/BlackListMapper.cs diff --git a/API_SQLuedo/ModelToEntities/ContentLessonMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/ContentLessonMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/ContentLessonMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/ContentLessonMapper.cs diff --git a/API_SQLuedo/ModelToEntities/InquiryMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/InquiryMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/InquiryMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/InquiryMapper.cs diff --git a/API_SQLuedo/ModelToEntities/InquiryTableMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/InquiryTableMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/InquiryTableMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/InquiryTableMapper.cs diff --git a/API_SQLuedo/ModelToEntities/LessonMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/LessonMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/LessonMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/LessonMapper.cs diff --git a/API_SQLuedo/ModelToEntities/NotepadMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/NotepadMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/NotepadMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/NotepadMapper.cs diff --git a/API_SQLuedo/ModelToEntities/ParagraphMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/ParagraphMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/ParagraphMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/ParagraphMapper.cs diff --git a/API_SQLuedo/ModelToEntities/SolutionMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/SolutionMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/SolutionMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/SolutionMapper.cs diff --git a/API_SQLuedo/ModelToEntities/SuccessMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/SuccessMapper.cs similarity index 100% rename from API_SQLuedo/ModelToEntities/SuccessMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/SuccessMapper.cs diff --git a/API_SQLuedo/ModelToEntities/UserMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs similarity index 97% rename from API_SQLuedo/ModelToEntities/UserMapper.cs rename to API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs index 940a187..c570909 100644 --- a/API_SQLuedo/ModelToEntities/UserMapper.cs +++ b/API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs @@ -2,7 +2,7 @@ using Entities; using ModelToEntities.Business; -namespace ModelToEntities +namespace ModelToEntities.Service { public static class UserMapper { diff --git a/API_SQLuedo/ModelToEntities/ModelToEntities.csproj b/API_SQLuedo/ModelToEntities/ModelToEntities.csproj index 1d0c3c9..36a5aa9 100644 --- a/API_SQLuedo/ModelToEntities/ModelToEntities.csproj +++ b/API_SQLuedo/ModelToEntities/ModelToEntities.csproj @@ -24,6 +24,7 @@ + diff --git a/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs b/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs new file mode 100644 index 0000000..78c5a65 --- /dev/null +++ b/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs @@ -0,0 +1,22 @@ +using ModelToEntities.Business; +using Shared; + +namespace ModelToEntities.Service; + +public class InquiryDataService : IInquiryService +{ + public IEnumerable GetInquiries(int page, int number) + { + throw new NotImplementedException(); + } + + public Inquiry GetInquiryById(int id) + { + throw new NotImplementedException(); + } + + public Inquiry GetInquiryByTitle(string title) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Services/UserDataService.cs b/API_SQLuedo/ModelToEntities/Service/UserDataService.cs similarity index 83% rename from API_SQLuedo/Services/UserDataService.cs rename to API_SQLuedo/ModelToEntities/Service/UserDataService.cs index f0b2a3a..2e9a365 100644 --- a/API_SQLuedo/Services/UserDataService.cs +++ b/API_SQLuedo/ModelToEntities/Service/UserDataService.cs @@ -1,11 +1,11 @@ -using DbContextLib; -using Dto; +using Dto; using Microsoft.EntityFrameworkCore; -using ModelToEntities; +using ModelToEntities.Business; +using Shared; -namespace Services +namespace ModelToEntities.Service { - public class UserDataService : IDataService + public class UserDataService : IUserService { private UserDbContext DbContext { get; set; } public UserDataService(UserDbContext context) @@ -71,7 +71,7 @@ namespace Services public UserDTO CreateUser(string username, string password, string email, bool isAdmin) { - var newUserEntity = new UserDTO + var newUserEntity = new User { Username = username, Password = password, @@ -82,20 +82,5 @@ namespace Services DbContext.SaveChangesAsync(); return newUserEntity; } - - public IEnumerable GetInquiries(int page, int number) - { - throw new NotImplementedException(); - } - - public InquiryDTO GetInquiryById(int id) - { - throw new NotImplementedException(); - } - - public InquiryDTO GetInquiryByTitle(string title) - { - throw new NotImplementedException(); - } } } diff --git a/API_SQLuedo/Services/IDataService.cs b/API_SQLuedo/Services/IDataService.cs deleted file mode 100644 index 653a3bc..0000000 --- a/API_SQLuedo/Services/IDataService.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Dto; -using ModelToEntities.Business; - -namespace Services -{ - public interface IDataService - { - public IEnumerable GetUsers(int page, int number); - public UserDTO GetUserById(int id); - public UserDTO GetUserByUsername(string username); - public bool DeleteUser(int id); - public UserDTO UpdateUser(int id, UserDTO user); - public UserDTO CreateUser(string username, string password, string email, bool isAdmin); - public IEnumerable GetInquiries(int page, int number); - public InquiryDTO GetInquiryById(int id); - public InquiryDTO GetInquiryByTitle(string title); - } -} diff --git a/API_SQLuedo/Services/Services.csproj b/API_SQLuedo/Services/Services.csproj deleted file mode 100644 index 88af2f2..0000000 --- a/API_SQLuedo/Services/Services.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - diff --git a/API_SQLuedo/Shared/IInquiryService.cs b/API_SQLuedo/Shared/IInquiryService.cs new file mode 100644 index 0000000..7d03786 --- /dev/null +++ b/API_SQLuedo/Shared/IInquiryService.cs @@ -0,0 +1,8 @@ +namespace Shared; + +public interface IInquiryService +{ + public IEnumerable GetInquiries(int page, int number); + public TInquiry GetInquiryById(int id); + public TInquiry GetInquiryByTitle(string title); +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/IUserService.cs b/API_SQLuedo/Shared/IUserService.cs new file mode 100644 index 0000000..2d17fd3 --- /dev/null +++ b/API_SQLuedo/Shared/IUserService.cs @@ -0,0 +1,12 @@ +namespace Shared +{ + public interface IUserService + { + public IEnumerable GetUsers(int page, int number); + public TUser GetUserById(int id); + public TUser GetUserByUsername(string username); + public bool DeleteUser(int id); + public TUser UpdateUser(int id, TUser user); + public TUser CreateUser(string username, string password, string email, bool isAdmin); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Shared.csproj b/API_SQLuedo/Shared/Shared.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/API_SQLuedo/Shared/Shared.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/API_SQLuedo/TestConsoleAPI/Program.cs b/API_SQLuedo/TestConsoleAPI/Program.cs index 9d83c32..df49a1a 100644 --- a/API_SQLuedo/TestConsoleAPI/Program.cs +++ b/API_SQLuedo/TestConsoleAPI/Program.cs @@ -8,7 +8,7 @@ using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Services; +using ModelToEntities.Service; var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); diff --git a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj index cea8135..801193b 100644 --- a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj +++ b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj @@ -15,7 +15,6 @@ - From c8c2c969db59e6344389f47c7f39d3f1fe43c175 Mon Sep 17 00:00:00 2001 From: masapountz Date: Tue, 27 Feb 2024 22:14:20 +0100 Subject: [PATCH 06/11] Ajout des codes de retour pour les deux controllers --- .../API/Controllers/InquiriesController.cs | 9 ++++++++- API_SQLuedo/API/Controllers/UserController.cs | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/API_SQLuedo/API/Controllers/InquiriesController.cs b/API_SQLuedo/API/Controllers/InquiriesController.cs index 80227f5..0724500 100644 --- a/API_SQLuedo/API/Controllers/InquiriesController.cs +++ b/API_SQLuedo/API/Controllers/InquiriesController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using Dto; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Shared; @@ -19,6 +20,8 @@ namespace API.Controllers } [HttpGet("inquiries/{page}/{number}")] + [ProducesResponseType(typeof(InquiryDTO), 200)] + [ProducesResponseType(typeof(string), 204)] public IActionResult GetInquiries(int page, int number) { var nbInquiry = _inquiryUserService.GetInquiries(page, number).Count(); @@ -32,6 +35,8 @@ namespace API.Controllers } [HttpGet("inquiry/id/{id}")] + [ProducesResponseType(typeof(InquiryDTO), 200)] + [ProducesResponseType(typeof(string), 404)] public IActionResult GetInquiryById(int id) { try @@ -47,6 +52,8 @@ namespace API.Controllers } [HttpGet("inquiry/title/{title}")] + [ProducesResponseType(typeof(InquiryDTO), 200)] + [ProducesResponseType(typeof(string), 404)] public IActionResult GetInquiryByTitle(string title) { try diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index 5d59627..88e7c95 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using Dto; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Shared; @@ -21,6 +22,8 @@ namespace API.Controllers } [HttpGet("users/{page}/{number}")] + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 204)] public IActionResult GetUsers(int page, int number) { var getUsers = new InClassName(page, number); @@ -38,6 +41,8 @@ namespace API.Controllers } [HttpGet("user/id/{id}")] + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 404)] public IActionResult GetUserById(int id) { try @@ -52,6 +57,8 @@ namespace API.Controllers } [HttpGet("user/username/{username}")] + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 404)] public IActionResult GetUserByUsername(string username) { try @@ -67,6 +74,8 @@ namespace API.Controllers } [HttpDelete] + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 404)] public IActionResult DeleteUser(int id) { var success = _userUserService.DeleteUser(id); @@ -83,6 +92,8 @@ namespace API.Controllers } [HttpPost] + [ProducesResponseType(typeof(UserDTO), 201)] + [ProducesResponseType(typeof(string), 400)] public IActionResult CreateUser([FromBody]UserDTO dto) { if (dto.Username == null || dto.Password == null || dto.Email == null) @@ -95,6 +106,10 @@ namespace API.Controllers } [HttpPut] + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + public IActionResult UpdateUser(int id, [FromBody] UserDTO userDTO) { if(id != userDTO.Id) From b446e972737f474b1e18a0139765df75333dd7ab Mon Sep 17 00:00:00 2001 From: clchieu Date: Tue, 27 Feb 2024 22:37:06 +0100 Subject: [PATCH 07/11] :construction: Modification des services en cours --- .../API/Controllers/InquiriesController.cs | 36 +++--- API_SQLuedo/API/Controllers/UserController.cs | 106 +++++++++--------- .../ModelToEntities/ModelToEntities.csproj | 1 + .../Service/UserDataService.cs | 24 ++-- API_SQLuedo/TestConsoleAPI/Program.cs | 2 +- 5 files changed, 84 insertions(+), 85 deletions(-) diff --git a/API_SQLuedo/API/Controllers/InquiriesController.cs b/API_SQLuedo/API/Controllers/InquiriesController.cs index 80227f5..e93d43a 100644 --- a/API_SQLuedo/API/Controllers/InquiriesController.cs +++ b/API_SQLuedo/API/Controllers/InquiriesController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using Dto; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Shared; @@ -7,28 +8,21 @@ namespace API.Controllers [Route("api/[controller]")] [Authorize] [ApiController] - public class InquiriesController : ControllerBase + public class InquiriesController(ILogger logger, IInquiryService inquiryService) + : ControllerBase, IInquiryService { - private IUserService<> _inquiryUserService; - - private readonly ILogger _logger; - - public InquiriesController(IUserService<> inquiryUserService) - { - _inquiryUserService = inquiryUserService; - } - [HttpGet("inquiries/{page}/{number}")] public IActionResult GetInquiries(int page, int number) { - var nbInquiry = _inquiryUserService.GetInquiries(page, number).Count(); + var nbInquiry = inquiryService.GetInquiries(page, number).Count(); if (nbInquiry == 0) { - _logger.LogError("[ERREUR] Aucune enquête trouvé."); + logger.LogError("[ERREUR] Aucune enquête trouvé."); return StatusCode(204); } - _logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry); - return Ok(_inquiryUserService.GetInquiries(page, number)); + + logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry); + return Ok(inquiryService.GetInquiries(page, number)); } [HttpGet("inquiry/id/{id}")] @@ -36,12 +30,12 @@ namespace API.Controllers { try { - _logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id); - return Ok(_inquiryUserService.GetInquiryById(id)); + logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id); + return Ok(inquiryService.GetInquiryById(id)); } catch (ArgumentException) { - _logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id); + logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id); return NotFound(); } } @@ -51,12 +45,12 @@ namespace API.Controllers { try { - _logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title); - return Ok(_inquiryUserService.GetInquiryByTitle(title)); + logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title); + return Ok(inquiryService.GetInquiryByTitle(title)); } catch (ArgumentException) { - _logger.LogError("[ERREUR] Aucune enquête trouvée avec le titre {title}.", title); + logger.LogError("[ERREUR] Aucune enquête trouvée avec le titre {title}.", title); return NotFound(); } } diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index 5d59627..5bb8da5 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using Dto; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Shared; @@ -8,33 +9,20 @@ namespace API.Controllers [Authorize] [ApiVersion("1.0")] [ApiController] - public class UserController : ControllerBase + public class UserController(ILogger logger, IUserService userService) : ControllerBase, IUserService { - private IUserService<> _userUserService; - - private readonly ILogger _logger; - - public UserController(IUserService<> userUserService, ILogger logger) - { - _userUserService = userUserService; - _logger = logger; - } - [HttpGet("users/{page}/{number}")] - public IActionResult GetUsers(int page, int number) + public IActionResult GetUsers(int page, int number) { - var getUsers = new InClassName(page, number); - _userUserService.GetUsers(getUsers); - var nbUser = getUsers.ReturnValue.Count(); - if(nbUser == 0) + var users = userService.GetUsers(page, number).ToList(); + if (users.Count == 0) { - _logger.LogError("[ERREUR] Aucun utilisateur trouvé."); + logger.LogError("[ERREUR] Aucun utilisateur trouvé."); return StatusCode(204); } - _logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", nbUser); - var value = new InClassName(page, number); - _userUserService.GetUsers(value); - return Ok(value.ReturnValue); + + logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", users.Count); + return Ok(users); } [HttpGet("user/id/{id}")] @@ -42,11 +30,12 @@ namespace API.Controllers { try { - _logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id); - return Ok(_userUserService.GetUserById(id)); - } catch (ArgumentException) + logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id); + return Ok(userService.GetUserById(id)); + } + catch (ArgumentException) { - _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); + logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); return NotFound(); } } @@ -56,64 +45,73 @@ namespace API.Controllers { try { - _logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username); - return Ok(_userUserService.GetUserByUsername(username)); - }catch (ArgumentException) + logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username); + return Ok(userService.GetUserByUsername(username)); + } + catch (ArgumentException) { - _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {username}.", username); + logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {username}.", username); return NotFound(); } - } [HttpDelete] public IActionResult DeleteUser(int id) { - var success = _userUserService.DeleteUser(id); - if(success) + var success = userService.DeleteUser(id); + if (success) { - _logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id); - return Ok(_userUserService.DeleteUser(id)); - } else + logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id); + return Ok(userService.DeleteUser(id)); + } + else { - _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); - return NotFound(); + logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); + return NotFound(); } - } [HttpPost] - public IActionResult CreateUser([FromBody]UserDTO dto) + public IActionResult CreateUser([FromBody] UserDTO dto) { if (dto.Username == null || dto.Password == null || dto.Email == null) { return BadRequest(); } - // return Ok(_userDataService.CreateUser(username, password, email, isAdmin)); - _logger.LogInformation("[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}", dto.Username, dto.Password, dto.Email, dto.IsAdmin); - return Created(nameof(GetUsers), _userUserService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin)); + + // return Ok(userService.CreateUser(username, password, email, isAdmin)); + logger.LogInformation( + "[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}", + dto.Username, dto.Password, dto.Email, dto.IsAdmin); + return Created(nameof(GetUsers), + userService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin)); } [HttpPut] - public IActionResult UpdateUser(int id, [FromBody] UserDTO userDTO) + public IActionResult UpdateUser(int id, [FromBody] UserDTO userDto) { - if(id != userDTO.Id) + if (id != userDto.Id) { - _logger.LogError("[ERREUR] Problème ID - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id); + logger.LogError("[ERREUR] Problème ID - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id); return BadRequest(); } - if(!ModelState.IsValid) + + if (!ModelState.IsValid) { - _logger.LogError("[ERREUR] Problème controlleur - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id); + logger.LogError( + "[ERREUR] Problème controlleur - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id); return BadRequest(); } - if(userDTO != null) + + if (userDto != null) { - _logger.LogInformation("[INFORMATION] La mise à jour de l'utilsiateur avec l'id {id} a été effectuée", id); - return Ok(_userUserService.UpdateUser(id, userDTO)); + logger.LogInformation("[INFORMATION] La mise à jour de l'utilsiateur avec l'id {id} a été effectuée", + id); + return Ok(userService.UpdateUser(id, userDto)); } - _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); - return NotFound(); + + logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); + return NotFound(); } } -} +} \ No newline at end of file diff --git a/API_SQLuedo/ModelToEntities/ModelToEntities.csproj b/API_SQLuedo/ModelToEntities/ModelToEntities.csproj index 36a5aa9..9220dbb 100644 --- a/API_SQLuedo/ModelToEntities/ModelToEntities.csproj +++ b/API_SQLuedo/ModelToEntities/ModelToEntities.csproj @@ -21,6 +21,7 @@ + diff --git a/API_SQLuedo/ModelToEntities/Service/UserDataService.cs b/API_SQLuedo/ModelToEntities/Service/UserDataService.cs index 2e9a365..1ad41d2 100644 --- a/API_SQLuedo/ModelToEntities/Service/UserDataService.cs +++ b/API_SQLuedo/ModelToEntities/Service/UserDataService.cs @@ -1,6 +1,7 @@ -using Dto; +using DbContextLib; +using Dto; +using Entities; using Microsoft.EntityFrameworkCore; -using ModelToEntities.Business; using Shared; namespace ModelToEntities.Service @@ -8,7 +9,8 @@ namespace ModelToEntities.Service public class UserDataService : IUserService { private UserDbContext DbContext { get; set; } - public UserDataService(UserDbContext context) + + public UserDataService(UserDbContext context) { DbContext = context; context.Database.EnsureCreated(); @@ -21,8 +23,8 @@ namespace ModelToEntities.Service { throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(id)); } - return userEntity.FromEntityToModel().FromModelToDTO(); + return userEntity.FromEntityToModel().FromModelToDTO(); } public UserDTO GetUserByUsername(string username) @@ -32,12 +34,14 @@ namespace ModelToEntities.Service { throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(username)); } + return userEntity.FromEntityToModel().FromModelToDTO(); } public IEnumerable GetUsers(int page, int number) { - return DbContext.Users.Skip((page - 1) * number).Take(number).ToList().Select(u => u.FromEntityToModel().FromModelToDTO()); + return DbContext.Users.Skip((page - 1) * number).Take(number).ToList() + .Select(u => u.FromEntityToModel().FromModelToDTO()); } public bool DeleteUser(int id) @@ -47,6 +51,7 @@ namespace ModelToEntities.Service { return false; } + DbContext.Users.Remove(userEntity); DbContext.SaveChangesAsync(); return true; @@ -59,6 +64,7 @@ namespace ModelToEntities.Service { throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(id)); } + updatingUser.Username = user.Username; updatingUser.Password = user.Password; updatingUser.Email = user.Email; @@ -71,16 +77,16 @@ namespace ModelToEntities.Service public UserDTO CreateUser(string username, string password, string email, bool isAdmin) { - var newUserEntity = new User + var newUserEntity = new UserEntity() { Username = username, Password = password, Email = email, IsAdmin = isAdmin }; - DbContext.Users.Add(newUserEntity.FromDTOToModel().FromModelToEntity()); + DbContext.Users.Add(newUserEntity); DbContext.SaveChangesAsync(); - return newUserEntity; + return newUserEntity.FromEntityToDTO(); } } -} +} \ No newline at end of file diff --git a/API_SQLuedo/TestConsoleAPI/Program.cs b/API_SQLuedo/TestConsoleAPI/Program.cs index df49a1a..10c1d99 100644 --- a/API_SQLuedo/TestConsoleAPI/Program.cs +++ b/API_SQLuedo/TestConsoleAPI/Program.cs @@ -20,7 +20,7 @@ ILogger logger = factory.CreateLogger(); using (var context = new UserDbContext(options)) { - var controller = new UserController(new UserDataService(context), logger); + var controller = new UserController(logger); void PrintUsers() { From 6e11809f60a8531631b6065f3d9961a3ef55e808 Mon Sep 17 00:00:00 2001 From: clchieu Date: Tue, 27 Feb 2024 23:27:15 +0100 Subject: [PATCH 08/11] =?UTF-8?q?:construction:=20Les=20injections=20de=20?= =?UTF-8?q?d=C3=A9pendance=20ne=20sont=20surement=20pas=20bonnes,=20mais?= =?UTF-8?q?=20l'archi=20est=20faite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../API/Controllers/InquiriesController.cs | 33 ++++++++++++------- API_SQLuedo/API/Controllers/UserController.cs | 8 +++-- API_SQLuedo/API/Program.cs | 6 ++-- .../API/Service/InquiryDataServiceAPI.cs | 13 ++++++++ API_SQLuedo/API/Service/UserDataServiceAPI.cs | 20 +++++++++++ .../Service/InquiryDataService.cs | 11 ++++--- API_SQLuedo/TestConsoleAPI/Program.cs | 3 +- 7 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 API_SQLuedo/API/Service/InquiryDataServiceAPI.cs create mode 100644 API_SQLuedo/API/Service/UserDataServiceAPI.cs diff --git a/API_SQLuedo/API/Controllers/InquiriesController.cs b/API_SQLuedo/API/Controllers/InquiriesController.cs index 31b9626..9e4eacd 100644 --- a/API_SQLuedo/API/Controllers/InquiriesController.cs +++ b/API_SQLuedo/API/Controllers/InquiriesController.cs @@ -8,23 +8,32 @@ namespace API.Controllers [Route("api/[controller]")] [Authorize] [ApiController] - public class InquiriesController(ILogger logger, IInquiryService inquiryService) - : ControllerBase, IInquiryService + public class InquiriesController() + : ControllerBase { + private readonly IInquiryService _inquiryService; + private readonly ILogger _logger; + + public InquiriesController(IInquiryService inquiryService, ILogger logger) : this() + { + _inquiryService = inquiryService; + _logger = logger; + } + [HttpGet("inquiries/{page}/{number}")] [ProducesResponseType(typeof(InquiryDTO), 200)] [ProducesResponseType(typeof(string), 204)] public IActionResult GetInquiries(int page, int number) { - var nbInquiry = inquiryService.GetInquiries(page, number).Count(); + var nbInquiry = _inquiryService.GetInquiries(page, number).Count(); if (nbInquiry == 0) { - logger.LogError("[ERREUR] Aucune enquête trouvé."); + _logger.LogError("[ERREUR] Aucune enquête trouvé."); return StatusCode(204); } - logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry); - return Ok(inquiryService.GetInquiries(page, number)); + _logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry); + return Ok(_inquiryService.GetInquiries(page, number)); } [HttpGet("inquiry/id/{id}")] @@ -34,12 +43,12 @@ namespace API.Controllers { try { - logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id); - return Ok(inquiryService.GetInquiryById(id)); + _logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id); + return Ok(_inquiryService.GetInquiryById(id)); } catch (ArgumentException) { - logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id); + _logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id); return NotFound(); } } @@ -51,12 +60,12 @@ namespace API.Controllers { try { - logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title); - return Ok(inquiryService.GetInquiryByTitle(title)); + _logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title); + return Ok(_inquiryService.GetInquiryByTitle(title)); } catch (ArgumentException) { - logger.LogError("[ERREUR] Aucune enquête trouvée avec le titre {title}.", title); + _logger.LogError("[ERREUR] Aucune enquête trouvée avec le titre {title}.", title); return NotFound(); } } diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index a60b6e7..612d0ff 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -1,6 +1,8 @@ -using Dto; +using API.Service; +using Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using ModelToEntities.Service; using Shared; namespace API.Controllers @@ -9,7 +11,7 @@ namespace API.Controllers [Authorize] [ApiVersion("1.0")] [ApiController] - public class UserController(ILogger logger, IUserService userService) : ControllerBase, IUserService + public class UserController(ILogger logger, IUserService userService) : ControllerBase { [HttpGet("users/{page}/{number}")] [ProducesResponseType(typeof(UserDTO), 200)] @@ -101,7 +103,7 @@ namespace API.Controllers [ProducesResponseType(typeof(UserDTO), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 404)] - public IActionResult UpdateUser(int id, [FromBody] UserDTO userDTO) + public IActionResult UpdateUser(int id, [FromBody] UserDTO userDto) { if (id != userDto.Id) { diff --git a/API_SQLuedo/API/Program.cs b/API_SQLuedo/API/Program.cs index 9eeab75..2f26e29 100644 --- a/API_SQLuedo/API/Program.cs +++ b/API_SQLuedo/API/Program.cs @@ -1,11 +1,11 @@ using API; +using API.Service; using DbContextLib; using Dto; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; -using ModelToEntities.Business; using ModelToEntities.Service; using Shared; @@ -18,7 +18,9 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddScoped, UserDataService>(); -builder.Services.AddScoped, InquiryDataService>(); +builder.Services.AddScoped, UserDataServiceApi>(); +builder.Services.AddScoped, InquiryDataService>(); +builder.Services.AddScoped, InquiryDataServiceApi>(); builder.Services.AddDbContext(); builder.Services.AddDbContext(options => options.UseInMemoryDatabase("appDb")); builder.Services.AddIdentityApiEndpoints().AddEntityFrameworkStores(); diff --git a/API_SQLuedo/API/Service/InquiryDataServiceAPI.cs b/API_SQLuedo/API/Service/InquiryDataServiceAPI.cs new file mode 100644 index 0000000..90eb3e7 --- /dev/null +++ b/API_SQLuedo/API/Service/InquiryDataServiceAPI.cs @@ -0,0 +1,13 @@ +using Dto; +using Shared; + +namespace API.Service; + +public class InquiryDataServiceApi(IInquiryService inquiryService) : IInquiryService +{ + public IEnumerable GetInquiries(int page, int number) => inquiryService.GetInquiries(page, number); + + public InquiryDTO GetInquiryById(int id) => inquiryService.GetInquiryById(id); + + public InquiryDTO GetInquiryByTitle(string title) => inquiryService.GetInquiryByTitle(title); +} \ No newline at end of file diff --git a/API_SQLuedo/API/Service/UserDataServiceAPI.cs b/API_SQLuedo/API/Service/UserDataServiceAPI.cs new file mode 100644 index 0000000..66013dd --- /dev/null +++ b/API_SQLuedo/API/Service/UserDataServiceAPI.cs @@ -0,0 +1,20 @@ +using Dto; +using Shared; + +namespace API.Service; + +public class UserDataServiceApi(IUserService userService) : IUserService +{ + public IEnumerable GetUsers(int page, int number) => userService.GetUsers(page, number); + + public UserDTO GetUserById(int id) => userService.GetUserById(id); + + public UserDTO GetUserByUsername(string username) => userService.GetUserByUsername(username); + + public bool DeleteUser(int id) => userService.DeleteUser(id); + + public UserDTO UpdateUser(int id, UserDTO user) => userService.UpdateUser(id, user); + + public UserDTO CreateUser(string username, string password, string email, bool isAdmin) => + userService.CreateUser(username, password, email, isAdmin); +} \ No newline at end of file diff --git a/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs b/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs index 78c5a65..4b76513 100644 --- a/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs +++ b/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs @@ -1,21 +1,22 @@ -using ModelToEntities.Business; +using Dto; +using ModelToEntities.Business; using Shared; namespace ModelToEntities.Service; -public class InquiryDataService : IInquiryService +public class InquiryDataService : IInquiryService { - public IEnumerable GetInquiries(int page, int number) + public IEnumerable GetInquiries(int page, int number) { throw new NotImplementedException(); } - public Inquiry GetInquiryById(int id) + public InquiryDTO GetInquiryById(int id) { throw new NotImplementedException(); } - public Inquiry GetInquiryByTitle(string title) + public InquiryDTO GetInquiryByTitle(string title) { throw new NotImplementedException(); } diff --git a/API_SQLuedo/TestConsoleAPI/Program.cs b/API_SQLuedo/TestConsoleAPI/Program.cs index 10c1d99..50fd3a5 100644 --- a/API_SQLuedo/TestConsoleAPI/Program.cs +++ b/API_SQLuedo/TestConsoleAPI/Program.cs @@ -1,6 +1,7 @@ // See https://aka.ms/new-console-template for more information using API.Controllers; +using API.Service; using DbContextLib; using Dto; using Microsoft.AspNetCore.Mvc; @@ -20,7 +21,7 @@ ILogger logger = factory.CreateLogger(); using (var context = new UserDbContext(options)) { - var controller = new UserController(logger); + var controller = new UserController(logger, new UserDataServiceApi(new UserDataService(context))); void PrintUsers() { From ff1b907c801cae400a2fac082462e1013389b661 Mon Sep 17 00:00:00 2001 From: Nestisse Date: Tue, 5 Mar 2024 18:51:09 +0100 Subject: [PATCH 09/11] =?UTF-8?q?Ajout=20des=20noms=20des=20tables=20via?= =?UTF-8?q?=20les=20annotations=20de=20donn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EntityFramework/BlackListEntity.cs | 32 ++++---- .../EntityFramework/ContentLessonEntity.cs | 36 ++++----- API_SQLuedo/EntityFramework/InquiryEntity.cs | 4 +- .../EntityFramework/InquiryTableEntity.cs | 56 +++++++------- API_SQLuedo/EntityFramework/LessonEntity.cs | 54 +++++++------- API_SQLuedo/EntityFramework/NotepadEntity.cs | 60 +++++++-------- .../EntityFramework/ParagraphEntity.cs | 64 ++++++++-------- API_SQLuedo/EntityFramework/SolutionEntity.cs | 74 +++++++++---------- API_SQLuedo/EntityFramework/SuccessEntity.cs | 64 ++++++++-------- API_SQLuedo/EntityFramework/UserEntity.cs | 61 +++++++-------- 10 files changed, 254 insertions(+), 251 deletions(-) diff --git a/API_SQLuedo/EntityFramework/BlackListEntity.cs b/API_SQLuedo/EntityFramework/BlackListEntity.cs index bcc8c6d..e4b744b 100644 --- a/API_SQLuedo/EntityFramework/BlackListEntity.cs +++ b/API_SQLuedo/EntityFramework/BlackListEntity.cs @@ -1,22 +1,18 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; -namespace Entities +namespace Entities; + +[Table("BlackList")] +public class BlackListEntity { - public class BlackListEntity + [Key] + public string Email { get; set; } + public DateOnly ExpirationDate { get; set; } + public BlackListEntity() { } + public BlackListEntity(string email, DateOnly expirationDate) { - [Key] - public string Email { get; set; } - public DateOnly ExpirationDate { get; set; } - public BlackListEntity() { } - public BlackListEntity(string email, DateOnly expirationDate) - { - Email = email; - ExpirationDate = expirationDate; - } + Email = email; + ExpirationDate = expirationDate; } -} +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/ContentLessonEntity.cs b/API_SQLuedo/EntityFramework/ContentLessonEntity.cs index 414fef6..067cc39 100644 --- a/API_SQLuedo/EntityFramework/ContentLessonEntity.cs +++ b/API_SQLuedo/EntityFramework/ContentLessonEntity.cs @@ -1,24 +1,24 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace Entities +namespace Entities; + +[Table("ContentLesson")] +public class ContentLessonEntity { - public class ContentLessonEntity - { - [ForeignKey(nameof(Lesson))] - public int LessonId { get; set; } - public LessonEntity Lesson { get; set; } + [ForeignKey(nameof(Lesson))] + public int LessonId { get; set; } + public LessonEntity Lesson { get; set; } - [ForeignKey(nameof(Paragraph))] - public int LessonPartId { get; set; } - public ParagraphEntity Paragraph { get; set; } + [ForeignKey(nameof(Paragraph))] + public int LessonPartId { get; set; } + public ParagraphEntity Paragraph { get; set; } - public ContentLessonEntity(){} - public ContentLessonEntity(int lessonId, LessonEntity lesson, int lessonPartId, ParagraphEntity paragraph) - { - LessonId = lessonId; - Lesson = lesson; - LessonPartId = lessonPartId; - Paragraph = paragraph; - } + public ContentLessonEntity(){} + public ContentLessonEntity(int lessonId, LessonEntity lesson, int lessonPartId, ParagraphEntity paragraph) + { + LessonId = lessonId; + Lesson = lesson; + LessonPartId = lessonPartId; + Paragraph = paragraph; } -} +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/InquiryEntity.cs b/API_SQLuedo/EntityFramework/InquiryEntity.cs index e311db5..f930acf 100644 --- a/API_SQLuedo/EntityFramework/InquiryEntity.cs +++ b/API_SQLuedo/EntityFramework/InquiryEntity.cs @@ -1,4 +1,6 @@ -namespace Entities +using System.ComponentModel.DataAnnotations; + +namespace Entities { public class InquiryEntity { diff --git a/API_SQLuedo/EntityFramework/InquiryTableEntity.cs b/API_SQLuedo/EntityFramework/InquiryTableEntity.cs index bc3f0e0..c8798b9 100644 --- a/API_SQLuedo/EntityFramework/InquiryTableEntity.cs +++ b/API_SQLuedo/EntityFramework/InquiryTableEntity.cs @@ -1,37 +1,37 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace Entities +namespace Entities; + +[Table("InquiryTable")] +public class InquiryTableEntity { - public class InquiryTableEntity - { - [Key] - [ForeignKey(nameof(Owner))] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - [Required] - public int OwnerId { get; set; } - public InquiryEntity Owner { get; set; } - public string DatabaseName { get; set; } - public string ConnectionInfo { get; set; } + [Key] + [ForeignKey(nameof(Owner))] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Required] + public int OwnerId { get; set; } + public InquiryEntity Owner { get; set; } + public string DatabaseName { get; set; } + public string ConnectionInfo { get; set; } - public InquiryTableEntity() { } + public InquiryTableEntity() { } - public InquiryTableEntity(int inquiryId) - { - OwnerId = inquiryId; - } - public InquiryTableEntity(int inquiryId, string databaseName, string connectionInfo) - { - OwnerId = inquiryId; - DatabaseName = databaseName; - ConnectionInfo = connectionInfo; - } + public InquiryTableEntity(int inquiryId) + { + OwnerId = inquiryId; + } + public InquiryTableEntity(int inquiryId, string databaseName, string connectionInfo) + { + OwnerId = inquiryId; + DatabaseName = databaseName; + ConnectionInfo = connectionInfo; + } - public InquiryTableEntity(InquiryEntity owner, string databaseName, string connectionInfo) - { - Owner = owner; - DatabaseName = databaseName; - ConnectionInfo = connectionInfo; - } + public InquiryTableEntity(InquiryEntity owner, string databaseName, string connectionInfo) + { + Owner = owner; + DatabaseName = databaseName; + ConnectionInfo = connectionInfo; } } \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/LessonEntity.cs b/API_SQLuedo/EntityFramework/LessonEntity.cs index af3986b..2c345d3 100644 --- a/API_SQLuedo/EntityFramework/LessonEntity.cs +++ b/API_SQLuedo/EntityFramework/LessonEntity.cs @@ -1,31 +1,33 @@ -namespace Entities +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("Lesson")] +public class LessonEntity { - public class LessonEntity - { - public int Id { get; set; } - public string? Title { get; set; } - public string? LastPublisher { get; set; } - public DateOnly? LastEdit { get; set; } + public int Id { get; set; } + public string? Title { get; set; } + public string? LastPublisher { get; set; } + public DateOnly? LastEdit { get; set; } - public LessonEntity() { } + public LessonEntity() { } - public LessonEntity(int id) - { - Id = id; - } - public LessonEntity(int id, string title, string lastPublisher, DateOnly? lastEdit) - { - Id = id; - Title = title; - LastPublisher = lastPublisher; - LastEdit = lastEdit; - } + public LessonEntity(int id) + { + Id = id; + } + public LessonEntity(int id, string title, string lastPublisher, DateOnly? lastEdit) + { + Id = id; + Title = title; + LastPublisher = lastPublisher; + LastEdit = lastEdit; + } - public LessonEntity(string title, string lastPublisher, DateOnly? lastEdit) - { - Title = title; - LastPublisher = lastPublisher; - LastEdit = lastEdit; - } + public LessonEntity(string title, string lastPublisher, DateOnly? lastEdit) + { + Title = title; + LastPublisher = lastPublisher; + LastEdit = lastEdit; } -} +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/NotepadEntity.cs b/API_SQLuedo/EntityFramework/NotepadEntity.cs index 69226d2..0a3f9c9 100644 --- a/API_SQLuedo/EntityFramework/NotepadEntity.cs +++ b/API_SQLuedo/EntityFramework/NotepadEntity.cs @@ -1,38 +1,38 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace Entities +namespace Entities; + +[Table("Notepad")] +public class NotepadEntity { - public class NotepadEntity - { - public int Id { get; set; } + public int Id { get; set; } - [ForeignKey(nameof(User))] - public int UserId { get; set; } - public UserEntity User { get; set; } + [ForeignKey(nameof(User))] + public int UserId { get; set; } + public UserEntity User { get; set; } - [ForeignKey(nameof(Inquiry))] - public int InquiryId { get; set; } - public InquiryEntity Inquiry { get; set; } - public string Notes { get; set; } + [ForeignKey(nameof(Inquiry))] + public int InquiryId { get; set; } + public InquiryEntity Inquiry { get; set; } + public string Notes { get; set; } - public NotepadEntity() { } + public NotepadEntity() { } - public NotepadEntity(int id, int userId, UserEntity user, int inquiryId, InquiryEntity inquiry, string notes) - { - Id = id; - UserId = userId; - User = user; - InquiryId = inquiryId; - Inquiry = inquiry; - Notes = notes; - } - public NotepadEntity(int userId, UserEntity user, int inquiryId, InquiryEntity inquiry, string notes) - { - UserId = userId; - User = user; - InquiryId = inquiryId; - Inquiry = inquiry; - Notes = notes; - } + public NotepadEntity(int id, int userId, UserEntity user, int inquiryId, InquiryEntity inquiry, string notes) + { + Id = id; + UserId = userId; + User = user; + InquiryId = inquiryId; + Inquiry = inquiry; + Notes = notes; + } + public NotepadEntity(int userId, UserEntity user, int inquiryId, InquiryEntity inquiry, string notes) + { + UserId = userId; + User = user; + InquiryId = inquiryId; + Inquiry = inquiry; + Notes = notes; } -} +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/ParagraphEntity.cs b/API_SQLuedo/EntityFramework/ParagraphEntity.cs index 65bd2cb..4dc2277 100644 --- a/API_SQLuedo/EntityFramework/ParagraphEntity.cs +++ b/API_SQLuedo/EntityFramework/ParagraphEntity.cs @@ -1,38 +1,40 @@ -namespace Entities +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("Paragraph")] +public class ParagraphEntity { - public class ParagraphEntity - { - public int Id { get; set; } - public string Title { get; set; } - public string Content { get; set; } - public string Info { get; set; } - public string Query { get; set; } - public string Comment { get; set; } + public int Id { get; set; } + public string Title { get; set; } + public string Content { get; set; } + public string Info { get; set; } + public string Query { get; set; } + public string Comment { get; set; } - public ParagraphEntity() { } + public ParagraphEntity() { } - public ParagraphEntity(int id) - { - Id = id; - } + public ParagraphEntity(int id) + { + Id = id; + } - public ParagraphEntity(int id, string title, string content, string info, string query, string comment) - { - Id = id; - Title = title; - Content = content; - Info = info; - Query = query; - Comment = comment; - } - public ParagraphEntity(string title, string content, string info, string query, string comment) - { - Title = title; - Content = content; - Info = info; - Query = query; - Comment = comment; - } + public ParagraphEntity(int id, string title, string content, string info, string query, string comment) + { + Id = id; + Title = title; + Content = content; + Info = info; + Query = query; + Comment = comment; + } + public ParagraphEntity(string title, string content, string info, string query, string comment) + { + Title = title; + Content = content; + Info = info; + Query = query; + Comment = comment; } } \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/SolutionEntity.cs b/API_SQLuedo/EntityFramework/SolutionEntity.cs index fa15060..6c8dbdf 100644 --- a/API_SQLuedo/EntityFramework/SolutionEntity.cs +++ b/API_SQLuedo/EntityFramework/SolutionEntity.cs @@ -1,44 +1,44 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace Entities +namespace Entities; + +[Table("Solution")] +public class SolutionEntity { - public class SolutionEntity + [Key] + [ForeignKey(nameof(Owner))] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Required] + public int OwnerId { get; set; } + public InquiryEntity? 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 SolutionEntity() { } + public SolutionEntity(int ownerId) + { + OwnerId = ownerId; + } + public SolutionEntity(int ownerId, InquiryEntity? 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 SolutionEntity(InquiryEntity? owner, string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon, string explanation) { - [Key] - [ForeignKey(nameof(Owner))] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - [Required] - public int OwnerId { get; set; } - public InquiryEntity? 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 SolutionEntity() { } - public SolutionEntity(int ownerId) - { - OwnerId = ownerId; - } - public SolutionEntity(int ownerId, InquiryEntity? 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 SolutionEntity(InquiryEntity? owner, string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon, string explanation) - { - Owner = owner; - MurdererFirstName = murdererFirstName; - MurdererLastName = murdererLastName; - MurderPlace = murderPlace; - MurderWeapon = murderWeapon; - Explanation = explanation; - } + Owner = owner; + MurdererFirstName = murdererFirstName; + MurdererLastName = murdererLastName; + MurderPlace = murderPlace; + MurderWeapon = murderWeapon; + Explanation = explanation; } } \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/SuccessEntity.cs b/API_SQLuedo/EntityFramework/SuccessEntity.cs index 81f9e11..10f21a9 100644 --- a/API_SQLuedo/EntityFramework/SuccessEntity.cs +++ b/API_SQLuedo/EntityFramework/SuccessEntity.cs @@ -1,41 +1,41 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace Entities +namespace Entities; + +[Table("Success")] +public class SuccessEntity { - public class SuccessEntity - { - [ForeignKey(nameof(User))] - public int UserId { get; set; } - public UserEntity User { get; set; } + [ForeignKey(nameof(User))] + public int UserId { get; set; } + public UserEntity User { get; set; } - [ForeignKey(nameof(Inquiry))] - public int InquiryId { get; set; } - public InquiryEntity Inquiry { get; set; } - public bool IsFinished { get; set; } + [ForeignKey(nameof(Inquiry))] + public int InquiryId { get; set; } + public InquiryEntity Inquiry { get; set; } + public bool IsFinished { get; set; } - public SuccessEntity() { } + public SuccessEntity() { } - public SuccessEntity(int userId, UserEntity user, int inquiryId, InquiryEntity inquiry, bool isFinished) - { - UserId = userId; - User = user; - InquiryId = inquiryId; - Inquiry = inquiry; - IsFinished = isFinished; - } + public SuccessEntity(int userId, UserEntity user, int inquiryId, InquiryEntity inquiry, bool isFinished) + { + UserId = userId; + User = user; + InquiryId = inquiryId; + Inquiry = inquiry; + IsFinished = isFinished; + } - public SuccessEntity(int userId, int inquiryId, bool isFinished) - { - UserId = userId; - InquiryId = inquiryId; - IsFinished = isFinished; - } + public SuccessEntity(int userId, int inquiryId, bool isFinished) + { + UserId = userId; + InquiryId = inquiryId; + IsFinished = isFinished; + } - public SuccessEntity(UserEntity user, InquiryEntity inquiry, bool isFinished) - { - User = user; - Inquiry = inquiry; - IsFinished = isFinished; - } + public SuccessEntity(UserEntity user, InquiryEntity inquiry, bool isFinished) + { + User = user; + Inquiry = inquiry; + IsFinished = isFinished; } -} +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/UserEntity.cs b/API_SQLuedo/EntityFramework/UserEntity.cs index 52ed8f8..2d22110 100644 --- a/API_SQLuedo/EntityFramework/UserEntity.cs +++ b/API_SQLuedo/EntityFramework/UserEntity.cs @@ -1,38 +1,39 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace Entities +namespace Entities; + +[Table("User")] +public class UserEntity { - [Table("user")] - public class UserEntity - { - public int Id { get; set; } - public string Username { get; set; } - public string Password { get; set; } - public string Email { get; set; } - public bool IsAdmin { get; set; } + public int Id { get; set; } + public string Username { get; set; } + public string Password { get; set; } + public string Email { get; set; } + public bool IsAdmin { get; set; } - public UserEntity() { } + public UserEntity() + { + } - public UserEntity(int id) - { - Id = id; - } + public UserEntity(int id) + { + Id = id; + } - public UserEntity(int id, string username, string password, string email, bool isAdmin) - { - Id = id; - Username = username; - Password = password; - Email = email; - IsAdmin = isAdmin; - } + public UserEntity(int id, string username, string password, string email, bool isAdmin) + { + Id = id; + Username = username; + Password = password; + Email = email; + IsAdmin = isAdmin; + } - public UserEntity(string username, string password, string email, bool isAdmin) - { - Username = username; - Password = password; - Email = email; - IsAdmin = isAdmin; - } + public UserEntity(string username, string password, string email, bool isAdmin) + { + Username = username; + Password = password; + Email = email; + IsAdmin = isAdmin; } -} +} \ No newline at end of file From 1fc4affc8911bdaecd5551b2901bdcc6ae73de38 Mon Sep 17 00:00:00 2001 From: Nestisse Date: Tue, 5 Mar 2024 18:51:51 +0100 Subject: [PATCH 10/11] Modification du nom d'un projet --- .../DbDataManager.csproj} | 0 .../Service/InquiryDataService.cs | 23 +++++ .../DbDataManager/Service/UserDataService.cs | 90 ++++++++++++++++++ .../ModelToEntities/Mapper/BlackListMapper.cs | 39 -------- .../Mapper/ContentLessonMapper.cs | 34 ------- .../ModelToEntities/Mapper/InquiryMapper.cs | 39 -------- .../Mapper/InquiryTableMapper.cs | 39 -------- .../ModelToEntities/Mapper/LessonMapper.cs | 41 --------- .../ModelToEntities/Mapper/NotepadMapper.cs | 39 -------- .../ModelToEntities/Mapper/ParagraphMapper.cs | 38 -------- .../ModelToEntities/Mapper/SolutionMapper.cs | 38 -------- .../ModelToEntities/Mapper/SuccessMapper.cs | 39 -------- .../ModelToEntities/Mapper/UserMapper.cs | 38 -------- .../Service/InquiryDataService.cs | 23 ----- .../Service/UserDataService.cs | 92 ------------------- 15 files changed, 113 insertions(+), 499 deletions(-) rename API_SQLuedo/{ModelToEntities/ModelToEntities.csproj => DbDataManager/DbDataManager.csproj} (100%) create mode 100644 API_SQLuedo/DbDataManager/Service/InquiryDataService.cs create mode 100644 API_SQLuedo/DbDataManager/Service/UserDataService.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/BlackListMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/ContentLessonMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/InquiryMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/InquiryTableMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/LessonMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/NotepadMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/ParagraphMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/SolutionMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/SuccessMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs delete mode 100644 API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs delete mode 100644 API_SQLuedo/ModelToEntities/Service/UserDataService.cs diff --git a/API_SQLuedo/ModelToEntities/ModelToEntities.csproj b/API_SQLuedo/DbDataManager/DbDataManager.csproj similarity index 100% rename from API_SQLuedo/ModelToEntities/ModelToEntities.csproj rename to API_SQLuedo/DbDataManager/DbDataManager.csproj diff --git a/API_SQLuedo/DbDataManager/Service/InquiryDataService.cs b/API_SQLuedo/DbDataManager/Service/InquiryDataService.cs new file mode 100644 index 0000000..e57ca27 --- /dev/null +++ b/API_SQLuedo/DbDataManager/Service/InquiryDataService.cs @@ -0,0 +1,23 @@ +using Dto; +using Entities; +using Shared; + +namespace DbDataManager.Service; + +public class InquiryDataService : IInquiryService +{ + public IEnumerable GetInquiries(int page, int number) + { + throw new NotImplementedException(); + } + + public InquiryEntity GetInquiryById(int id) + { + throw new NotImplementedException(); + } + + public InquiryEntity GetInquiryByTitle(string title) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/API_SQLuedo/DbDataManager/Service/UserDataService.cs b/API_SQLuedo/DbDataManager/Service/UserDataService.cs new file mode 100644 index 0000000..e9d32ce --- /dev/null +++ b/API_SQLuedo/DbDataManager/Service/UserDataService.cs @@ -0,0 +1,90 @@ +using DbContextLib; +using Entities; +using Microsoft.EntityFrameworkCore; +using Shared; + +namespace DbDataManager.Service; + +public class UserDataService : IUserService +{ + private UserDbContext DbContext { get; set; } + + public UserDataService(UserDbContext context) + { + DbContext = context; + context.Database.EnsureCreated(); + } + + public UserEntity GetUserById(int id) + { + var userEntity = DbContext.Users.FirstOrDefault(u => u.Id == id); + if (userEntity == null) + { + throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(id)); + } + + return userEntity; + } + + public UserEntity GetUserByUsername(string username) + { + var userEntity = DbContext.Users.FirstOrDefault(u => u.Username == username); + if (userEntity == null) + { + throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(username)); + } + + return userEntity; + } + + public IEnumerable GetUsers(int page, int number) + { + return DbContext.Users.Skip((page - 1) * number).Take(number).ToList() + .Select(u => u); + } + + public bool DeleteUser(int id) + { + var userEntity = DbContext.Users.FirstOrDefault(u => u.Id == id); + if (userEntity == null) + { + return false; + } + + DbContext.Users.Remove(userEntity); + DbContext.SaveChangesAsync(); + return true; + } + + public UserEntity UpdateUser(int id, UserEntity user) + { + var updatingUser = DbContext.Users.FirstOrDefault(u => u.Id == id); + if (updatingUser == null) + { + throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(id)); + } + + updatingUser.Username = user.Username; + updatingUser.Password = user.Password; + updatingUser.Email = user.Email; + updatingUser.IsAdmin = user.IsAdmin; + // Permet d'indiquer en Db que l'entité a été modifiée. + DbContext.Entry(updatingUser).State = EntityState.Modified; + DbContext.SaveChangesAsync(); + return updatingUser; + } + + public UserEntity CreateUser(string username, string password, string email, bool isAdmin) + { + var newUserEntity = new UserEntity() + { + Username = username, + Password = password, + Email = email, + IsAdmin = isAdmin + }; + DbContext.Users.Add(newUserEntity); + DbContext.SaveChangesAsync(); + return newUserEntity; + } +} \ No newline at end of file diff --git a/API_SQLuedo/ModelToEntities/Mapper/BlackListMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/BlackListMapper.cs deleted file mode 100644 index 0eb2392..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/BlackListMapper.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class BlackListMapper - { - public static BlackListDTO FromModelToDTO(BlackList model) - { - return new BlackListDTO(model.Email, model.ExpirationDate); - } - - public static BlackListDTO FromEntityToDTO(BlackListEntity ent) - { - return new BlackListDTO(ent.Email, ent.ExpirationDate); - } - - public static BlackList FromDTOToModel(BlackListDTO dto) - { - return new BlackList(dto.Email, dto.ExpirationDate); - } - - public static BlackList FromEntityToModel(BlackListEntity ent) - { - return new BlackList(ent.Email, ent.ExpirationDate); - } - - public static BlackListEntity FromDTOToEntity(BlackListDTO dto) - { - return new BlackListEntity(dto.Email, dto.ExpirationDate); - } - - public static BlackListEntity FromModelToEntity(BlackList model) - { - return new BlackListEntity(model.Email, model.ExpirationDate); - } - } -} diff --git a/API_SQLuedo/ModelToEntities/Mapper/ContentLessonMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/ContentLessonMapper.cs deleted file mode 100644 index 1cff6d4..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/ContentLessonMapper.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class ContentLessonMapper - { - public static ContentLesson FromDTOToModel(this ContentLessonDTO dto) - { - return new ContentLesson(dto.LessonId, dto.LessonPartId); - } - - public static ContentLesson FromEntityToModel(this ContentLessonEntity ent) - { - return new ContentLesson(ent.LessonId, ent.LessonPartId); - } - - public static ContentLessonDTO FromModelToDTO(this ContentLesson les) - { - return new ContentLessonDTO(les.LessonId, les.LessonPartId); - } - - public static ContentLessonDTO FromEntityToDTO(this ContentLessonEntity ent) - { - return new ContentLessonDTO(ent.LessonId, ent.LessonPartId); - } - - public static ContentLessonEntity FromModelToEntity(this ContentLesson les) - { - return new ContentLessonEntity(les.LessonId,new LessonEntity(les.LessonId),les.LessonPartId,new ParagraphEntity(les.LessonPartId)); - } - } -} diff --git a/API_SQLuedo/ModelToEntities/Mapper/InquiryMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/InquiryMapper.cs deleted file mode 100644 index 5fc0fe4..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/InquiryMapper.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class InquiryMapper - { - public static Inquiry FromDTOToModel(this InquiryDTO InqDto) - { - return new Inquiry(InqDto.Id,InqDto.Title,InqDto.Description,InqDto.IsUser,InqDto.Database,InqDto.InquiryTable); - } - - public static Inquiry FromEntityToModel(this InquiryEntity InqEntity) - { - return new Inquiry(InqEntity.Id, InqEntity.Title, InqEntity.Description, InqEntity.IsUser, InqEntity.Database.OwnerId, InqEntity.InquiryTable.OwnerId); - } - - - public static InquiryEntity FromModelToEntity(this Inquiry Inq) - { - return new InquiryEntity(Inq.Id, Inq.Title, Inq.Description, Inq.IsUser,new InquiryTableEntity(Inq.Database),new SolutionEntity(Inq.InquiryTable)); - } - public static InquiryEntity FromDTOToEntity(this InquiryDTO InqDto) - { - return new InquiryEntity(InqDto.Id, InqDto.Title, InqDto.Description, InqDto.IsUser, new InquiryTableEntity(InqDto.Database), new SolutionEntity(InqDto.InquiryTable)); - } - public static InquiryDTO FromModelToDTO(this Inquiry Inq) - { - return new InquiryDTO(Inq.Id, Inq.Title, Inq.Description, Inq.IsUser, Inq.Database, Inq.InquiryTable); - } - - public static InquiryDTO FromEntityToDTO(this InquiryEntity InqEntity) - { - return new InquiryDTO(InqEntity.Id, InqEntity.Title, InqEntity.Description, InqEntity.IsUser, InqEntity.Database.OwnerId, InqEntity.InquiryTable.OwnerId); - - } - } -} diff --git a/API_SQLuedo/ModelToEntities/Mapper/InquiryTableMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/InquiryTableMapper.cs deleted file mode 100644 index 5f01925..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/InquiryTableMapper.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class InquiryTableMapper - { - public static InquiryTable FromDTOToModel(this InquiryTableDTO InqTDto) - { - return new InquiryTable(InqTDto.OwnerId, InqTDto.ConnectionInfo, InqTDto.DatabaseName); - } - - public static InquiryTable FromEntityToModel(this InquiryTableEntity InqTEntity) - { - return new InquiryTable(InqTEntity.OwnerId, InqTEntity.ConnectionInfo, InqTEntity.DatabaseName); - } - - public static InquiryTableDTO FromModelToDTO(this InquiryTable InqT) - { - return new InquiryTableDTO(InqT.OwnerId, InqT.DatabaseName, InqT.ConnectionInfo); - } - - public static InquiryTableDTO FromEntityToDTO(this InquiryTableEntity InqTEntity) - { - return new InquiryTableDTO(InqTEntity.OwnerId, InqTEntity.DatabaseName, InqTEntity.ConnectionInfo); - } - - public static InquiryTableEntity FromModelToEntity(this InquiryTable InqT) - { - return new InquiryTableEntity(InqT.OwnerId, InqT.DatabaseName, InqT.ConnectionInfo); - } - - public static InquiryTableEntity FromDTOToEntity(this InquiryTableDTO dto) - { - return new InquiryTableEntity(dto.OwnerId, dto.DatabaseName, dto.ConnectionInfo); - } - } -} diff --git a/API_SQLuedo/ModelToEntities/Mapper/LessonMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/LessonMapper.cs deleted file mode 100644 index 9b22858..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/LessonMapper.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class LessonMapper - { - - public static LessonDTO FromModelToDTO(Lesson model) - { - return new LessonDTO(model.Id, model.Title, model.LastPublisher, model.LastEdit); - } - - public static LessonDTO FromEntityToDTO(LessonEntity model) - { - return new LessonDTO(model.Id, model.Title, model.LastPublisher, model.LastEdit); - } - - public static LessonEntity FromModelToEntity(Lesson model) - { - return new LessonEntity(model.Id, model.Title, model.LastPublisher, model.LastEdit); - } - - public static LessonEntity FromDTOToEntity(LessonDTO dto) - { - return new LessonEntity(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit); - } - - public static Lesson FromDTOToModel(LessonDTO dto) - { - return new Lesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit); - } - - public static Lesson FromEntityToModel(LessonEntity entity) - { - return new Lesson(entity.Id, entity.Title, entity.LastPublisher, entity.LastEdit); - } - } -} - \ No newline at end of file diff --git a/API_SQLuedo/ModelToEntities/Mapper/NotepadMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/NotepadMapper.cs deleted file mode 100644 index ecb7013..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/NotepadMapper.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class NotepadMapper - { - public static Notepad FromDTOToModel(this NotepadDTO dto) - { - return new Notepad(dto.Id, dto.UserId, dto.InquiryId, dto.Notes); - } - - public static Notepad FromEntityToModel(this NotepadEntity ent) - { - return new Notepad(ent.Id, ent.UserId, ent.InquiryId, ent.Notes); - } - - public static NotepadDTO FromModelToDTO(this Notepad not) - { - return new NotepadDTO(not.Id, not.UserId, not.InquiryId, not.Notes); - } - - public static NotepadDTO FromEntityToDTO(this NotepadEntity ent) - { - return new NotepadDTO(ent.Id, ent.UserId, ent.InquiryId, ent.Notes); - } - - public static NotepadEntity FromDTOToEntity(this NotepadDTO dto) - { - return new NotepadEntity(dto.Id,new UserEntity(dto.UserId), dto.UserId, new InquiryEntity(dto.InquiryId), dto.Notes); - } - - public static NotepadEntity FromModelToEntity(this Notepad not) - { - return new NotepadEntity(not.Id, new UserEntity(not.UserId), not.UserId, new InquiryEntity(not.InquiryId), not.Notes); - } - } -} diff --git a/API_SQLuedo/ModelToEntities/Mapper/ParagraphMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/ParagraphMapper.cs deleted file mode 100644 index 72ddb9c..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/ParagraphMapper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class ParagraphMapper - { - public static Paragraph FromDTOToModel(ParagraphDTO dto) - { - return new Paragraph(dto.Id,dto.Title,dto.Content,dto.Info,dto.Query,dto.Comment); - } - - public static Paragraph FromEntityToModel(ParagraphEntity model) - { - return new Paragraph(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment); - } - public static ParagraphDTO FromEntityToDTO(ParagraphEntity model) - { - return new ParagraphDTO(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment); - } - - public static ParagraphDTO FromModelToDTO(Paragraph model) - { - return new ParagraphDTO(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment); - } - - public static ParagraphEntity FromDTOToEntity(ParagraphDTO dto) - { - return new ParagraphEntity(dto.Id, dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment); - } - - public static Paragraph FromModelToEntity(Paragraph model) - { - return new Paragraph(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment); - } - } -} diff --git a/API_SQLuedo/ModelToEntities/Mapper/SolutionMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/SolutionMapper.cs deleted file mode 100644 index cad2024..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/SolutionMapper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class SolutionMapper - { - public static Solution FromDTOToModel(this SolutionDTO dto) - { - return new Solution(dto.OwnerId,dto.MurdererFirstName,dto.MurdererLastName,dto.MurderPlace,dto.MurderWeapon,dto.Explanation); - } - - public static Solution FromEntityToModel(this SolutionEntity entity) - { - return new Solution(entity.OwnerId, entity.MurdererFirstName, entity.MurdererLastName, entity.MurderPlace, entity.MurderWeapon, entity.Explanation); - } - public static SolutionDTO FromModelToDTO(this Solution model) - { - return new SolutionDTO(model.OwnerId, model.MurdererFirstName, model.MurdererLastName, model.MurderPlace, model.MurderWeapon, model.Explanation); - } - - public static SolutionDTO FromEntityToDTO(this SolutionEntity entity) - { - return new SolutionDTO(entity.OwnerId, entity.MurdererFirstName, entity.MurdererLastName, entity.MurderPlace, entity.MurderWeapon, entity.Explanation); - } - - public static SolutionEntity FromModelToEntity(this Solution model) - { - return new SolutionEntity(model.OwnerId, new InquiryEntity(model.OwnerId), model.MurdererFirstName, model.MurdererLastName, model.MurderPlace, model.MurderWeapon, model.Explanation); - } - - public static SolutionEntity FromDTOToEntity(this SolutionDTO dto) - { - return new SolutionEntity(dto.OwnerId, new InquiryEntity(dto.OwnerId), dto.MurdererFirstName, dto.MurdererLastName, dto.MurderPlace, dto.MurderWeapon, dto.Explanation); - } - } -} diff --git a/API_SQLuedo/ModelToEntities/Mapper/SuccessMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/SuccessMapper.cs deleted file mode 100644 index 935689a..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/SuccessMapper.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities -{ - public static class SuccessMapper - { - public static Success FromDTOToModel(this SuccessDTO dto) - { - return new Success(dto.UserId, dto.InquiryId, dto.IsFinished); - } - - public static Success FromEntityToModel(this SuccessEntity ent) - { - return new Success(ent.UserId, ent.InquiryId, ent.IsFinished); - } - - public static SuccessDTO FromModelToDTO(this Success suc) - { - return new SuccessDTO(suc.UserId, suc.InquiryId, suc.IsFinished); - } - - public static SuccessDTO FromEntityToDTO(this SuccessEntity ent) - { - return new SuccessDTO(ent.UserId, ent.InquiryId, ent.IsFinished); - } - - public static SuccessEntity FromDTOToEntity(this SuccessDTO dto) - { - return new SuccessEntity(dto.UserId,new UserEntity(dto.UserId),dto.InquiryId,new InquiryEntity(dto.InquiryId),dto.IsFinished); - } - - public static SuccessEntity FromModelToEntity(this Success suc) - { - return new SuccessEntity(suc.UserId, new UserEntity(suc.UserId), suc.InquiryId, new InquiryEntity(suc.InquiryId), suc.IsFinished); - } - } -} diff --git a/API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs deleted file mode 100644 index c570909..0000000 --- a/API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Dto; -using Entities; -using ModelToEntities.Business; - -namespace ModelToEntities.Service -{ - public static class UserMapper - { - public static User FromDTOToModel(this UserDTO dto) - { - 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) - { - return new UserDTO(user.Id, user.Username, user.Password, user.Email, user.IsAdmin); - } - - public static UserEntity FromModelToEntity(this User user) - { - return new UserEntity(user.Id, user.Username, user.Password, user.Email, user.IsAdmin); - } - - } -} diff --git a/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs b/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs deleted file mode 100644 index 4b76513..0000000 --- a/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Dto; -using ModelToEntities.Business; -using Shared; - -namespace ModelToEntities.Service; - -public class InquiryDataService : IInquiryService -{ - public IEnumerable GetInquiries(int page, int number) - { - throw new NotImplementedException(); - } - - public InquiryDTO GetInquiryById(int id) - { - throw new NotImplementedException(); - } - - public InquiryDTO GetInquiryByTitle(string title) - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/API_SQLuedo/ModelToEntities/Service/UserDataService.cs b/API_SQLuedo/ModelToEntities/Service/UserDataService.cs deleted file mode 100644 index 1ad41d2..0000000 --- a/API_SQLuedo/ModelToEntities/Service/UserDataService.cs +++ /dev/null @@ -1,92 +0,0 @@ -using DbContextLib; -using Dto; -using Entities; -using Microsoft.EntityFrameworkCore; -using Shared; - -namespace ModelToEntities.Service -{ - public class UserDataService : IUserService - { - private UserDbContext DbContext { get; set; } - - public UserDataService(UserDbContext context) - { - DbContext = context; - context.Database.EnsureCreated(); - } - - public UserDTO GetUserById(int id) - { - var userEntity = DbContext.Users.FirstOrDefault(u => u.Id == id); - if (userEntity == null) - { - throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(id)); - } - - return userEntity.FromEntityToModel().FromModelToDTO(); - } - - public UserDTO GetUserByUsername(string username) - { - var userEntity = DbContext.Users.FirstOrDefault(u => u.Username == username); - if (userEntity == null) - { - throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(username)); - } - - return userEntity.FromEntityToModel().FromModelToDTO(); - } - - public IEnumerable GetUsers(int page, int number) - { - return DbContext.Users.Skip((page - 1) * number).Take(number).ToList() - .Select(u => u.FromEntityToModel().FromModelToDTO()); - } - - public bool DeleteUser(int id) - { - var userEntity = DbContext.Users.FirstOrDefault(u => u.Id == id); - if (userEntity == null) - { - return false; - } - - DbContext.Users.Remove(userEntity); - DbContext.SaveChangesAsync(); - return true; - } - - public UserDTO UpdateUser(int id, UserDTO user) - { - var updatingUser = DbContext.Users.FirstOrDefault(u => u.Id == id); - if (updatingUser == null) - { - throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(id)); - } - - updatingUser.Username = user.Username; - updatingUser.Password = user.Password; - updatingUser.Email = user.Email; - updatingUser.IsAdmin = user.IsAdmin; - // Permet d'indiquer en Db que l'entité a été modifiée. - DbContext.Entry(updatingUser).State = EntityState.Modified; - DbContext.SaveChangesAsync(); - return updatingUser.FromEntityToModel().FromModelToDTO(); - } - - public UserDTO CreateUser(string username, string password, string email, bool isAdmin) - { - var newUserEntity = new UserEntity() - { - Username = username, - Password = password, - Email = email, - IsAdmin = isAdmin - }; - DbContext.Users.Add(newUserEntity); - DbContext.SaveChangesAsync(); - return newUserEntity.FromEntityToDTO(); - } - } -} \ No newline at end of file From 11d970cd8841e123ca59aba9ebaa1e6a29b7c396 Mon Sep 17 00:00:00 2001 From: Nestisse Date: Tue, 5 Mar 2024 18:52:32 +0100 Subject: [PATCH 11/11] =?UTF-8?q?Modification=20de=20la=20localisation=20d?= =?UTF-8?q?es=20mapper=20et=20suppression=20des=20d=C3=A9pendances=20circu?= =?UTF-8?q?laires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_SQLuedo/API/API.csproj | 3 +- API_SQLuedo/API/Controllers/UserController.cs | 4 +- API_SQLuedo/API/Program.cs | 7 +-- .../API/Service/InquiryDataServiceAPI.cs | 14 ++++-- API_SQLuedo/API/Service/UserDataServiceAPI.cs | 19 +++++--- API_SQLuedo/API_SQLuedo.sln | 2 +- API_SQLuedo/DbContextLib/UserDbContext.cs | 2 +- API_SQLuedo/Shared/Mapper/BlackListMapper.cs | 38 ++++++++++++++++ .../Shared/Mapper/ContentLessonMapper.cs | 34 ++++++++++++++ API_SQLuedo/Shared/Mapper/InquiryMapper.cs | 44 +++++++++++++++++++ .../Shared/Mapper/InquiryTableMapper.cs | 38 ++++++++++++++++ API_SQLuedo/Shared/Mapper/LessonMapper.cs | 38 ++++++++++++++++ API_SQLuedo/Shared/Mapper/NotepadMapper.cs | 40 +++++++++++++++++ API_SQLuedo/Shared/Mapper/ParagraphMapper.cs | 38 ++++++++++++++++ API_SQLuedo/Shared/Mapper/SolutionMapper.cs | 44 +++++++++++++++++++ API_SQLuedo/Shared/Mapper/SuccessMapper.cs | 40 +++++++++++++++++ API_SQLuedo/Shared/Mapper/UserMapper.cs | 38 ++++++++++++++++ API_SQLuedo/Shared/Shared.csproj | 6 +++ .../StubbedContextLib.csproj | 7 +++ API_SQLuedo/TestConsoleAPI/Program.cs | 3 +- .../TestConsoleAPI/TestConsoleAPI.csproj | 2 +- 21 files changed, 439 insertions(+), 22 deletions(-) create mode 100644 API_SQLuedo/Shared/Mapper/BlackListMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/ContentLessonMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/InquiryMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/InquiryTableMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/LessonMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/NotepadMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/ParagraphMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/SolutionMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/SuccessMapper.cs create mode 100644 API_SQLuedo/Shared/Mapper/UserMapper.cs diff --git a/API_SQLuedo/API/API.csproj b/API_SQLuedo/API/API.csproj index 7d09073..e9ccb98 100644 --- a/API_SQLuedo/API/API.csproj +++ b/API_SQLuedo/API/API.csproj @@ -27,8 +27,9 @@ - + + diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index 612d0ff..9596304 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -1,8 +1,6 @@ -using API.Service; -using Dto; +using Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using ModelToEntities.Service; using Shared; namespace API.Controllers diff --git a/API_SQLuedo/API/Program.cs b/API_SQLuedo/API/Program.cs index 2f26e29..5f9663c 100644 --- a/API_SQLuedo/API/Program.cs +++ b/API_SQLuedo/API/Program.cs @@ -1,12 +1,13 @@ using API; using API.Service; using DbContextLib; +using DbDataManager.Service; using Dto; +using Entities; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; -using ModelToEntities.Service; using Shared; var builder = WebApplication.CreateBuilder(args); @@ -17,9 +18,9 @@ builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddScoped, UserDataService>(); +builder.Services.AddScoped, UserDataService>(); builder.Services.AddScoped, UserDataServiceApi>(); -builder.Services.AddScoped, InquiryDataService>(); +builder.Services.AddScoped, InquiryDataService>(); builder.Services.AddScoped, InquiryDataServiceApi>(); builder.Services.AddDbContext(); builder.Services.AddDbContext(options => options.UseInMemoryDatabase("appDb")); diff --git a/API_SQLuedo/API/Service/InquiryDataServiceAPI.cs b/API_SQLuedo/API/Service/InquiryDataServiceAPI.cs index 90eb3e7..68a2c1a 100644 --- a/API_SQLuedo/API/Service/InquiryDataServiceAPI.cs +++ b/API_SQLuedo/API/Service/InquiryDataServiceAPI.cs @@ -1,13 +1,19 @@ using Dto; +using Entities; using Shared; +using Shared.Mapper; namespace API.Service; -public class InquiryDataServiceApi(IInquiryService inquiryService) : IInquiryService +public class InquiryDataServiceApi(IInquiryService inquiryService) : IInquiryService { - public IEnumerable GetInquiries(int page, int number) => inquiryService.GetInquiries(page, number); + public IEnumerable GetInquiries(int page, int number) + { + var inquiries = inquiryService.GetInquiries(page, number); + return inquiries.Select(i => i.FromEntityToDTO()).ToList(); + } - public InquiryDTO GetInquiryById(int id) => inquiryService.GetInquiryById(id); + public InquiryDTO GetInquiryById(int id) => inquiryService.GetInquiryById(id).FromEntityToDTO(); - public InquiryDTO GetInquiryByTitle(string title) => inquiryService.GetInquiryByTitle(title); + public InquiryDTO GetInquiryByTitle(string title) => inquiryService.GetInquiryByTitle(title).FromEntityToDTO(); } \ No newline at end of file diff --git a/API_SQLuedo/API/Service/UserDataServiceAPI.cs b/API_SQLuedo/API/Service/UserDataServiceAPI.cs index 66013dd..a4a6dca 100644 --- a/API_SQLuedo/API/Service/UserDataServiceAPI.cs +++ b/API_SQLuedo/API/Service/UserDataServiceAPI.cs @@ -1,20 +1,27 @@ using Dto; +using Entities; using Shared; +using Shared.Mapper; namespace API.Service; -public class UserDataServiceApi(IUserService userService) : IUserService +public class UserDataServiceApi(IUserService userService) : IUserService { - public IEnumerable GetUsers(int page, int number) => userService.GetUsers(page, number); + public IEnumerable GetUsers(int page, int number) + { + var usersEntities = userService.GetUsers(page, number); + return usersEntities.Select(e => e.FromEntityToDTO()).ToList(); + } - public UserDTO GetUserById(int id) => userService.GetUserById(id); + public UserDTO GetUserById(int id) => userService.GetUserById(id).FromEntityToDTO(); - public UserDTO GetUserByUsername(string username) => userService.GetUserByUsername(username); + public UserDTO GetUserByUsername(string username) => userService.GetUserByUsername(username).FromEntityToDTO(); public bool DeleteUser(int id) => userService.DeleteUser(id); - public UserDTO UpdateUser(int id, UserDTO user) => userService.UpdateUser(id, user); + public UserDTO UpdateUser(int id, UserDTO user) => + userService.UpdateUser(id, user.FromDTOToEntity()).FromEntityToDTO(); public UserDTO CreateUser(string username, string password, string email, bool isAdmin) => - userService.CreateUser(username, password, email, isAdmin); + userService.CreateUser(username, password, email, isAdmin).FromEntityToDTO(); } \ No newline at end of file diff --git a/API_SQLuedo/API_SQLuedo.sln b/API_SQLuedo/API_SQLuedo.sln index c6c08b5..61850b6 100644 --- a/API_SQLuedo/API_SQLuedo.sln +++ b/API_SQLuedo/API_SQLuedo.sln @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{6 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "EntityFramework\Entities.csproj", "{6D079CDA-C000-4833-98A0-D07D153EA264}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelToEntities", "ModelToEntities\ModelToEntities.csproj", "{ADCC427D-A3CD-431C-A90B-F9369C4584E8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbDataManager", "DbDataManager\DbDataManager.csproj", "{ADCC427D-A3CD-431C-A90B-F9369C4584E8}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{17025B90-8B2A-49E9-97D3-1A84A208DF50}" EndProject diff --git a/API_SQLuedo/DbContextLib/UserDbContext.cs b/API_SQLuedo/DbContextLib/UserDbContext.cs index a3956bb..8be1c6f 100644 --- a/API_SQLuedo/DbContextLib/UserDbContext.cs +++ b/API_SQLuedo/DbContextLib/UserDbContext.cs @@ -29,11 +29,11 @@ namespace DbContextLib protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().ToTable("user"); modelBuilder.Entity().HasKey(c => c.LessonId); modelBuilder.Entity().HasKey(c => c.LessonPartId); modelBuilder.Entity().HasKey(s => s.UserId); modelBuilder.Entity().HasKey(s => s.InquiryId); + modelBuilder.Entity().HasKey(s => s.Id); base.OnModelCreating(modelBuilder); } } diff --git a/API_SQLuedo/Shared/Mapper/BlackListMapper.cs b/API_SQLuedo/Shared/Mapper/BlackListMapper.cs new file mode 100644 index 0000000..945d823 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/BlackListMapper.cs @@ -0,0 +1,38 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class BlackListMapper +{ + public static BlackListDTO FromModelToDTO(BlackList model) + { + return new BlackListDTO(model.Email, model.ExpirationDate); + } + + public static BlackListDTO FromEntityToDTO(BlackListEntity ent) + { + return new BlackListDTO(ent.Email, ent.ExpirationDate); + } + + public static BlackList FromDTOToModel(BlackListDTO dto) + { + return new BlackList(dto.Email, dto.ExpirationDate); + } + + public static BlackList FromEntityToModel(BlackListEntity ent) + { + return new BlackList(ent.Email, ent.ExpirationDate); + } + + public static BlackListEntity FromDTOToEntity(BlackListDTO dto) + { + return new BlackListEntity(dto.Email, dto.ExpirationDate); + } + + public static BlackListEntity FromModelToEntity(BlackList model) + { + return new BlackListEntity(model.Email, model.ExpirationDate); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/ContentLessonMapper.cs b/API_SQLuedo/Shared/Mapper/ContentLessonMapper.cs new file mode 100644 index 0000000..1feb9a1 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/ContentLessonMapper.cs @@ -0,0 +1,34 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class ContentLessonMapper +{ + public static ContentLesson FromDTOToModel(this ContentLessonDTO dto) + { + return new ContentLesson(dto.LessonId, dto.LessonPartId); + } + + public static ContentLesson FromEntityToModel(this ContentLessonEntity ent) + { + return new ContentLesson(ent.LessonId, ent.LessonPartId); + } + + public static ContentLessonDTO FromModelToDTO(this ContentLesson les) + { + return new ContentLessonDTO(les.LessonId, les.LessonPartId); + } + + public static ContentLessonDTO FromEntityToDTO(this ContentLessonEntity ent) + { + return new ContentLessonDTO(ent.LessonId, ent.LessonPartId); + } + + public static ContentLessonEntity FromModelToEntity(this ContentLesson les) + { + return new ContentLessonEntity(les.LessonId, new LessonEntity(les.LessonId), les.LessonPartId, + new ParagraphEntity(les.LessonPartId)); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/InquiryMapper.cs b/API_SQLuedo/Shared/Mapper/InquiryMapper.cs new file mode 100644 index 0000000..7ade449 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/InquiryMapper.cs @@ -0,0 +1,44 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class InquiryMapper +{ + public static Inquiry FromDTOToModel(this InquiryDTO InqDto) + { + return new Inquiry(InqDto.Id, InqDto.Title, InqDto.Description, InqDto.IsUser, InqDto.Database, + InqDto.InquiryTable); + } + + public static Inquiry FromEntityToModel(this InquiryEntity InqEntity) + { + return new Inquiry(InqEntity.Id, InqEntity.Title, InqEntity.Description, InqEntity.IsUser, + InqEntity.Database.OwnerId, InqEntity.InquiryTable.OwnerId); + } + + + public static InquiryEntity FromModelToEntity(this Inquiry Inq) + { + return new InquiryEntity(Inq.Id, Inq.Title, Inq.Description, Inq.IsUser, new InquiryTableEntity(Inq.Database), + new SolutionEntity(Inq.InquiryTable)); + } + + public static InquiryEntity FromDTOToEntity(this InquiryDTO InqDto) + { + return new InquiryEntity(InqDto.Id, InqDto.Title, InqDto.Description, InqDto.IsUser, + new InquiryTableEntity(InqDto.Database), new SolutionEntity(InqDto.InquiryTable)); + } + + public static InquiryDTO FromModelToDTO(this Inquiry Inq) + { + return new InquiryDTO(Inq.Id, Inq.Title, Inq.Description, Inq.IsUser, Inq.Database, Inq.InquiryTable); + } + + public static InquiryDTO FromEntityToDTO(this InquiryEntity InqEntity) + { + return new InquiryDTO(InqEntity.Id, InqEntity.Title, InqEntity.Description, InqEntity.IsUser, + InqEntity.Database.OwnerId, InqEntity.InquiryTable.OwnerId); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/InquiryTableMapper.cs b/API_SQLuedo/Shared/Mapper/InquiryTableMapper.cs new file mode 100644 index 0000000..d5048a9 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/InquiryTableMapper.cs @@ -0,0 +1,38 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class InquiryTableMapper +{ + public static InquiryTable FromDTOToModel(this InquiryTableDTO InqTDto) + { + return new InquiryTable(InqTDto.OwnerId, InqTDto.ConnectionInfo, InqTDto.DatabaseName); + } + + public static InquiryTable FromEntityToModel(this InquiryTableEntity InqTEntity) + { + return new InquiryTable(InqTEntity.OwnerId, InqTEntity.ConnectionInfo, InqTEntity.DatabaseName); + } + + public static InquiryTableDTO FromModelToDTO(this InquiryTable InqT) + { + return new InquiryTableDTO(InqT.OwnerId, InqT.DatabaseName, InqT.ConnectionInfo); + } + + public static InquiryTableDTO FromEntityToDTO(this InquiryTableEntity InqTEntity) + { + return new InquiryTableDTO(InqTEntity.OwnerId, InqTEntity.DatabaseName, InqTEntity.ConnectionInfo); + } + + public static InquiryTableEntity FromModelToEntity(this InquiryTable InqT) + { + return new InquiryTableEntity(InqT.OwnerId, InqT.DatabaseName, InqT.ConnectionInfo); + } + + public static InquiryTableEntity FromDTOToEntity(this InquiryTableDTO dto) + { + return new InquiryTableEntity(dto.OwnerId, dto.DatabaseName, dto.ConnectionInfo); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/LessonMapper.cs b/API_SQLuedo/Shared/Mapper/LessonMapper.cs new file mode 100644 index 0000000..9edf99f --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/LessonMapper.cs @@ -0,0 +1,38 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class LessonMapper +{ + public static LessonDTO FromModelToDTO(Lesson model) + { + return new LessonDTO(model.Id, model.Title, model.LastPublisher, model.LastEdit); + } + + public static LessonDTO FromEntityToDTO(LessonEntity model) + { + return new LessonDTO(model.Id, model.Title, model.LastPublisher, model.LastEdit); + } + + public static LessonEntity FromModelToEntity(Lesson model) + { + return new LessonEntity(model.Id, model.Title, model.LastPublisher, model.LastEdit); + } + + public static LessonEntity FromDTOToEntity(LessonDTO dto) + { + return new LessonEntity(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit); + } + + public static Lesson FromDTOToModel(LessonDTO dto) + { + return new Lesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit); + } + + public static Lesson FromEntityToModel(LessonEntity entity) + { + return new Lesson(entity.Id, entity.Title, entity.LastPublisher, entity.LastEdit); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/NotepadMapper.cs b/API_SQLuedo/Shared/Mapper/NotepadMapper.cs new file mode 100644 index 0000000..ba8aa08 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/NotepadMapper.cs @@ -0,0 +1,40 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class NotepadMapper +{ + public static Notepad FromDTOToModel(this NotepadDTO dto) + { + return new Notepad(dto.Id, dto.UserId, dto.InquiryId, dto.Notes); + } + + public static Notepad FromEntityToModel(this NotepadEntity ent) + { + return new Notepad(ent.Id, ent.UserId, ent.InquiryId, ent.Notes); + } + + public static NotepadDTO FromModelToDTO(this Notepad not) + { + return new NotepadDTO(not.Id, not.UserId, not.InquiryId, not.Notes); + } + + public static NotepadDTO FromEntityToDTO(this NotepadEntity ent) + { + return new NotepadDTO(ent.Id, ent.UserId, ent.InquiryId, ent.Notes); + } + + public static NotepadEntity FromDTOToEntity(this NotepadDTO dto) + { + return new NotepadEntity(dto.Id, new UserEntity(dto.UserId), dto.UserId, new InquiryEntity(dto.InquiryId), + dto.Notes); + } + + public static NotepadEntity FromModelToEntity(this Notepad not) + { + return new NotepadEntity(not.Id, new UserEntity(not.UserId), not.UserId, new InquiryEntity(not.InquiryId), + not.Notes); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/ParagraphMapper.cs b/API_SQLuedo/Shared/Mapper/ParagraphMapper.cs new file mode 100644 index 0000000..0afa24d --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/ParagraphMapper.cs @@ -0,0 +1,38 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class ParagraphMapper +{ + public static Paragraph FromDTOToModel(ParagraphDTO dto) + { + return new Paragraph(dto.Id, dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment); + } + + public static Paragraph FromEntityToModel(ParagraphEntity model) + { + return new Paragraph(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment); + } + + public static ParagraphDTO FromEntityToDTO(ParagraphEntity model) + { + return new ParagraphDTO(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment); + } + + public static ParagraphDTO FromModelToDTO(Paragraph model) + { + return new ParagraphDTO(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment); + } + + public static ParagraphEntity FromDTOToEntity(ParagraphDTO dto) + { + return new ParagraphEntity(dto.Id, dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment); + } + + public static Paragraph FromModelToEntity(Paragraph model) + { + return new Paragraph(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/SolutionMapper.cs b/API_SQLuedo/Shared/Mapper/SolutionMapper.cs new file mode 100644 index 0000000..4d99120 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/SolutionMapper.cs @@ -0,0 +1,44 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class SolutionMapper +{ + public static Solution FromDTOToModel(this SolutionDTO dto) + { + return new Solution(dto.OwnerId, dto.MurdererFirstName, dto.MurdererLastName, dto.MurderPlace, dto.MurderWeapon, + dto.Explanation); + } + + public static Solution FromEntityToModel(this SolutionEntity entity) + { + return new Solution(entity.OwnerId, entity.MurdererFirstName, entity.MurdererLastName, entity.MurderPlace, + entity.MurderWeapon, entity.Explanation); + } + + public static SolutionDTO FromModelToDTO(this Solution model) + { + return new SolutionDTO(model.OwnerId, model.MurdererFirstName, model.MurdererLastName, model.MurderPlace, + model.MurderWeapon, model.Explanation); + } + + public static SolutionDTO FromEntityToDTO(this SolutionEntity entity) + { + return new SolutionDTO(entity.OwnerId, entity.MurdererFirstName, entity.MurdererLastName, entity.MurderPlace, + entity.MurderWeapon, entity.Explanation); + } + + public static SolutionEntity FromModelToEntity(this Solution model) + { + return new SolutionEntity(model.OwnerId, new InquiryEntity(model.OwnerId), model.MurdererFirstName, + model.MurdererLastName, model.MurderPlace, model.MurderWeapon, model.Explanation); + } + + public static SolutionEntity FromDTOToEntity(this SolutionDTO dto) + { + return new SolutionEntity(dto.OwnerId, new InquiryEntity(dto.OwnerId), dto.MurdererFirstName, + dto.MurdererLastName, dto.MurderPlace, dto.MurderWeapon, dto.Explanation); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/SuccessMapper.cs b/API_SQLuedo/Shared/Mapper/SuccessMapper.cs new file mode 100644 index 0000000..a6d0261 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/SuccessMapper.cs @@ -0,0 +1,40 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class SuccessMapper +{ + public static Success FromDTOToModel(this SuccessDTO dto) + { + return new Success(dto.UserId, dto.InquiryId, dto.IsFinished); + } + + public static Success FromEntityToModel(this SuccessEntity ent) + { + return new Success(ent.UserId, ent.InquiryId, ent.IsFinished); + } + + public static SuccessDTO FromModelToDTO(this Success suc) + { + return new SuccessDTO(suc.UserId, suc.InquiryId, suc.IsFinished); + } + + public static SuccessDTO FromEntityToDTO(this SuccessEntity ent) + { + return new SuccessDTO(ent.UserId, ent.InquiryId, ent.IsFinished); + } + + public static SuccessEntity FromDTOToEntity(this SuccessDTO dto) + { + return new SuccessEntity(dto.UserId, new UserEntity(dto.UserId), dto.InquiryId, + new InquiryEntity(dto.InquiryId), dto.IsFinished); + } + + public static SuccessEntity FromModelToEntity(this Success suc) + { + return new SuccessEntity(suc.UserId, new UserEntity(suc.UserId), suc.InquiryId, + new InquiryEntity(suc.InquiryId), suc.IsFinished); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/UserMapper.cs b/API_SQLuedo/Shared/Mapper/UserMapper.cs new file mode 100644 index 0000000..a9d4350 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/UserMapper.cs @@ -0,0 +1,38 @@ +using Dto; +using Entities; +using ModelToEntities.Business; + +namespace Shared.Mapper; + +public static class UserMapper +{ + public static User FromDTOToModel(this UserDTO dto) + { + 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) + { + return new UserDTO(user.Id, user.Username, user.Password, user.Email, user.IsAdmin); + } + + public static UserEntity FromModelToEntity(this User user) + { + return new UserEntity(user.Id, user.Username, user.Password, user.Email, user.IsAdmin); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Shared.csproj b/API_SQLuedo/Shared/Shared.csproj index 3a63532..7db1a18 100644 --- a/API_SQLuedo/Shared/Shared.csproj +++ b/API_SQLuedo/Shared/Shared.csproj @@ -6,4 +6,10 @@ enable + + + + + + diff --git a/API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj b/API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj index 19a69a6..c87b24a 100644 --- a/API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj +++ b/API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj @@ -10,4 +10,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/API_SQLuedo/TestConsoleAPI/Program.cs b/API_SQLuedo/TestConsoleAPI/Program.cs index 50fd3a5..cbe8925 100644 --- a/API_SQLuedo/TestConsoleAPI/Program.cs +++ b/API_SQLuedo/TestConsoleAPI/Program.cs @@ -3,13 +3,12 @@ using API.Controllers; using API.Service; using DbContextLib; +using DbDataManager.Service; using Dto; using Microsoft.AspNetCore.Mvc; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using ModelToEntities.Service; var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); diff --git a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj index 801193b..fa9db2a 100644 --- a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj +++ b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj @@ -14,7 +14,7 @@ - +