Compare commits
318 Commits
crud/secur
...
master
@ -0,0 +1,93 @@
|
|||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: API_SQLuedo
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
|
commands:
|
||||||
|
- cd API_SQLuedo/
|
||||||
|
- dotnet restore API_SQLuedo.sln
|
||||||
|
- dotnet build API_SQLuedo.sln -c Release --no-restore
|
||||||
|
|
||||||
|
- name: tests
|
||||||
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
|
commands:
|
||||||
|
- cd API_SQLuedo/
|
||||||
|
- dotnet restore API_SQLuedo.sln
|
||||||
|
- dotnet test API_SQLuedo.sln -c Release --no-build --no-restore
|
||||||
|
depends_on: [build]
|
||||||
|
|
||||||
|
- name: code-inspection
|
||||||
|
image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet8
|
||||||
|
secrets: [SECRET_SONAR_LOGIN]
|
||||||
|
environment:
|
||||||
|
sonar_host: https://codefirst.iut.uca.fr/sonar/
|
||||||
|
sonar_token:
|
||||||
|
from_secret: SECRET_SONAR_LOGIN
|
||||||
|
project_key: API_SQLuedo
|
||||||
|
coverage_exclusions: "**/Test*/**,**/*Context*/**,**/Program.cs,**/Migrations/**"
|
||||||
|
commands:
|
||||||
|
- cd API_SQLuedo/
|
||||||
|
- dotnet restore API_SQLuedo.sln
|
||||||
|
- dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token}
|
||||||
|
- dotnet build API_SQLuedo.sln -c Release --no-restore
|
||||||
|
- dotnet test API_SQLuedo.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage"
|
||||||
|
- reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport"
|
||||||
|
- dotnet publish API_SQLuedo.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release
|
||||||
|
- dotnet sonarscanner end /d:sonar.login=$${sonar_token}
|
||||||
|
depends_on: [build]
|
||||||
|
|
||||||
|
- name: deploy-sqluedo-db
|
||||||
|
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
|
||||||
|
environment:
|
||||||
|
IMAGENAME: postgres:16.2
|
||||||
|
CONTAINERNAME: sqluedo-db
|
||||||
|
COMMAND: create
|
||||||
|
OVERWRITE: true
|
||||||
|
PRIVATE: true
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_POSTGRES_USER:
|
||||||
|
from_secret: db_username
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_POSTGRES_PASSWORD:
|
||||||
|
from_secret: db_password
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_POSTGRES_DB:
|
||||||
|
from_secret: db_database
|
||||||
|
ADMINS: erwanmenager,maximesapountzis,johnnyratton,victorgaborit,clementchieu
|
||||||
|
depends_on: [tests]
|
||||||
|
|
||||||
|
# Build and push API image
|
||||||
|
- name: api-image-build-and-push
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
dockerfile: API_SQLuedo/API/Dockerfile
|
||||||
|
context: API_SQLuedo/
|
||||||
|
registry: hub.codefirst.iut.uca.fr
|
||||||
|
repo: hub.codefirst.iut.uca.fr/johnny.ratton/api_sqluedo
|
||||||
|
mirror: https://proxy.iut.uca.fr:8443
|
||||||
|
username:
|
||||||
|
from_secret: secret_registry_username
|
||||||
|
password:
|
||||||
|
from_secret: secret_registry_password
|
||||||
|
|
||||||
|
# Deploy API
|
||||||
|
- name: deploy-api-from-image
|
||||||
|
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
|
||||||
|
environment:
|
||||||
|
IMAGENAME: hub.codefirst.iut.uca.fr/johnny.ratton/api_sqluedo:latest
|
||||||
|
CONTAINERNAME: sqluedo-api
|
||||||
|
COMMAND: create
|
||||||
|
OVERWRITE: true
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_DB_HOST:
|
||||||
|
from_secret: db_host
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_DB_USER:
|
||||||
|
from_secret: db_username
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_DB_PASSWORD:
|
||||||
|
from_secret: db_password
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_DB_DATABASE:
|
||||||
|
from_secret: db_database
|
||||||
|
ADMINS: erwanmenager,maximesapountzis,johnnyratton,victorgaborit,clementchieu
|
||||||
|
depends_on: [ api-image-build-and-push, deploy-sqluedo-db ]
|
@ -0,0 +1,30 @@
|
|||||||
|
**/.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/**
|
@ -0,0 +1,94 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
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"]
|
@ -0,0 +1,27 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace Model.OrderCriteria;
|
||||||
|
|
||||||
|
public enum BlackListOdrerCriteria
|
||||||
|
{
|
||||||
|
None, ByEmail, ByExpirationDate
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
namespace Model.OrderCriteria;
|
||||||
|
|
||||||
|
public enum UserOrderCriteria
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
ById,
|
||||||
|
ByUsername,
|
||||||
|
ByEmail,
|
||||||
|
ByIsAdmin
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
namespace Model.OrderCriteria;
|
||||||
|
|
||||||
|
public enum InquiryOrderCriteria
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
ByTitle,
|
||||||
|
ByDescription,
|
||||||
|
ByIsUser,
|
||||||
|
ById
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
namespace Model.OrderCriteria;
|
||||||
|
|
||||||
|
public enum LessonOrderCriteria
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
ByTitle,
|
||||||
|
ByLastPublisher,
|
||||||
|
ByLastEdit,
|
||||||
|
ById
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
namespace Model.OrderCriteria;
|
||||||
|
|
||||||
|
public enum ParagraphOrderCriteria
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
ByTitle,
|
||||||
|
ByContent,
|
||||||
|
ByInfo,
|
||||||
|
ByQuery,
|
||||||
|
ByComment
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace Model.OrderCriteria;
|
||||||
|
|
||||||
|
public enum SuccessOrderCriteria
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
ByUserId,
|
||||||
|
ByInquiryId,
|
||||||
|
ByIsFinished
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue