diff --git a/API_SQLuedo/API/API.csproj b/API_SQLuedo/API/API.csproj
index 822644c..7d09073 100644
--- a/API_SQLuedo/API/API.csproj
+++ b/API_SQLuedo/API/API.csproj
@@ -25,7 +25,10 @@
-
+
+
+
+
diff --git a/API_SQLuedo/API/Controllers/InquiriesController.cs b/API_SQLuedo/API/Controllers/InquiriesController.cs
index c1d8210..80227f5 100644
--- a/API_SQLuedo/API/Controllers/InquiriesController.cs
+++ b/API_SQLuedo/API/Controllers/InquiriesController.cs
@@ -1,34 +1,34 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using Services;
+using Shared;
namespace API.Controllers
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
- public class InquiriesController : Controller
+ public class InquiriesController : ControllerBase
{
- private IDataService _inquiryDataService;
+ private IUserService<> _inquiryUserService;
private readonly ILogger _logger;
- public InquiriesController(IDataService inquiryDataService)
+ public InquiriesController(IUserService<> inquiryUserService)
{
- _inquiryDataService = inquiryDataService;
+ _inquiryUserService = inquiryUserService;
}
[HttpGet("inquiries/{page}/{number}")]
public IActionResult GetInquiries(int page, int number)
{
- var nbInquiry = _inquiryDataService.GetInquiries(page, number).Count();
+ var nbInquiry = _inquiryUserService.GetInquiries(page, number).Count();
if (nbInquiry == 0)
{
_logger.LogError("[ERREUR] Aucune enquête trouvé.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry);
- return Ok(_inquiryDataService.GetInquiries(page, number));
+ return Ok(_inquiryUserService.GetInquiries(page, number));
}
[HttpGet("inquiry/id/{id}")]
@@ -37,7 +37,7 @@ namespace API.Controllers
try
{
_logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id);
- return Ok(_inquiryDataService.GetInquiryById(id));
+ return Ok(_inquiryUserService.GetInquiryById(id));
}
catch (ArgumentException)
{
@@ -52,7 +52,7 @@ namespace API.Controllers
try
{
_logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title);
- return Ok(_inquiryDataService.GetInquiryByTitle(title));
+ return Ok(_inquiryUserService.GetInquiryByTitle(title));
}
catch (ArgumentException)
{
diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs
index 505fb4f..5d59627 100644
--- a/API_SQLuedo/API/Controllers/UserController.cs
+++ b/API_SQLuedo/API/Controllers/UserController.cs
@@ -1,7 +1,6 @@
-using Dto;
-using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using Services;
+using Shared;
namespace API.Controllers
{
@@ -9,29 +8,33 @@ namespace API.Controllers
[Authorize]
[ApiVersion("1.0")]
[ApiController]
- public class UserController : Controller
+ public class UserController : ControllerBase
{
- private IDataService _userDataService;
+ private IUserService<> _userUserService;
private readonly ILogger _logger;
- public UserController(IDataService userDataService, ILogger logger)
+ public UserController(IUserService<> userUserService, ILogger logger)
{
- _userDataService = userDataService;
+ _userUserService = userUserService;
_logger = logger;
}
[HttpGet("users/{page}/{number}")]
public IActionResult GetUsers(int page, int number)
{
- var nbUser = _userDataService.GetUsers(page, number).Count();
+ var getUsers = new InClassName(page, number);
+ _userUserService.GetUsers(getUsers);
+ var nbUser = getUsers.ReturnValue.Count();
if(nbUser == 0)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", nbUser);
- return Ok(_userDataService.GetUsers(page, number));
+ var value = new InClassName(page, number);
+ _userUserService.GetUsers(value);
+ return Ok(value.ReturnValue);
}
[HttpGet("user/id/{id}")]
@@ -40,7 +43,7 @@ namespace API.Controllers
try
{
_logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id);
- return Ok(_userDataService.GetUserById(id));
+ return Ok(_userUserService.GetUserById(id));
} catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
@@ -54,7 +57,7 @@ namespace API.Controllers
try
{
_logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username);
- return Ok(_userDataService.GetUserByUsername(username));
+ return Ok(_userUserService.GetUserByUsername(username));
}catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {username}.", username);
@@ -66,11 +69,11 @@ namespace API.Controllers
[HttpDelete]
public IActionResult DeleteUser(int id)
{
- var success = _userDataService.DeleteUser(id);
+ var success = _userUserService.DeleteUser(id);
if(success)
{
_logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id);
- return Ok(_userDataService.DeleteUser(id));
+ return Ok(_userUserService.DeleteUser(id));
} else
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
@@ -88,7 +91,7 @@ namespace API.Controllers
}
// return Ok(_userDataService.CreateUser(username, password, email, isAdmin));
_logger.LogInformation("[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}", dto.Username, dto.Password, dto.Email, dto.IsAdmin);
- return Created(nameof(GetUsers), _userDataService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin));
+ return Created(nameof(GetUsers), _userUserService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin));
}
[HttpPut]
@@ -107,7 +110,7 @@ namespace API.Controllers
if(userDTO != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour de l'utilsiateur avec l'id {id} a été effectuée", id);
- return Ok(_userDataService.UpdateUser(id, userDTO));
+ return Ok(_userUserService.UpdateUser(id, userDTO));
}
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
diff --git a/API_SQLuedo/API/Program.cs b/API_SQLuedo/API/Program.cs
index 8630246..9eeab75 100644
--- a/API_SQLuedo/API/Program.cs
+++ b/API_SQLuedo/API/Program.cs
@@ -1,10 +1,13 @@
using API;
using DbContextLib;
+using Dto;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
-using Services;
+using ModelToEntities.Business;
+using ModelToEntities.Service;
+using Shared;
var builder = WebApplication.CreateBuilder(args);
@@ -14,7 +17,8 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
-builder.Services.AddScoped();
+builder.Services.AddScoped, UserDataService>();
+builder.Services.AddScoped, InquiryDataService>();
builder.Services.AddDbContext();
builder.Services.AddDbContext(options => options.UseInMemoryDatabase("appDb"));
builder.Services.AddIdentityApiEndpoints().AddEntityFrameworkStores();
diff --git a/API_SQLuedo/API_SQLuedo.sln b/API_SQLuedo/API_SQLuedo.sln
index 85e6314..c6c08b5 100644
--- a/API_SQLuedo/API_SQLuedo.sln
+++ b/API_SQLuedo/API_SQLuedo.sln
@@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEF", "TestEF\TestEF.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleAPI", "TestConsoleAPI\TestConsoleAPI.csproj", "{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{B64941C9-0550-4C47-89B6-396F6DB0486D}"
@@ -25,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dto", "Dto\Dto.csproj", "{9
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{EDDA59D4-BD38-46BF-8292-26A47187B76F}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -55,10 +55,6 @@ Global
{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Release|Any CPU.Build.0 = Release|Any CPU
- {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.Build.0 = Release|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -75,6 +71,10 @@ Global
{EDDA59D4-BD38-46BF-8292-26A47187B76F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDDA59D4-BD38-46BF-8292-26A47187B76F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDDA59D4-BD38-46BF-8292-26A47187B76F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/API_SQLuedo/ModelToEntities/BlackListMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/BlackListMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/BlackListMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/BlackListMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/ContentLessonMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/ContentLessonMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/ContentLessonMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/ContentLessonMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/InquiryMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/InquiryMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/InquiryMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/InquiryMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/InquiryTableMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/InquiryTableMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/InquiryTableMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/InquiryTableMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/LessonMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/LessonMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/LessonMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/LessonMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/NotepadMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/NotepadMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/NotepadMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/NotepadMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/ParagraphMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/ParagraphMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/ParagraphMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/ParagraphMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/SolutionMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/SolutionMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/SolutionMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/SolutionMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/SuccessMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/SuccessMapper.cs
similarity index 100%
rename from API_SQLuedo/ModelToEntities/SuccessMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/SuccessMapper.cs
diff --git a/API_SQLuedo/ModelToEntities/UserMapper.cs b/API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs
similarity index 97%
rename from API_SQLuedo/ModelToEntities/UserMapper.cs
rename to API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs
index 940a187..c570909 100644
--- a/API_SQLuedo/ModelToEntities/UserMapper.cs
+++ b/API_SQLuedo/ModelToEntities/Mapper/UserMapper.cs
@@ -2,7 +2,7 @@
using Entities;
using ModelToEntities.Business;
-namespace ModelToEntities
+namespace ModelToEntities.Service
{
public static class UserMapper
{
diff --git a/API_SQLuedo/ModelToEntities/ModelToEntities.csproj b/API_SQLuedo/ModelToEntities/ModelToEntities.csproj
index 1d0c3c9..36a5aa9 100644
--- a/API_SQLuedo/ModelToEntities/ModelToEntities.csproj
+++ b/API_SQLuedo/ModelToEntities/ModelToEntities.csproj
@@ -24,6 +24,7 @@
+
diff --git a/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs b/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs
new file mode 100644
index 0000000..78c5a65
--- /dev/null
+++ b/API_SQLuedo/ModelToEntities/Service/InquiryDataService.cs
@@ -0,0 +1,22 @@
+using ModelToEntities.Business;
+using Shared;
+
+namespace ModelToEntities.Service;
+
+public class InquiryDataService : IInquiryService
+{
+ public IEnumerable GetInquiries(int page, int number)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Inquiry GetInquiryById(int id)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Inquiry GetInquiryByTitle(string title)
+ {
+ throw new NotImplementedException();
+ }
+}
\ No newline at end of file
diff --git a/API_SQLuedo/Services/UserDataService.cs b/API_SQLuedo/ModelToEntities/Service/UserDataService.cs
similarity index 83%
rename from API_SQLuedo/Services/UserDataService.cs
rename to API_SQLuedo/ModelToEntities/Service/UserDataService.cs
index f0b2a3a..2e9a365 100644
--- a/API_SQLuedo/Services/UserDataService.cs
+++ b/API_SQLuedo/ModelToEntities/Service/UserDataService.cs
@@ -1,11 +1,11 @@
-using DbContextLib;
-using Dto;
+using Dto;
using Microsoft.EntityFrameworkCore;
-using ModelToEntities;
+using ModelToEntities.Business;
+using Shared;
-namespace Services
+namespace ModelToEntities.Service
{
- public class UserDataService : IDataService
+ public class UserDataService : IUserService
{
private UserDbContext DbContext { get; set; }
public UserDataService(UserDbContext context)
@@ -71,7 +71,7 @@ namespace Services
public UserDTO CreateUser(string username, string password, string email, bool isAdmin)
{
- var newUserEntity = new UserDTO
+ var newUserEntity = new User
{
Username = username,
Password = password,
@@ -82,20 +82,5 @@ namespace Services
DbContext.SaveChangesAsync();
return newUserEntity;
}
-
- public IEnumerable GetInquiries(int page, int number)
- {
- throw new NotImplementedException();
- }
-
- public InquiryDTO GetInquiryById(int id)
- {
- throw new NotImplementedException();
- }
-
- public InquiryDTO GetInquiryByTitle(string title)
- {
- throw new NotImplementedException();
- }
}
}
diff --git a/API_SQLuedo/Services/IDataService.cs b/API_SQLuedo/Services/IDataService.cs
deleted file mode 100644
index 653a3bc..0000000
--- a/API_SQLuedo/Services/IDataService.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Dto;
-using ModelToEntities.Business;
-
-namespace Services
-{
- public interface IDataService
- {
- public IEnumerable GetUsers(int page, int number);
- public UserDTO GetUserById(int id);
- public UserDTO GetUserByUsername(string username);
- public bool DeleteUser(int id);
- public UserDTO UpdateUser(int id, UserDTO user);
- public UserDTO CreateUser(string username, string password, string email, bool isAdmin);
- public IEnumerable GetInquiries(int page, int number);
- public InquiryDTO GetInquiryById(int id);
- public InquiryDTO GetInquiryByTitle(string title);
- }
-}
diff --git a/API_SQLuedo/Services/Services.csproj b/API_SQLuedo/Services/Services.csproj
deleted file mode 100644
index 88af2f2..0000000
--- a/API_SQLuedo/Services/Services.csproj
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
- net8.0
- enable
- enable
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
-
-
-
-
-
diff --git a/API_SQLuedo/Shared/IInquiryService.cs b/API_SQLuedo/Shared/IInquiryService.cs
new file mode 100644
index 0000000..7d03786
--- /dev/null
+++ b/API_SQLuedo/Shared/IInquiryService.cs
@@ -0,0 +1,8 @@
+namespace Shared;
+
+public interface IInquiryService
+{
+ public IEnumerable GetInquiries(int page, int number);
+ public TInquiry GetInquiryById(int id);
+ public TInquiry GetInquiryByTitle(string title);
+}
\ No newline at end of file
diff --git a/API_SQLuedo/Shared/IUserService.cs b/API_SQLuedo/Shared/IUserService.cs
new file mode 100644
index 0000000..2d17fd3
--- /dev/null
+++ b/API_SQLuedo/Shared/IUserService.cs
@@ -0,0 +1,12 @@
+namespace Shared
+{
+ public interface IUserService
+ {
+ public IEnumerable GetUsers(int page, int number);
+ public TUser GetUserById(int id);
+ public TUser GetUserByUsername(string username);
+ public bool DeleteUser(int id);
+ public TUser UpdateUser(int id, TUser user);
+ public TUser CreateUser(string username, string password, string email, bool isAdmin);
+ }
+}
\ No newline at end of file
diff --git a/API_SQLuedo/Shared/Shared.csproj b/API_SQLuedo/Shared/Shared.csproj
new file mode 100644
index 0000000..3a63532
--- /dev/null
+++ b/API_SQLuedo/Shared/Shared.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
diff --git a/API_SQLuedo/TestConsoleAPI/Program.cs b/API_SQLuedo/TestConsoleAPI/Program.cs
index 9d83c32..df49a1a 100644
--- a/API_SQLuedo/TestConsoleAPI/Program.cs
+++ b/API_SQLuedo/TestConsoleAPI/Program.cs
@@ -8,7 +8,7 @@ using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
-using Services;
+using ModelToEntities.Service;
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
diff --git a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj
index cea8135..801193b 100644
--- a/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj
+++ b/API_SQLuedo/TestConsoleAPI/TestConsoleAPI.csproj
@@ -15,7 +15,6 @@
-