Compare commits
No commits in common. 'master' and 'testConsoleEF' have entirely different histories.
master
...
testConsol
@ -1,30 +0,0 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
@ -1,94 +0,0 @@
|
||||
using Asp.Versioning;
|
||||
using Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Model.OrderCriteria;
|
||||
using Shared;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Authorize]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
public class BlackListController(ILogger<UsersController> logger, IBlackListService<BlackListDto> blackListService)
|
||||
: ControllerBase
|
||||
{
|
||||
[HttpGet("user/ban/{page:int}/{number:int}")]
|
||||
[ProducesResponseType(typeof(IEnumerable<BlackListDto>), 200)]
|
||||
[ProducesResponseType(typeof(string), 204)]
|
||||
public IActionResult GetBannedUsers(int page, int number, BlackListOdrerCriteria orderCriteria)
|
||||
{
|
||||
var users = blackListService.GetBannedUsers(page, number, orderCriteria).ToList();
|
||||
if (users.Count == 0)
|
||||
{
|
||||
logger.LogError("[ERREUR] Aucun email banni trouvé.");
|
||||
return StatusCode(204);
|
||||
}
|
||||
|
||||
logger.LogInformation("[INFORMATION] {nb} Email(s) banni(s) trouvé(s)", users.Count);
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("user/ban/number")]
|
||||
[ProducesResponseType(typeof(UserDto), 200)]
|
||||
[ProducesResponseType(typeof(string), 204)]
|
||||
public IActionResult GetNumberOfBannedUsers()
|
||||
{
|
||||
var nb = blackListService.GetNumberOfBannedUsers();
|
||||
logger.LogInformation("[INFORMATION] {nb} Email(s) banni(s) trouvé(s)", nb);
|
||||
return Ok(new KeyValuePair<string,int>("number",nb));
|
||||
}
|
||||
|
||||
[HttpPost("user/ban")]
|
||||
[ProducesResponseType(typeof(UserDto), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
public IActionResult GetUserBannedByEmail([FromBody] string email)
|
||||
{
|
||||
var res = blackListService.GetUserBannedByEmail(email);
|
||||
if (res != null)
|
||||
{
|
||||
logger.LogInformation("[INFORMATION] Utilisateur banni avec l'email {email} a été trouvé.", email);
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
logger.LogError("[ERREUR] Aucun utilisateur banni trouvé avec l'email {email}.", email);
|
||||
return NotFound("Utilisateur non trouvé !");
|
||||
}
|
||||
|
||||
[HttpDelete("user/ban/{username:alpha}")]
|
||||
[ProducesResponseType(typeof(UserDto), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
public IActionResult BanUser(string username)
|
||||
{
|
||||
var success = blackListService.BanUser(username);
|
||||
if (success)
|
||||
{
|
||||
logger.LogInformation("[INFORMATION] L'utilisateur avec le pseudo {username} a été banni pour 2 ans.", username);
|
||||
return Ok(new KeyValuePair<string,bool>("success", true));
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec le pseudo {username}.", username);
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("user/unban")]
|
||||
[ProducesResponseType(typeof(UserDto), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
public IActionResult UnbanUser([FromBody] string email)
|
||||
{
|
||||
var success = blackListService.UnbanUser(email);
|
||||
if (success)
|
||||
{
|
||||
logger.LogInformation("[INFORMATION] L'utilisateur avec l'email {email} a été débanni.", email);
|
||||
return Ok(new KeyValuePair<string,bool>("success", true));
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("[ERREUR] Aucun utilisateur banni trouvé avec l'email {email}.", email);
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
using Asp.Versioning;
|
||||
using Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Authorize]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
public class InquiryTableController : Controller
|
||||
{
|
||||
private readonly IInquiryTableService<InquiryTableDto> _inquiryTableService;
|
||||
|
||||
private readonly ILogger<InquiryTableController> _logger;
|
||||
|
||||
public InquiryTableController(IInquiryTableService<InquiryTableDto> inquiryTableService, ILogger<InquiryTableController> logger)
|
||||
{
|
||||
_inquiryTableService = inquiryTableService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("database/{id:int}")]
|
||||
[ProducesResponseType(typeof(string), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
public IActionResult GetDatabaseNameByInquiryById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("[INFORMATION] La base de données pour l'enquête avec l'id {id} a été trouvé.", id);
|
||||
return Ok(_inquiryTableService.GetDatabaseNameByInquiryId(id));
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
_logger.LogError("[ERREUR] Aucune base de données trouvée pour l'enquête avec l'id {id}.", id);
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
using Asp.Versioning;
|
||||
using Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Authorize]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
public class NotepadController : Controller
|
||||
{
|
||||
private readonly INotepadService<NotepadDto> _notepadDataService;
|
||||
|
||||
private readonly ILogger<NotepadController> _logger;
|
||||
|
||||
public NotepadController(INotepadService<NotepadDto> notepadService, ILogger<NotepadController> logger)
|
||||
{
|
||||
_notepadDataService = notepadService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("notepad/{userId:int}/{inquiryId:int}")]
|
||||
[ProducesResponseType(typeof(NotepadDto), 200)]
|
||||
[ProducesResponseType(typeof(void), 404)]
|
||||
public IActionResult GetNotepadByUserAndInquiryById(int userId, int inquiryId)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"[INFORMATION] Le bloc-notes de l'utilisateur avec l'id {id} et l'enquête avec l'id {idInquiry} a été trouvé.",
|
||||
userId, inquiryId);
|
||||
return Ok(_notepadDataService.GetNotepadFromUserAndInquiryId(userId,inquiryId));
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
_logger.LogError(
|
||||
"[ERREUR] Aucun bloc-notes trouvé pour l'utilisateur avec l'id {id} et l'enquête avec l'id {inquiryId}.",
|
||||
userId, inquiryId);
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("notepad")]
|
||||
[ProducesResponseType(typeof(void), 200)]
|
||||
[ProducesResponseType(typeof(void), 404)]
|
||||
public IActionResult SetNotepadByUserAndInquiryById([FromBody] NotepadDto notepad)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (notepad.InquiryId < 0 || notepad.UserId < 0 || notepad.Notes == null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
_notepadDataService.SetNotepadFromUserAndInquiryId(notepad.UserId, notepad.InquiryId, notepad.Notes);
|
||||
_logger.LogInformation(
|
||||
"[INFORMATION] Le bloc-notes de l'utilisateur avec l'id {id} et l'enquête avec l'id {idInquiry} a été créé.",
|
||||
notepad.UserId, notepad.InquiryId);
|
||||
return Ok();
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
_logger.LogError(
|
||||
"[ERREUR] Aucun bloc-notes n'a pu être créé pour l'utilisateur avec l'id {id} et l'enquête avec l'id {inquiryId}.",
|
||||
notepad.UserId, notepad.InquiryId);
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("notepad")]
|
||||
[ProducesResponseType(typeof(void), 203)]
|
||||
[ProducesResponseType(typeof(void), 404)]
|
||||
public IActionResult UpdateNotepadByUserAndInquiryById([FromBody] NotepadDto notepad)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (notepad.InquiryId < 0 || notepad.UserId < 0 || notepad.Notes == null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
_notepadDataService.UpdateNotepadFromUserAndInquiryId(notepad.UserId, notepad.InquiryId, notepad.Notes);
|
||||
_logger.LogInformation(
|
||||
"[INFORMATION] Le bloc-notes de l'utilisateur avec l'id {id} et l'enquête avec l'id {idInquiry} a été mis à jour.",
|
||||
notepad.UserId, notepad.InquiryId);
|
||||
return Ok();
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
_logger.LogError(
|
||||
"[ERREUR] Aucun bloc-notes n'a pu être mis à jour pour l'utilisateur avec l'id {id} et l'enquête avec l'id {inquiryId}.",
|
||||
notepad.UserId, notepad.InquiryId);
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Dto;
|
||||
using Model.OrderCriteria;
|
||||
using Shared;
|
||||
using Asp.Versioning;
|
||||
|
||||
namespace API.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Authorize]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
public class SolutionController : Controller
|
||||
{
|
||||
private readonly ISolutionService<SolutionDto> _solutionDataService;
|
||||
|
||||
private readonly ILogger<SolutionController> _logger;
|
||||
|
||||
public SolutionController(ISolutionService<SolutionDto> solutionDataService, ILogger<SolutionController> logger)
|
||||
{
|
||||
_solutionDataService = solutionDataService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("solution/{id:int}")]
|
||||
[ProducesResponseType(typeof(SolutionDto), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
public IActionResult GetSolutionByInquiryById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("[INFORMATION] L'enquête avec l'id {id} a été trouvé.", id);
|
||||
return Ok(_solutionDataService.GetSolutionByInquiryId(id));
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER app
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["API/API.csproj", "API/"]
|
||||
COPY ["DbContextLib/DbContextLib.csproj", "DbContextLib/"]
|
||||
COPY ["EntityFramework/Entities.csproj", "EntityFramework/"]
|
||||
COPY ["Dto/Dto.csproj", "Dto/"]
|
||||
COPY ["DbDataManager/DbDataManager.csproj", "DbDataManager/"]
|
||||
COPY ["Model/Model.csproj", "Model/"]
|
||||
COPY ["Shared/Shared.csproj", "Shared/"]
|
||||
COPY ["StubbedContextLib/StubbedContextLib.csproj", "StubbedContextLib/"]
|
||||
RUN dotnet restore "./API/./API.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/API"
|
||||
RUN dotnet build "./API.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENV ASPNETCORE_HTTP_PORTS=80
|
||||
ENV DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE=false
|
||||
ENTRYPOINT ["dotnet", "API.dll"]
|
@ -1,27 +0,0 @@
|
||||
using Dto;
|
||||
using Entities;
|
||||
using Model.OrderCriteria;
|
||||
using Shared;
|
||||
using Shared.Mapper;
|
||||
|
||||
namespace API.Service;
|
||||
|
||||
public class BlackListDataServiceAPI (IBlackListService<BlackListEntity> userService) : IBlackListService<BlackListDto>
|
||||
{
|
||||
public IEnumerable<BlackListDto> GetBannedUsers(int page, int number, BlackListOdrerCriteria orderCriteria) =>
|
||||
userService.GetBannedUsers(page, number, orderCriteria).Select(b => b.FromEntityToDto());
|
||||
|
||||
public int GetNumberOfBannedUsers() => userService.GetNumberOfBannedUsers();
|
||||
public BlackListDto? GetUserBannedByEmail(string email)
|
||||
{
|
||||
var res = userService.GetUserBannedByEmail(email);
|
||||
if (res == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return res.FromEntityToDto();
|
||||
}
|
||||
|
||||
public bool BanUser(string username) => userService.BanUser(username);
|
||||
public bool UnbanUser(string email) => userService.UnbanUser(email);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using Dto;
|
||||
using Entities;
|
||||
using Shared;
|
||||
|
||||
namespace API.Service;
|
||||
|
||||
public class InquiryTableDataServiceAPI(IInquiryTableService<InquiryTableEntity> inquiryTableService) : IInquiryTableService<InquiryTableDto>
|
||||
{
|
||||
public string GetDatabaseNameByInquiryId(int id)
|
||||
{
|
||||
return inquiryTableService.GetDatabaseNameByInquiryId(id);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
using Dto;
|
||||
using Entities;
|
||||
using Shared;
|
||||
using Shared.Mapper;
|
||||
|
||||
namespace API.Service;
|
||||
|
||||
public class NotepadDataServiceAPI(INotepadService<NotepadEntity> notepadService) : INotepadService<NotepadDto>
|
||||
{
|
||||
public NotepadDto GetNotepadFromUserAndInquiryId(int userId, int inquiryId)
|
||||
{
|
||||
return notepadService.GetNotepadFromUserAndInquiryId(userId, inquiryId).FromEntityToDto();
|
||||
}
|
||||
|
||||
public void SetNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||
{
|
||||
notepadService.SetNotepadFromUserAndInquiryId(userId,inquiryId,notes);
|
||||
}
|
||||
|
||||
public void UpdateNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||
{
|
||||
notepadService.UpdateNotepadFromUserAndInquiryId(userId,inquiryId,notes);
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using Dto;
|
||||
using Entities;
|
||||
using Shared;
|
||||
using Shared.Mapper;
|
||||
|
||||
namespace API.Service;
|
||||
|
||||
public class SolutionDataServiceAPI(ISolutionService<SolutionEntity> solutionService) : ISolutionService<SolutionDto>
|
||||
{
|
||||
public SolutionDto GetSolutionByInquiryId(int id)
|
||||
{
|
||||
return solutionService.GetSolutionByInquiryId(id).FromEntityToDto();
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
using DbContextLib;
|
||||
using Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Model.OrderCriteria;
|
||||
using Shared;
|
||||
|
||||
namespace DbDataManager.Service;
|
||||
|
||||
public class BlackListDataService : IBlackListService<BlackListEntity>
|
||||
{
|
||||
private UserDbContext DbContext { get; set; }
|
||||
|
||||
public BlackListDataService(UserDbContext context)
|
||||
{
|
||||
DbContext = context;
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public int GetNumberOfBannedUsers()
|
||||
{
|
||||
return DbContext.BlackLists.Count();
|
||||
}
|
||||
public IEnumerable<BlackListEntity> GetBannedUsers(int page, int number, BlackListOdrerCriteria orderCriteria)
|
||||
{
|
||||
if (page <= 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
|
||||
if (number <= 0)
|
||||
{
|
||||
number = 10;
|
||||
}
|
||||
IQueryable<BlackListEntity> query = DbContext.BlackLists.Skip((page - 1) * number).Take(number);
|
||||
switch (orderCriteria)
|
||||
{
|
||||
case BlackListOdrerCriteria.None:
|
||||
break;
|
||||
case BlackListOdrerCriteria.ByEmail:
|
||||
query = query.OrderBy(s => s.Email);
|
||||
break;
|
||||
case BlackListOdrerCriteria.ByExpirationDate:
|
||||
query = query.OrderBy(s => s.ExpirationDate);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
var blackList = query.ToList();
|
||||
return blackList;
|
||||
}
|
||||
public BlackListEntity? GetUserBannedByEmail(string email)
|
||||
{
|
||||
var blackListEntity = DbContext.BlackLists.FirstOrDefault(b => b.Email == email);
|
||||
return blackListEntity;
|
||||
}
|
||||
|
||||
public bool BanUser(string username)
|
||||
{
|
||||
var userEntity = DbContext.Users.FirstOrDefault(u => u.Username == username);
|
||||
if (userEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DbContext.BlackLists.Add(new BlackListEntity
|
||||
{ Email = userEntity.Email, ExpirationDate = DateOnly.FromDateTime(DateTime.Now.AddYears(2)) });
|
||||
DbContext.Users.Remove(userEntity);
|
||||
DbContext.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool UnbanUser(string email)
|
||||
{
|
||||
var blackListEntity = DbContext.BlackLists.FirstOrDefault(b => b.Email == email);
|
||||
if (blackListEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DbContext.BlackLists.Remove(blackListEntity);
|
||||
DbContext.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
using DbContextLib;
|
||||
using Entities;
|
||||
using Shared;
|
||||
|
||||
namespace DbDataManager.Service;
|
||||
|
||||
public class InquiryTableDataService : IInquiryTableService<InquiryTableEntity>
|
||||
{
|
||||
private UserDbContext DbContext { get; set; }
|
||||
|
||||
public InquiryTableDataService(UserDbContext context)
|
||||
{
|
||||
DbContext = context;
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public string GetDatabaseNameByInquiryId(int id)
|
||||
{
|
||||
var inquiryTable = DbContext.InquiryTables.FirstOrDefault(i => i.OwnerId == id);
|
||||
if (inquiryTable == null)
|
||||
{
|
||||
throw new ArgumentException($"Erreur, impossible de trouver l'objet InquiryTable pour l'enquête d'id {id}",
|
||||
nameof(id));
|
||||
}
|
||||
return inquiryTable.DatabaseName;
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
using DbContextLib;
|
||||
using Entities;
|
||||
using Shared;
|
||||
|
||||
namespace DbDataManager.Service;
|
||||
|
||||
public class NotepadDataService : INotepadService<NotepadEntity>
|
||||
{
|
||||
private UserDbContext DbContext { get; set; }
|
||||
|
||||
public NotepadDataService(UserDbContext context)
|
||||
{
|
||||
DbContext = context;
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
public NotepadEntity GetNotepadFromUserAndInquiryId(int userId, int inquiryId)
|
||||
{
|
||||
var user = DbContext.Users.FirstOrDefault(u => u.Id == userId);
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentException("Erreur, aucun utilisateur ne possède l'ID fourni");
|
||||
}
|
||||
var inquiry = DbContext.Inquiries.FirstOrDefault(i => i.Id == inquiryId);
|
||||
if (inquiry == null)
|
||||
{
|
||||
throw new ArgumentException("Erreur, aucune enquête ne possède l'ID fourni");
|
||||
}
|
||||
var notepad = DbContext.Notepads.FirstOrDefault(n => n.UserId == userId && n.InquiryId == inquiryId);
|
||||
if (notepad == null)
|
||||
{
|
||||
throw new ArgumentException("Erreur, aucun bloc-notes n'existe pour l'utilisateur et l'enquête donnés");
|
||||
}
|
||||
return notepad;
|
||||
}
|
||||
|
||||
public void SetNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||
{
|
||||
var user = DbContext.Users.FirstOrDefault(u => u.Id == userId);
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentException("Erreur, aucun utilisateur ne possède l'ID fourni");
|
||||
}
|
||||
var inquiry = DbContext.Inquiries.FirstOrDefault(i => i.Id == inquiryId);
|
||||
if (inquiry == null)
|
||||
{
|
||||
throw new ArgumentException("Erreur, aucune enquête ne possède l'ID fourni");
|
||||
}
|
||||
var notepad = DbContext.Notepads.FirstOrDefault(n => n.UserId == userId && n.InquiryId == inquiryId);
|
||||
if (notepad != null)
|
||||
{
|
||||
notepad.Notes = notes;
|
||||
//throw new ArgumentException("Erreur, un bloc-notes existe déjà pour l'utilisateur et l'enquête donnée");
|
||||
}
|
||||
else
|
||||
{
|
||||
DbContext.Notepads.Add(new NotepadEntity { UserId = userId, InquiryId = inquiryId, Notes = notes });
|
||||
}
|
||||
|
||||
DbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void UpdateNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||
{
|
||||
var notepad = GetNotepadFromUserAndInquiryId(userId, inquiryId);
|
||||
notepad.Notes = notes;
|
||||
DbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using DbContextLib;
|
||||
using Entities;
|
||||
using Shared;
|
||||
|
||||
namespace DbDataManager.Service;
|
||||
|
||||
public class SolutionDataService : ISolutionService<SolutionEntity>
|
||||
{
|
||||
private UserDbContext DbContext { get; set; }
|
||||
|
||||
public SolutionDataService(UserDbContext context)
|
||||
{
|
||||
DbContext = context;
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public SolutionEntity GetSolutionByInquiryId(int id)
|
||||
{
|
||||
var solution = DbContext.Solutions.FirstOrDefault(s => s.OwnerId == id);
|
||||
if (solution == null)
|
||||
{
|
||||
throw new ArgumentException($"Impossible de trouver la solution pour l'enquête d'id {id}", nameof(id));
|
||||
}
|
||||
return solution;
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace Model.OrderCriteria;
|
||||
|
||||
public enum BlackListOdrerCriteria
|
||||
{
|
||||
None, ByEmail, ByExpirationDate
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using Model.OrderCriteria;
|
||||
|
||||
namespace Shared;
|
||||
|
||||
public interface IBlackListService<TBlackList>
|
||||
{
|
||||
public IEnumerable<TBlackList> GetBannedUsers(int page, int number, BlackListOdrerCriteria orderCriteria);
|
||||
public int GetNumberOfBannedUsers();
|
||||
public TBlackList? GetUserBannedByEmail(string email);
|
||||
public bool BanUser(string username);
|
||||
public bool UnbanUser(string email);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace Shared;
|
||||
|
||||
public interface IInquiryTableService<TInquiryTable>
|
||||
{
|
||||
public string GetDatabaseNameByInquiryId(int id);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Shared;
|
||||
|
||||
public interface INotepadService<TNotepad>
|
||||
{
|
||||
public TNotepad GetNotepadFromUserAndInquiryId(int userId, int inquiryId);
|
||||
|
||||
public void SetNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes);
|
||||
|
||||
public void UpdateNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace Shared;
|
||||
|
||||
public interface ISolutionService<TSolution>
|
||||
{
|
||||
public TSolution GetSolutionByInquiryId(int id);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using Dto;
|
||||
using Entities;
|
||||
using Model;
|
||||
|
||||
namespace Shared.Mapper;
|
||||
|
||||
public static class ContentLessonMapper
|
||||
{
|
||||
public static ContentLessonDto FromEntityToDto(this ContentLessonEntity entity)
|
||||
{
|
||||
return new ContentLessonDto(entity.Id, entity.ContentContent, entity.ContentTitle, entity.LessonId);
|
||||
}
|
||||
}
|
@ -1,195 +0,0 @@
|
||||
using API.Controllers;
|
||||
using Dto;
|
||||
using Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Model.OrderCriteria;
|
||||
using Moq;
|
||||
using Shared;
|
||||
using TestAPI.Extensions;
|
||||
|
||||
namespace TestAPI;
|
||||
|
||||
public class BlackListUnitTest
|
||||
{
|
||||
private readonly Mock<IBlackListService<BlackListDto>> _blackListService;
|
||||
|
||||
public BlackListUnitTest()
|
||||
{
|
||||
_blackListService = new Mock<IBlackListService<BlackListDto>>();
|
||||
}
|
||||
[Fact]
|
||||
public void IsBanned()
|
||||
{
|
||||
_blackListService.Setup(x => x.GetUserBannedByEmail("email@example.com"))
|
||||
.Returns(new BlackListDto { Email = "email@example.com", ExpirationDate = DateOnly.FromDateTime(DateTime.Now)});
|
||||
var usersController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
var result = usersController.GetUserBannedByEmail("email@example.com");
|
||||
Assert.Equal(typeof(OkObjectResult), result.GetType());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsBannedNotFound()
|
||||
{
|
||||
_blackListService.Setup(x => x.GetUserBannedByEmail("example@notfound.com"))
|
||||
.Returns<BlackListDto?>(null);
|
||||
var usersController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
var result = usersController.GetUserBannedByEmail("example@notfound.com");
|
||||
Assert.Equal(typeof(NotFoundObjectResult), result.GetType());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BanUser()
|
||||
{
|
||||
_blackListService.Setup(x => x.BanUser("Test1"))
|
||||
.Returns(true);
|
||||
var usersController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var userResult = usersController.BanUser("Test1");
|
||||
Assert.Equal(typeof(OkObjectResult), userResult.GetType());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BanUserNotFound()
|
||||
{
|
||||
_blackListService.Setup(x => x.BanUser("Test1"))
|
||||
.Returns(true);
|
||||
var usersController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var userResult = usersController.BanUser("Test42");
|
||||
Assert.Equal(typeof(NotFoundResult), userResult.GetType());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnbanUser()
|
||||
{
|
||||
_blackListService.Setup(x => x.UnbanUser("example@email.com"))
|
||||
.Returns(true);
|
||||
var usersController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var userResult = usersController.UnbanUser("example@email.com");
|
||||
Assert.Equal(typeof(OkObjectResult), userResult.GetType());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnbanUserNotFound()
|
||||
{
|
||||
_blackListService.Setup(x => x.UnbanUser("example@email.com"))
|
||||
.Returns(false);
|
||||
var usersController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var userResult = usersController.UnbanUser("example@email.com");
|
||||
Assert.Equal(typeof(NotFoundResult), userResult.GetType());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetBannedUsers_NoneOrderCriteria()
|
||||
{
|
||||
_blackListService.Setup(x => x.GetBannedUsers(1,10,BlackListOdrerCriteria.None))
|
||||
.Returns(new List<BlackListDto>()
|
||||
{
|
||||
new BlackListDto { Email = "example1@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) },
|
||||
new BlackListDto { Email = "example2@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) },
|
||||
new BlackListDto { Email = "example3@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) }
|
||||
});
|
||||
var blackListController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var result = blackListController.GetBannedUsers(1,10,BlackListOdrerCriteria.None);
|
||||
Assert.Equal(typeof(OkObjectResult), result.GetType());
|
||||
if (result is OkObjectResult okObjectResult)
|
||||
{
|
||||
var valeur = okObjectResult.Value;
|
||||
|
||||
Assert.NotNull(valeur);
|
||||
Assert.Equal(GetBlackList().ToString(), valeur.ToString());
|
||||
Assert.True(GetBlackList().SequenceEqual(valeur as IEnumerable<BlackListDto>, new BlackListDtoEqualityComparer()));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetBannedUsers_OrderByEmail()
|
||||
{
|
||||
_blackListService.Setup(x => x.GetBannedUsers(1,10,BlackListOdrerCriteria.ByEmail))
|
||||
.Returns(new List<BlackListDto>()
|
||||
{
|
||||
new BlackListDto { Email = "example1@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) },
|
||||
new BlackListDto { Email = "example2@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) },
|
||||
new BlackListDto { Email = "example3@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) }
|
||||
});
|
||||
var blackListController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var result = blackListController.GetBannedUsers(1,10,BlackListOdrerCriteria.ByEmail);
|
||||
Assert.Equal(typeof(OkObjectResult), result.GetType());
|
||||
if (result is OkObjectResult okObjectResult)
|
||||
{
|
||||
var valeur = okObjectResult.Value;
|
||||
|
||||
Assert.NotNull(valeur);
|
||||
Assert.Equal(GetBlackList().ToString(), valeur.ToString());
|
||||
Assert.True(GetBlackList().SequenceEqual(valeur as IEnumerable<BlackListDto>, new BlackListDtoEqualityComparer()));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetBannedUsers_OrderedByExpirationDate()
|
||||
{
|
||||
_blackListService.Setup(x => x.GetBannedUsers(1,10,BlackListOdrerCriteria.ByExpirationDate))
|
||||
.Returns(new List<BlackListDto>()
|
||||
{
|
||||
new BlackListDto { Email = "example1@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) },
|
||||
new BlackListDto { Email = "example2@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) },
|
||||
new BlackListDto { Email = "example3@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) }
|
||||
});
|
||||
var blackListController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var result = blackListController.GetBannedUsers(1,10,BlackListOdrerCriteria.ByExpirationDate);
|
||||
Assert.Equal(typeof(OkObjectResult), result.GetType());
|
||||
if (result is OkObjectResult okObjectResult)
|
||||
{
|
||||
var valeur = okObjectResult.Value;
|
||||
|
||||
Assert.NotNull(valeur);
|
||||
Assert.Equal(GetBlackList().ToString(), valeur.ToString());
|
||||
Assert.True(GetBlackList().SequenceEqual(valeur as IEnumerable<BlackListDto>, new BlackListDtoEqualityComparer()));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Get_0_BannedUsers_OrderedByNone()
|
||||
{
|
||||
_blackListService.Setup(x => x.GetBannedUsers(1, 10, BlackListOdrerCriteria.None))
|
||||
.Returns(new List<BlackListDto>());
|
||||
var blackListController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var result = blackListController.GetBannedUsers(1, 10, BlackListOdrerCriteria.None);
|
||||
Assert.Equal(typeof(StatusCodeResult), result.GetType());
|
||||
if (result is NotFoundObjectResult notFoundObjectResult)
|
||||
{
|
||||
var valeur = notFoundObjectResult.Value;
|
||||
|
||||
Assert.NotNull(valeur);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetNbBannedUsers()
|
||||
{
|
||||
_blackListService.Setup(x => x.GetNumberOfBannedUsers())
|
||||
.Returns(10);
|
||||
var usersController = new BlackListController(new NullLogger<UsersController>(), _blackListService.Object);
|
||||
|
||||
var userResult = usersController.GetNumberOfBannedUsers();
|
||||
Assert.Equal(typeof(OkObjectResult), userResult.GetType());
|
||||
Assert.Equal(10, ((KeyValuePair<string,int>)(userResult as OkObjectResult).Value).Value);
|
||||
}
|
||||
|
||||
private IEnumerable<BlackListDto> GetBlackList()
|
||||
{
|
||||
return new List<BlackListDto>()
|
||||
{
|
||||
new BlackListDto { Email = "example1@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) },
|
||||
new BlackListDto { Email = "example2@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) },
|
||||
new BlackListDto { Email = "example3@email.com" , ExpirationDate = DateOnly.FromDateTime(DateTime.Now) }
|
||||
};
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
using Dto;
|
||||
|
||||
namespace TestAPI.Extensions;
|
||||
|
||||
public class BlackListDtoEqualityComparer : EqualityComparer<BlackListDto>
|
||||
{
|
||||
public override bool Equals(BlackListDto x, BlackListDto y)
|
||||
{
|
||||
return x.Email == y.Email;
|
||||
}
|
||||
|
||||
public override int GetHashCode(BlackListDto obj)
|
||||
{
|
||||
return obj.Email.GetHashCode();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue