Compare commits
318 Commits
correction
...
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,235 @@
|
|||||||
|
using Dto;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Shared;
|
||||||
|
using Model.OrderCriteria;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[ApiController]
|
||||||
|
public class UsersController(ILogger<UsersController> logger, IUserService<UserDto> userService) : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet("users/{page:int}/{number:int}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 204)]
|
||||||
|
public IActionResult GetUsers(int page, int number, UserOrderCriteria orderCriteria)
|
||||||
|
{
|
||||||
|
var users = userService.GetUsers(page, number, orderCriteria).ToList();
|
||||||
|
if (users.Count == 0)
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
|
||||||
|
return StatusCode(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", users.Count);
|
||||||
|
return Ok(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("users/not-admin/{page:int}/{number:int}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 204)]
|
||||||
|
public IActionResult GetNotAdminUsers(int page, int number, UserOrderCriteria orderCriteria)
|
||||||
|
{
|
||||||
|
var users = userService.GetNotAdminUsers(page, number, orderCriteria).ToList();
|
||||||
|
if (users.Count == 0)
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
|
||||||
|
return StatusCode(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", users.Count);
|
||||||
|
return Ok(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("users/number")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 204)]
|
||||||
|
public IActionResult GetNumberOfUsers()
|
||||||
|
{
|
||||||
|
var users = userService.GetNumberOfUsers();
|
||||||
|
if (users == 0)
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
|
||||||
|
return StatusCode(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("[INFORMATION] {users} Utilisateur(s) trouvé(s)", users);
|
||||||
|
return Ok(new KeyValuePair<string, int>("nbUsers", users));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("user/{id:int}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult GetUserById(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id);
|
||||||
|
return Ok(userService.GetUserById(id));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("user/{username:alpha}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult GetUserByUsername(string username)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username);
|
||||||
|
return Ok(userService.GetUserByUsername(username));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {username}.", username);
|
||||||
|
return NotFound("Utilisateur non trouvé !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("user/email/{email}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult GetByEmail(string email)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.LogInformation("[INFORMATION] Utilisateur avec l'username {email} a été trouvé.", email);
|
||||||
|
return Ok(userService.GetUserByEmail(email));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {email}.", email);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("user/{id:int}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult DeleteUser(int id)
|
||||||
|
{
|
||||||
|
var success = userService.DeleteUser(id);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("user/username/{username:alpha}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult DeleteUserByUsername(string username)
|
||||||
|
{
|
||||||
|
var success = userService.DeleteUserByUsername(username);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
logger.LogInformation("[INFORMATION] L'utilisateur avec le pseudo {username} a été supprimé.",
|
||||||
|
username);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec le pseudo {username}.", username);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 201)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 409)]
|
||||||
|
[ProducesResponseType(typeof(string), 410)]
|
||||||
|
public IActionResult CreateUser([FromBody] UserDto dto)
|
||||||
|
{
|
||||||
|
if (dto.Username == null || dto.Password == null || dto.Email == null)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userService.IsEmailTaken(dto.Email))
|
||||||
|
{
|
||||||
|
return StatusCode(409, "Email déjà utilisé");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userService.IsUsernameTaken(dto.Username))
|
||||||
|
{
|
||||||
|
return StatusCode(410, "Username déjà utilisé");
|
||||||
|
}
|
||||||
|
|
||||||
|
// return Ok(userService.CreateUser(username, password, email, isAdmin));
|
||||||
|
logger.LogInformation(
|
||||||
|
"[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}",
|
||||||
|
dto.Username, dto.Password, dto.Email, dto.IsAdmin);
|
||||||
|
return Created(nameof(GetUsers),
|
||||||
|
userService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("user/{id:int}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 409)]
|
||||||
|
public IActionResult UpdateUser(int id, [FromBody] UserDto userDto)
|
||||||
|
{
|
||||||
|
if (id != userDto.Id)
|
||||||
|
{
|
||||||
|
logger.LogError("[ERREUR] Problème ID - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id);
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
logger.LogError(
|
||||||
|
"[ERREUR] Problème controller - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id);
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userDto.Username == userService.GetUserById(id).Username && !userService.IsEmailTaken(userDto.Email)
|
||||||
|
|| (userDto.Email == userService.GetUserById(id).Email &&
|
||||||
|
!userService.IsUsernameTaken(userDto.Username))
|
||||||
|
|| (!userService.IsEmailTaken(userDto.Email) && !userService.IsUsernameTaken(userDto.Username)))
|
||||||
|
{
|
||||||
|
logger.LogInformation("[INFORMATION] La mise à jour de l'utilisateur avec l'id {id} a été effectuée",
|
||||||
|
id);
|
||||||
|
return Ok(userService.UpdateUser(id, userDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogError("[ERREUR] Email ou nom d'utilisateur déjà utilisé");
|
||||||
|
return StatusCode(409, "Email ou nom d'utilisateur déjà utilisé");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("user/promote/{id:int}")]
|
||||||
|
[ProducesResponseType(typeof(UserDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult PromoteUser(int id)
|
||||||
|
{
|
||||||
|
var userPromoted = userService.GetUserById(id);
|
||||||
|
if (userPromoted != null)
|
||||||
|
{
|
||||||
|
userPromoted = userService.PromoteUser(id);
|
||||||
|
logger.LogInformation("[INFORMATION] La promotion de l'utilisateur avec l'id {id} a été effectuée");
|
||||||
|
return Ok(userPromoted);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.LogInformation("[INFORMATION] La promotion de l'utilisateur avec l'id {id} à échouée",
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue