diff --git a/API_SQLuedo/API/API.csproj b/API_SQLuedo/API/API.csproj index 6a516ab..effc567 100644 --- a/API_SQLuedo/API/API.csproj +++ b/API_SQLuedo/API/API.csproj @@ -26,7 +26,11 @@ - + + + + + diff --git a/API_SQLuedo/API/Controllers/InquiriesController.cs b/API_SQLuedo/API/Controllers/InquiriesController.cs index e42d14e..9e4eacd 100644 --- a/API_SQLuedo/API/Controllers/InquiriesController.cs +++ b/API_SQLuedo/API/Controllers/InquiriesController.cs @@ -1,46 +1,52 @@ -using Microsoft.AspNetCore.Authorization; +using Dto; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Model.DTO; -using Services; +using Shared; namespace API.Controllers { [Route("api/[controller]")] [Authorize] [ApiController] - public class InquiriesController : Controller + public class InquiriesController() + : ControllerBase { - private IDataService _inquiryDataService; + private readonly IInquiryService _inquiryService; + private readonly ILogger _logger; - private readonly ILogger _logger; - - public InquiriesController(IDataService inquiryDataService) + public InquiriesController(IInquiryService inquiryService, ILogger logger) : this() { - _inquiryDataService = inquiryDataService; + _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 = _inquiryDataService.GetInquiries(page, number).Count(); - if (nbInquiry == 0) + { + var nbInquiry = _inquiryService.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(_inquiryService.GetInquiries(page, number)); } [HttpGet("inquiry/id/{id}")] + [ProducesResponseType(typeof(InquiryDTO), 200)] + [ProducesResponseType(typeof(string), 404)] 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) + return Ok(_inquiryService.GetInquiryById(id)); + } + catch (ArgumentException) { _logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id); return NotFound(); @@ -48,14 +54,16 @@ namespace API.Controllers } [HttpGet("inquiry/title/{title}")] + [ProducesResponseType(typeof(InquiryDTO), 200)] + [ProducesResponseType(typeof(string), 404)] 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) + return Ok(_inquiryService.GetInquiryByTitle(title)); + } + 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 47b8b00..5809f53 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -1,11 +1,8 @@ -using Asp.Versioning; -using DbContextLib; +using Dto; +using Asp.Versioning; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Model.Business; -using Model.DTO; -using Services; +using Shared; namespace API.Controllers { @@ -13,108 +10,122 @@ namespace API.Controllers [Authorize] [ApiVersion("1.0")] [ApiController] - public class UserController : Controller + public class UserController(ILogger logger, IUserService userService) : ControllerBase { - private IDataService _userDataService; - - private readonly ILogger _logger; - - public UserController(IDataService userDataService, ILogger logger) - { - _userDataService = userDataService; - _logger = logger; - } - [HttpGet("users/{page}/{number}")] - public IActionResult GetUsers(int page, int number) + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 204)] + public IActionResult GetUsers(int page, int number) { - var nbUser = _userDataService.GetUsers(page, number).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); - return Ok(_userDataService.GetUsers(page, number)); + + logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", users.Count); + return Ok(users); } [HttpGet("user/id/{id}")] + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 404)] public IActionResult GetUserById(int id) { try { - _logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id); - return Ok(_userDataService.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(); } } [HttpGet("user/username/{username}")] + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 404)] public IActionResult GetUserByUsername(string username) { try { - _logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username); - return Ok(_userDataService.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] + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 404)] public IActionResult DeleteUser(int id) { - var success = _userDataService.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(_userDataService.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) + [ProducesResponseType(typeof(UserDTO), 201)] + [ProducesResponseType(typeof(string), 400)] + 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); - return Created(nameof(GetUsers), _userDataService.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) + [ProducesResponseType(typeof(UserDTO), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + 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); + 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(); } - 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(_userDataService.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/API/Program.cs b/API_SQLuedo/API/Program.cs index 4717d1f..3c71775 100644 --- a/API_SQLuedo/API/Program.cs +++ b/API_SQLuedo/API/Program.cs @@ -1,12 +1,16 @@ using API; +using API.Service; using Asp.Versioning; using DbContextLib; +using DbDataManager.Service; +using Dto; +using Entities; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; -using Services; +using Shared; var builder = WebApplication.CreateBuilder(args); @@ -16,7 +20,10 @@ 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, 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..68a2c1a --- /dev/null +++ b/API_SQLuedo/API/Service/InquiryDataServiceAPI.cs @@ -0,0 +1,19 @@ +using Dto; +using Entities; +using Shared; +using Shared.Mapper; + +namespace API.Service; + +public class InquiryDataServiceApi(IInquiryService inquiryService) : IInquiryService +{ + 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).FromEntityToDTO(); + + 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 new file mode 100644 index 0000000..a4a6dca --- /dev/null +++ b/API_SQLuedo/API/Service/UserDataServiceAPI.cs @@ -0,0 +1,27 @@ +using Dto; +using Entities; +using Shared; +using Shared.Mapper; + +namespace API.Service; + +public class UserDataServiceApi(IUserService userService) : IUserService +{ + 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).FromEntityToDTO(); + + 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.FromDTOToEntity()).FromEntityToDTO(); + + public UserDTO CreateUser(string username, string password, string email, bool 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 58f87a2..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}") = "Model", "Model\Model.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 @@ -15,10 +15,16 @@ 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}" +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 +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 @@ -49,14 +55,26 @@ 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 {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 + {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 + {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 + {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/DbContextLib/UserDbContext.cs b/API_SQLuedo/DbContextLib/UserDbContext.cs index 019d33c..8be1c6f 100644 --- a/API_SQLuedo/DbContextLib/UserDbContext.cs +++ b/API_SQLuedo/DbContextLib/UserDbContext.cs @@ -1,8 +1,6 @@ -using Entities.SQLuedoDB; +using Entities; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.AspNetCore.Cryptography.KeyDerivation; using Microsoft.EntityFrameworkCore; -using System.Security.Cryptography; using Microsoft.AspNetCore.Identity; namespace DbContextLib @@ -31,42 +29,11 @@ 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); modelBuilder.Entity().HasKey(s => s.InquiryId); + modelBuilder.Entity().HasKey(s => s.Id); base.OnModelCreating(modelBuilder); } } diff --git a/API_SQLuedo/Services/Services.csproj b/API_SQLuedo/DbDataManager/DbDataManager.csproj similarity index 88% rename from API_SQLuedo/Services/Services.csproj rename to API_SQLuedo/DbDataManager/DbDataManager.csproj index 074a41e..42ff6a0 100644 --- a/API_SQLuedo/Services/Services.csproj +++ b/API_SQLuedo/DbDataManager/DbDataManager.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + ModelToEntities @@ -22,8 +23,10 @@ + + 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/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/BlackListEntity.cs b/API_SQLuedo/EntityFramework/BlackListEntity.cs new file mode 100644 index 0000000..e4b744b --- /dev/null +++ b/API_SQLuedo/EntityFramework/BlackListEntity.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("BlackList")] +public class BlackListEntity +{ + [Key] + public string Email { get; set; } + public DateOnly ExpirationDate { get; set; } + public BlackListEntity() { } + public BlackListEntity(string email, DateOnly 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 new file mode 100644 index 0000000..067cc39 --- /dev/null +++ b/API_SQLuedo/EntityFramework/ContentLessonEntity.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("ContentLesson")] +public class ContentLessonEntity +{ + [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; } + + 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/SQLuedoDB/InquiryEntity.cs b/API_SQLuedo/EntityFramework/InquiryEntity.cs similarity index 88% rename from API_SQLuedo/EntityFramework/SQLuedoDB/InquiryEntity.cs rename to API_SQLuedo/EntityFramework/InquiryEntity.cs index e364a14..9cae83e 100644 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/InquiryEntity.cs +++ b/API_SQLuedo/EntityFramework/InquiryEntity.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; -namespace Entities.SQLuedoDB +namespace Entities { public class InquiryEntity { diff --git a/API_SQLuedo/EntityFramework/InquiryTableEntity.cs b/API_SQLuedo/EntityFramework/InquiryTableEntity.cs new file mode 100644 index 0000000..c8798b9 --- /dev/null +++ b/API_SQLuedo/EntityFramework/InquiryTableEntity.cs @@ -0,0 +1,37 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("InquiryTable")] +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; } + + public InquiryTableEntity() { } + + 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; + } +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/LessonEntity.cs b/API_SQLuedo/EntityFramework/LessonEntity.cs new file mode 100644 index 0000000..2c345d3 --- /dev/null +++ b/API_SQLuedo/EntityFramework/LessonEntity.cs @@ -0,0 +1,33 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("Lesson")] +public class LessonEntity +{ + public int Id { get; set; } + public string? Title { get; set; } + public string? LastPublisher { get; set; } + public DateOnly? LastEdit { get; set; } + + 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(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 new file mode 100644 index 0000000..0a3f9c9 --- /dev/null +++ b/API_SQLuedo/EntityFramework/NotepadEntity.cs @@ -0,0 +1,38 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("Notepad")] +public class NotepadEntity +{ + public int Id { 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; } + + 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; + } +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/ParagraphEntity.cs b/API_SQLuedo/EntityFramework/ParagraphEntity.cs new file mode 100644 index 0000000..4dc2277 --- /dev/null +++ b/API_SQLuedo/EntityFramework/ParagraphEntity.cs @@ -0,0 +1,40 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("Paragraph")] +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 ParagraphEntity() { } + + + 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; + } +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/BlackListEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/BlackListEntity.cs deleted file mode 100644 index a1cb718..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/BlackListEntity.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Entities.SQLuedoDB -{ - public class BlackListEntity - { - [Key] - public string Email { get; set; } - public DateOnly ExpirationDate { get; set; } - public BlackListEntity() { } - public BlackListEntity(string email, DateOnly expirationDate) - { - Email = email; - ExpirationDate = expirationDate; - } - } -} diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/ContentLessonEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/ContentLessonEntity.cs deleted file mode 100644 index 2778c16..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/ContentLessonEntity.cs +++ /dev/null @@ -1,31 +0,0 @@ -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; - -namespace Entities.SQLuedoDB -{ - public class ContentLessonEntity - { - [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; } - - public ContentLessonEntity(){} - public ContentLessonEntity(int lessonId, LessonEntity lesson, int lessonPartId, ParagraphEntity paragraph) - { - LessonId = lessonId; - Lesson = lesson; - LessonPartId = lessonPartId; - Paragraph = paragraph; - } - } -} diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/InquiryTableEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/InquiryTableEntity.cs deleted file mode 100644 index 155398b..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/InquiryTableEntity.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; - -namespace Entities.SQLuedoDB -{ - 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; } - - public InquiryTableEntity() { } - - 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; - } - } -} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/LessonEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/LessonEntity.cs deleted file mode 100644 index 623eb1b..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/LessonEntity.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Entities.SQLuedoDB -{ - public class LessonEntity - { - public int Id { get; set; } - public string? Title { get; set; } - public string? LastPublisher { get; set; } - public DateOnly? LastEdit { get; set; } - - 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(string title, string lastPublisher, DateOnly? lastEdit) - { - Title = title; - LastPublisher = lastPublisher; - LastEdit = lastEdit; - } - } -} diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/NotepadEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/NotepadEntity.cs deleted file mode 100644 index f20c498..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/NotepadEntity.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Entities.SQLuedoDB -{ - public class NotepadEntity - { - public int Id { 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; } - - 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; - } - } -} diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/ParagraphEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/ParagraphEntity.cs deleted file mode 100644 index d83e27c..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/ParagraphEntity.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace Entities.SQLuedoDB -{ - 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 ParagraphEntity() { } - - - 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; - } - } -} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/SolutionEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/SolutionEntity.cs deleted file mode 100644 index 15879f7..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/SolutionEntity.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Security.Cryptography.X509Certificates; - -namespace Entities.SQLuedoDB -{ - 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) - { - Owner = owner; - MurdererFirstName = murdererFirstName; - MurdererLastName = murdererLastName; - MurderPlace = murderPlace; - MurderWeapon = murderWeapon; - Explanation = explanation; - } - } -} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/SuccessEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/SuccessEntity.cs deleted file mode 100644 index 4c06815..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/SuccessEntity.cs +++ /dev/null @@ -1,47 +0,0 @@ -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; - -namespace Entities.SQLuedoDB -{ - public class SuccessEntity - { - [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; } - - 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, int inquiryId, bool isFinished) - { - UserId = userId; - InquiryId = inquiryId; - IsFinished = isFinished; - } - - public SuccessEntity(UserEntity user, InquiryEntity inquiry, bool isFinished) - { - User = user; - Inquiry = inquiry; - IsFinished = isFinished; - } - } -} diff --git a/API_SQLuedo/EntityFramework/SQLuedoDB/UserEntity.cs b/API_SQLuedo/EntityFramework/SQLuedoDB/UserEntity.cs deleted file mode 100644 index 2de5210..0000000 --- a/API_SQLuedo/EntityFramework/SQLuedoDB/UserEntity.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace Entities.SQLuedoDB -{ - [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 UserEntity() { } - - 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(string username, string password, string email, bool isAdmin) - { - Username = username; - Password = password; - Email = email; - IsAdmin = isAdmin; - } - } -} diff --git a/API_SQLuedo/EntityFramework/SolutionEntity.cs b/API_SQLuedo/EntityFramework/SolutionEntity.cs new file mode 100644 index 0000000..6c8dbdf --- /dev/null +++ b/API_SQLuedo/EntityFramework/SolutionEntity.cs @@ -0,0 +1,44 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("Solution")] +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) + { + 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 new file mode 100644 index 0000000..10f21a9 --- /dev/null +++ b/API_SQLuedo/EntityFramework/SuccessEntity.cs @@ -0,0 +1,41 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[Table("Success")] +public class SuccessEntity +{ + [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; } + + 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, int inquiryId, bool isFinished) + { + UserId = userId; + InquiryId = inquiryId; + 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 new file mode 100644 index 0000000..2d22110 --- /dev/null +++ b/API_SQLuedo/EntityFramework/UserEntity.cs @@ -0,0 +1,39 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities; + +[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 UserEntity() + { + } + + 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(string username, string password, string email, bool isAdmin) + { + Username = username; + Password = password; + Email = email; + IsAdmin = isAdmin; + } +} \ No newline at end of file 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/Mappers/BlackListMapper.cs b/API_SQLuedo/Model/Mappers/BlackListMapper.cs deleted file mode 100644 index 8f6f52d..0000000 --- a/API_SQLuedo/Model/Mappers/BlackListMapper.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; -using Model.Business; -using Model.DTO; - -namespace Model.Mappers -{ - 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/Model/Mappers/ContentLessonMapper.cs b/API_SQLuedo/Model/Mappers/ContentLessonMapper.cs deleted file mode 100644 index f568070..0000000 --- a/API_SQLuedo/Model/Mappers/ContentLessonMapper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; -using Model.Business; - -namespace Model.Mappers -{ - 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/Model/Mappers/InquiryMapper.cs b/API_SQLuedo/Model/Mappers/InquiryMapper.cs deleted file mode 100644 index a26ef45..0000000 --- a/API_SQLuedo/Model/Mappers/InquiryMapper.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; -using Model.Business; -using Model.DTO; - -namespace Model.Mappers -{ - 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/Model/Mappers/InquiryTableMapper.cs b/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs deleted file mode 100644 index 234aa35..0000000 --- a/API_SQLuedo/Model/Mappers/InquiryTableMapper.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Model.Business; -using Model.DTO; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; - -namespace Model.Mappers -{ - public static class InquiryTableMapper - { - public static InquiryTable FromDTOToModel(this InquiryTableDTO InqTDto) - { - return new InquiryTable(InqTDto.OwnerId, InqTDto.ConnectionInfo, InqTDto.DatabaseName); - } - - public static 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/Model/Mappers/LessonMapper.cs b/API_SQLuedo/Model/Mappers/LessonMapper.cs deleted file mode 100644 index 1ca4094..0000000 --- a/API_SQLuedo/Model/Mappers/LessonMapper.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; -using Model.Business; -using Model.DTO; - -namespace Model.Mappers -{ - 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/Model/Mappers/NotepadMapper.cs b/API_SQLuedo/Model/Mappers/NotepadMapper.cs deleted file mode 100644 index f19109b..0000000 --- a/API_SQLuedo/Model/Mappers/NotepadMapper.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; -using Model.Business; -using Model.DTO; - -namespace Model.Mappers -{ - 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/Model/Mappers/ParagraphMapper.cs b/API_SQLuedo/Model/Mappers/ParagraphMapper.cs deleted file mode 100644 index 5d1928c..0000000 --- a/API_SQLuedo/Model/Mappers/ParagraphMapper.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; -using Model.Business; -using Model.DTO; -namespace Model.Mappers -{ - 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/Model/Mappers/SolutionMapper.cs b/API_SQLuedo/Model/Mappers/SolutionMapper.cs deleted file mode 100644 index a464be8..0000000 --- a/API_SQLuedo/Model/Mappers/SolutionMapper.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; -using Model.Business; -using Model.DTO; - -namespace Model.Mappers -{ - public static class SolutionMapper - { - public static Solution FromDTOToModel(this SolutionDTO dto) - { - return new Solution(dto.OwnerId,dto.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/Model/Mappers/SuccessMapper.cs b/API_SQLuedo/Model/Mappers/SuccessMapper.cs deleted file mode 100644 index 04f56b3..0000000 --- a/API_SQLuedo/Model/Mappers/SuccessMapper.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Entities.SQLuedoDB; -using Model.Business; -using Model.DTO; - -namespace Model.Mappers -{ - 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/Model/Mappers/UserMapper.cs b/API_SQLuedo/Model/Mappers/UserMapper.cs deleted file mode 100644 index 68d80a0..0000000 --- a/API_SQLuedo/Model/Mappers/UserMapper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Entities.SQLuedoDB; -using Model.Business; -using Model.DTO; - -namespace Model.Mappers -{ - 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/Model/Model.csproj b/API_SQLuedo/Model/Model.csproj index d0d9429..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/Services/IDataService.cs b/API_SQLuedo/Services/IDataService.cs deleted file mode 100644 index a3faad9..0000000 --- a/API_SQLuedo/Services/IDataService.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Model.Business; -using Model.DTO; - -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/UserDataService.cs b/API_SQLuedo/Services/UserDataService.cs deleted file mode 100644 index ddaa3e6..0000000 --- a/API_SQLuedo/Services/UserDataService.cs +++ /dev/null @@ -1,107 +0,0 @@ -using DbContextLib; -using Model.DTO; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Model.Mappers; -using Model.Business; -using Microsoft.EntityFrameworkCore; - -namespace Services -{ - public class UserDataService : IDataService - { - 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 UserDTO - { - Username = username, - Password = password, - Email = email, - IsAdmin = isAdmin - }; - DbContext.Users.Add(newUserEntity.FromDTOToModel().FromModelToEntity()); - 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/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/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 new file mode 100644 index 0000000..7db1a18 --- /dev/null +++ b/API_SQLuedo/Shared/Shared.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + + + + + + + + + diff --git a/API_SQLuedo/StubbedContextLib/StubbedContext.cs b/API_SQLuedo/StubbedContextLib/StubbedContext.cs new file mode 100644 index 0000000..a833821 --- /dev/null +++ b/API_SQLuedo/StubbedContextLib/StubbedContext.cs @@ -0,0 +1,50 @@ +using System.Security.Cryptography; +using DbContextLib; +using Entities; +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..c87b24a --- /dev/null +++ b/API_SQLuedo/StubbedContextLib/StubbedContextLib.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + enable + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/API_SQLuedo/TestConsoleAPI/Program.cs b/API_SQLuedo/TestConsoleAPI/Program.cs index 651de21..cbe8925 100644 --- a/API_SQLuedo/TestConsoleAPI/Program.cs +++ b/API_SQLuedo/TestConsoleAPI/Program.cs @@ -1,14 +1,14 @@ // See https://aka.ms/new-console-template for more information 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 Model.DTO; -using Services; var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); @@ -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, new UserDataServiceApi(new UserDataService(context))); void PrintUsers() { diff --git a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj index f3904a6..683d41b 100644 --- a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj +++ b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj @@ -15,8 +15,7 @@ - - +