Merge pull request 'archi' (#29) from archi into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #29
pull/30/head
Maxime SAPOUNTZIS 1 year ago
commit 27ee6ed669

@ -26,7 +26,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Services\Services.csproj" /> <ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\Dto\Dto.csproj" />
<ProjectReference Include="..\DbDataManager\DbDataManager.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\StubbedContextLib\StubbedContextLib.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,44 +1,50 @@
using Microsoft.AspNetCore.Authorization; using Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Model.DTO; using Shared;
using Services;
namespace API.Controllers namespace API.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[Authorize] [Authorize]
[ApiController] [ApiController]
public class InquiriesController : Controller public class InquiriesController()
: ControllerBase
{ {
private IDataService _inquiryDataService; private readonly IInquiryService<InquiryDTO> _inquiryService;
private readonly ILogger<InquiriesController> _logger;
private readonly ILogger<UserController> _logger; public InquiriesController(IInquiryService<InquiryDTO> inquiryService, ILogger<InquiriesController> logger) : this()
public InquiriesController(IDataService inquiryDataService)
{ {
_inquiryDataService = inquiryDataService; _inquiryService = inquiryService;
_logger = logger;
} }
[HttpGet("inquiries/{page}/{number}")] [HttpGet("inquiries/{page}/{number}")]
[ProducesResponseType(typeof(InquiryDTO), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetInquiries(int page, int number) public IActionResult GetInquiries(int page, int number)
{ {
var nbInquiry = _inquiryDataService.GetInquiries(page, number).Count(); var nbInquiry = _inquiryService.GetInquiries(page, number).Count();
if (nbInquiry == 0) if (nbInquiry == 0)
{ {
_logger.LogError("[ERREUR] Aucune enquête trouvé."); _logger.LogError("[ERREUR] Aucune enquête trouvé.");
return StatusCode(204); return StatusCode(204);
} }
_logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry); _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}")] [HttpGet("inquiry/id/{id}")]
[ProducesResponseType(typeof(InquiryDTO), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetInquiryById(int id) public IActionResult GetInquiryById(int id)
{ {
try try
{ {
_logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id); _logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id);
return Ok(_inquiryDataService.GetInquiryById(id)); return Ok(_inquiryService.GetInquiryById(id));
} }
catch (ArgumentException) catch (ArgumentException)
{ {
@ -48,12 +54,14 @@ namespace API.Controllers
} }
[HttpGet("inquiry/title/{title}")] [HttpGet("inquiry/title/{title}")]
[ProducesResponseType(typeof(InquiryDTO), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetInquiryByTitle(string title) public IActionResult GetInquiryByTitle(string title)
{ {
try try
{ {
_logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title); _logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title);
return Ok(_inquiryDataService.GetInquiryByTitle(title)); return Ok(_inquiryService.GetInquiryByTitle(title));
} }
catch (ArgumentException) catch (ArgumentException)
{ {

@ -1,11 +1,8 @@
using Asp.Versioning; using Dto;
using DbContextLib; using Asp.Versioning;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Model.Business; using Shared;
using Model.DTO;
using Services;
namespace API.Controllers namespace API.Controllers
{ {
@ -13,107 +10,121 @@ namespace API.Controllers
[Authorize] [Authorize]
[ApiVersion("1.0")] [ApiVersion("1.0")]
[ApiController] [ApiController]
public class UserController : Controller public class UserController(ILogger<UserController> logger, IUserService<UserDTO> userService) : ControllerBase
{ {
private IDataService _userDataService;
private readonly ILogger<UserController> _logger;
public UserController(IDataService userDataService, ILogger<UserController> logger)
{
_userDataService = userDataService;
_logger = logger;
}
[HttpGet("users/{page}/{number}")] [HttpGet("users/{page}/{number}")]
[ProducesResponseType(typeof(UserDTO), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetUsers(int page, int number) public IActionResult GetUsers(int page, int number)
{ {
var nbUser = _userDataService.GetUsers(page, number).Count(); var users = userService.GetUsers(page, number).ToList();
if(nbUser == 0) if (users.Count == 0)
{ {
_logger.LogError("[ERREUR] Aucun utilisateur trouvé."); logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204); 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}")] [HttpGet("user/id/{id}")]
[ProducesResponseType(typeof(UserDTO), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetUserById(int id) public IActionResult GetUserById(int id)
{ {
try try
{ {
_logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id); logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id);
return Ok(_userDataService.GetUserById(id)); return Ok(userService.GetUserById(id));
} catch (ArgumentException) }
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(); return NotFound();
} }
} }
[HttpGet("user/username/{username}")] [HttpGet("user/username/{username}")]
[ProducesResponseType(typeof(UserDTO), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetUserByUsername(string username) public IActionResult GetUserByUsername(string username)
{ {
try try
{ {
_logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username); logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username);
return Ok(_userDataService.GetUserByUsername(username)); return Ok(userService.GetUserByUsername(username));
}catch (ArgumentException) }
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(); return NotFound();
} }
} }
[HttpDelete] [HttpDelete]
[ProducesResponseType(typeof(UserDTO), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteUser(int id) public IActionResult DeleteUser(int id)
{ {
var success = _userDataService.DeleteUser(id); var success = userService.DeleteUser(id);
if (success) if (success)
{ {
_logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id); logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id);
return Ok(_userDataService.DeleteUser(id)); return Ok(userService.DeleteUser(id));
} else }
else
{ {
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound(); return NotFound();
} }
} }
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(UserDTO), 201)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateUser([FromBody] UserDTO dto) public IActionResult CreateUser([FromBody] UserDTO dto)
{ {
if (dto.Username == null || dto.Password == null || dto.Email == null) if (dto.Username == null || dto.Password == null || dto.Email == null)
{ {
return BadRequest(); 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 Ok(userService.CreateUser(username, password, email, isAdmin));
return Created(nameof(GetUsers), _userDataService.CreateUser(dto.Username, dto.Password, dto.Email, dto.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] [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) if (id != userDto.Id)
{ {
_logger.LogError("[ERREUR] Problème ID - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id); logger.LogError("[ERREUR] Problème ID - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id);
return BadRequest(); 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(); 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); logger.LogInformation("[INFORMATION] La mise à jour de l'utilsiateur avec l'id {id} a été effectuée",
return Ok(_userDataService.UpdateUser(id, userDTO)); id);
return Ok(userService.UpdateUser(id, userDto));
} }
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound(); return NotFound();
} }
} }

@ -1,12 +1,16 @@
using API; using API;
using API.Service;
using Asp.Versioning; using Asp.Versioning;
using DbContextLib; using DbContextLib;
using DbDataManager.Service;
using Dto;
using Entities;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Services; using Shared;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -16,7 +20,10 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IDataService, UserDataService>(); builder.Services.AddScoped<IUserService<UserEntity>, UserDataService>();
builder.Services.AddScoped<IUserService<UserDTO>, UserDataServiceApi>();
builder.Services.AddScoped<IInquiryService<InquiryEntity>, InquiryDataService>();
builder.Services.AddScoped<IInquiryService<InquiryDTO>, InquiryDataServiceApi>();
builder.Services.AddDbContext<DbContext, UserDbContext>(); builder.Services.AddDbContext<DbContext, UserDbContext>();
builder.Services.AddDbContext<WebAPIDbContext>(options => options.UseInMemoryDatabase("appDb")); builder.Services.AddDbContext<WebAPIDbContext>(options => options.UseInMemoryDatabase("appDb"));
builder.Services.AddIdentityApiEndpoints<IdentityUser>().AddEntityFrameworkStores<WebAPIDbContext>(); builder.Services.AddIdentityApiEndpoints<IdentityUser>().AddEntityFrameworkStores<WebAPIDbContext>();

@ -0,0 +1,19 @@
using Dto;
using Entities;
using Shared;
using Shared.Mapper;
namespace API.Service;
public class InquiryDataServiceApi(IInquiryService<InquiryEntity> inquiryService) : IInquiryService<InquiryDTO>
{
public IEnumerable<InquiryDTO> 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();
}

@ -0,0 +1,27 @@
using Dto;
using Entities;
using Shared;
using Shared.Mapper;
namespace API.Service;
public class UserDataServiceApi(IUserService<UserEntity> userService) : IUserService<UserDTO>
{
public IEnumerable<UserDTO> 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();
}

@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{6
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "EntityFramework\Entities.csproj", "{6D079CDA-C000-4833-98A0-D07D153EA264}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "EntityFramework\Entities.csproj", "{6D079CDA-C000-4833-98A0-D07D153EA264}"
EndProject 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 EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{17025B90-8B2A-49E9-97D3-1A84A208DF50}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{17025B90-8B2A-49E9-97D3-1A84A208DF50}"
EndProject EndProject
@ -15,10 +15,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEF", "TestEF\TestEF.csp
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}"
EndProject 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleAPI", "TestConsoleAPI\TestConsoleAPI.csproj", "{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}"
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Release|Any CPU.Build.0 = 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.ActiveCfg = Debug|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -1,8 +1,6 @@
using Entities.SQLuedoDB; using Entities;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
namespace DbContextLib namespace DbContextLib
@ -31,42 +29,11 @@ namespace DbContextLib
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<UserEntity>().ToTable("user");
modelBuilder.Entity<UserEntity>().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<ContentLessonEntity>().HasKey(c => c.LessonId); modelBuilder.Entity<ContentLessonEntity>().HasKey(c => c.LessonId);
modelBuilder.Entity<ContentLessonEntity>().HasKey(c => c.LessonPartId); modelBuilder.Entity<ContentLessonEntity>().HasKey(c => c.LessonPartId);
modelBuilder.Entity<SuccessEntity>().HasKey(s => s.UserId); modelBuilder.Entity<SuccessEntity>().HasKey(s => s.UserId);
modelBuilder.Entity<SuccessEntity>().HasKey(s => s.InquiryId); modelBuilder.Entity<SuccessEntity>().HasKey(s => s.InquiryId);
modelBuilder.Entity<InquiryEntity>().HasKey(s => s.Id);
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
} }
} }

@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>ModelToEntities</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -22,8 +23,10 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" /> <ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\Dto\Dto.csproj" />
<ProjectReference Include="..\EntityFramework\Entities.csproj" /> <ProjectReference Include="..\EntityFramework\Entities.csproj" />
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -0,0 +1,23 @@
using Dto;
using Entities;
using Shared;
namespace DbDataManager.Service;
public class InquiryDataService : IInquiryService<InquiryEntity>
{
public IEnumerable<InquiryEntity> GetInquiries(int page, int number)
{
throw new NotImplementedException();
}
public InquiryEntity GetInquiryById(int id)
{
throw new NotImplementedException();
}
public InquiryEntity GetInquiryByTitle(string title)
{
throw new NotImplementedException();
}
}

@ -0,0 +1,90 @@
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
using Shared;
namespace DbDataManager.Service;
public class UserDataService : IUserService<UserEntity>
{
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<UserEntity> 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;
}
}

@ -1,10 +1,4 @@
using System; namespace Dto
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class BlackListDTO public class BlackListDTO
{ {

@ -1,12 +1,4 @@
using Entities.SQLuedoDB; namespace Dto
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class ContentLessonDTO public class ContentLessonDTO
{ {

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -1,11 +1,4 @@
using Entities.SQLuedoDB; namespace Dto
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class InquiryDTO public class InquiryDTO
{ {

@ -1,11 +1,4 @@
using Model.Business; namespace Dto
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class InquiryTableDTO public class InquiryTableDTO
{ {

@ -1,10 +1,4 @@
using System; namespace Dto
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class LessonDTO public class LessonDTO
{ {

@ -1,10 +1,4 @@
using System; namespace Dto
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class NotepadDTO public class NotepadDTO
{ {

@ -1,10 +1,4 @@
using System; namespace Dto
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class ParagraphDTO public class ParagraphDTO
{ {

@ -1,11 +1,4 @@
using Model.Business; namespace Dto
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class SolutionDTO public class SolutionDTO
{ {

@ -1,10 +1,4 @@
using System; namespace Dto
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class SuccessDTO public class SuccessDTO
{ {

@ -1,10 +1,4 @@
using System; namespace Dto
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{ {
public class UserDTO public class UserDTO
{ {

@ -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;
}
}

@ -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;
}
}

@ -1,10 +1,6 @@
using System; using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities.SQLuedoDB namespace Entities
{ {
public class InquiryEntity public class InquiryEntity
{ {

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -1,10 +1,4 @@
using System; namespace ModelToEntities.Business
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class BlackList public class BlackList
{ {

@ -1,12 +1,4 @@
using Entities.SQLuedoDB; namespace ModelToEntities.Business
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class ContentLesson public class ContentLesson
{ {

@ -1,12 +1,4 @@
using Entities.SQLuedoDB; namespace ModelToEntities.Business
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class Inquiry public class Inquiry
{ {

@ -1,11 +1,4 @@
using Entities.SQLuedoDB; namespace ModelToEntities.Business
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class InquiryTable public class InquiryTable
{ {

@ -1,10 +1,4 @@
using System; namespace ModelToEntities.Business
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class Lesson public class Lesson
{ {

@ -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);
}
}
}

@ -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));
}
}
}

@ -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);
}
}
}

@ -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);
}
}
}

@ -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);
}
}
}

@ -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);
}
}
}

@ -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);
}
}
}

@ -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);
}
}
}

@ -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);
}
}
}

@ -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);
}
}
}

@ -6,22 +6,4 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Asp.Versioning.Mvc" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EntityFramework\Entities.csproj" />
</ItemGroup>
</Project> </Project>

@ -1,12 +1,4 @@
using Entities.SQLuedoDB; namespace ModelToEntities.Business
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class Notepad public class Notepad
{ {

@ -1,10 +1,4 @@
using System; namespace ModelToEntities.Business
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class Paragraph public class Paragraph
{ {

@ -1,11 +1,4 @@
using Entities.SQLuedoDB; namespace ModelToEntities.Business
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class Solution public class Solution
{ {

@ -1,12 +1,4 @@
using Entities.SQLuedoDB; namespace ModelToEntities.Business
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{ {
public class Success public class Success
{ {

@ -1,4 +1,4 @@
namespace Model.Business namespace ModelToEntities.Business
{ {
public class User public class User
{ {

@ -1,18 +0,0 @@
using Model.Business;
using Model.DTO;
namespace Services
{
public interface IDataService
{
public IEnumerable<UserDTO> 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<InquiryDTO> GetInquiries(int page, int number);
public InquiryDTO GetInquiryById(int id);
public InquiryDTO GetInquiryByTitle(string title);
}
}

@ -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<UserDTO> 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<InquiryDTO> GetInquiries(int page, int number)
{
throw new NotImplementedException();
}
public InquiryDTO GetInquiryById(int id)
{
throw new NotImplementedException();
}
public InquiryDTO GetInquiryByTitle(string title)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,8 @@
namespace Shared;
public interface IInquiryService<TInquiry>
{
public IEnumerable<TInquiry> GetInquiries(int page, int number);
public TInquiry GetInquiryById(int id);
public TInquiry GetInquiryByTitle(string title);
}

@ -0,0 +1,12 @@
namespace Shared
{
public interface IUserService<TUser>
{
public IEnumerable<TUser> 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);
}
}

@ -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);
}
}

@ -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));
}
}

@ -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);
}
}

@ -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);
}
}

@ -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);
}
}

@ -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);
}
}

@ -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);
}
}

@ -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);
}
}

@ -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);
}
}

@ -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);
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dto\Dto.csproj" />
<ProjectReference Include="..\EntityFramework\Entities.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -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<UserDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<UserEntity>().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));
}
}

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -1,14 +1,14 @@
// See https://aka.ms/new-console-template for more information // See https://aka.ms/new-console-template for more information
using API.Controllers; using API.Controllers;
using API.Service;
using DbContextLib; using DbContextLib;
using DbDataManager.Service;
using Dto;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Model.DTO;
using Services;
var connection = new SqliteConnection("DataSource=:memory:"); var connection = new SqliteConnection("DataSource=:memory:");
connection.Open(); connection.Open();
@ -20,7 +20,7 @@ ILogger<UserController> logger = factory.CreateLogger<UserController>();
using (var context = new UserDbContext(options)) 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() void PrintUsers()
{ {

@ -15,8 +15,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\API\API.csproj" /> <ProjectReference Include="..\API\API.csproj" />
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" /> <ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\DbDataManager\DbDataManager.csproj" />
<ProjectReference Include="..\Services\Services.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

Loading…
Cancel
Save