Compare commits

...

105 Commits

Author SHA1 Message Date
NottarJohnny 97e1ce5be4 Rectifications
continuous-integration/drone/push Build is failing Details
10 months ago
Clement CHIEU 5a4f97489d Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 656af96aca Migrations supprimées du coverage
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 2386dfd275 Merge pull request 'Controller modifié mais bug avec test unitaires en local' (#51) from modifGameController into master
continuous-integration/drone/push Build is passing Details
1 year ago
Johnny RATTON 3568fa86f7 Merge branch 'modifGameController' of codefirst.iut.uca.fr:johnny.ratton/API_SQLuedo into modifGameController
continuous-integration/drone/push Build is passing Details
1 year ago
Johnny RATTON 8965ed2dcb Modification du format de renvoi pour les tables et les colonnes
1 year ago
Johnny RATTON cbbcfa030a Merge branch 'master' into modifGameController
continuous-integration/drone/push Build is passing Details
1 year ago
Johnny RATTON 18b35ae3a5 Controller modifié mais bug avec test unitaires en local
continuous-integration/drone/push Build is passing Details
1 year ago
Johnny RATTON 203c3962b1 Merge pull request 'deploiement' (#50) from deploiement into master
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 3ba6b0c521 Merge resolved
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 6843d969e5 Suppression du authorize pour test
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU f2c3791778 Merge branch 'deploiement' of codefirst.iut.uca.fr:johnny.ratton/API_SQLuedo into deploiement
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 1aafe248cd Nouvelle migration de test
1 year ago
Clement CHIEU 2c802739b0 Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU a15752d650 Ajout nouvelle migration
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 3a6693646c Ajout des bonnes routes des controller
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 037d3c5d7d Suppression de la route de test du controller
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU a4f75d948a Ajout pour migrer vers la base de données
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 0f0615c5a2 Ajout migrations
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU edc2e1055c Mise à jour de '.gitignore'
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU ad41f1dd41 Ajout de la connection string pour le développement
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU b5db7d32d3 Merge branch 'deploiement' of codefirst.iut.uca.fr:johnny.ratton/API_SQLuedo into deploiement
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU c95dc22881 Ajout des bonnes variables d'environnement
1 year ago
Clement CHIEU c0763ae9a9 Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 570f89b4e3 Ajout de l'utilisation de la variable d'environnement au moment de la création de l'api
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 1ec09bdedf Modification du context utilisé
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 0e1f873c9f Vérification production
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 509b0d7565 Vérification production
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 9b30ed1234 Mise à jour de 'API_SQLuedo/API/Dockerfile'
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 590fa7d629 Mise à jour de 'API_SQLuedo/API/Dockerfile'
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 951ba2c941 Mise à jour de 'API_SQLuedo/API/Program.cs'
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 06640b6530 Mise à jour de 'API_SQLuedo/API/Properties/launchSettings.json'
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 5bcfae1b17 Mise à jour de 'README.md'
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS 2ea38ae774 Merge branch 'QueryController'
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS 1f7cba0b22 Correction d'un security review (Username et password en clean dans le code)
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS 8b1f2280bc 80 %?
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS f025be2bd0 Ajout de tests et tentative de Mock une ArgumentException
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS b19801a21c Ajout de quelques test pour le coverage à cause du QueryController
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS bfa15606f7 Suppression du test c'était nul
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS a10242ce28 Test pas sur la c'est du docker (ChatGPT)
continuous-integration/drone/push Build is failing Details
1 year ago
Maxime SAPOUNTZIS 8349f43f8a Fin des TU sur le QueryController
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS fd18a3e099 Début test Controller et suppression des test service car impossible
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS 6c7970fda7 Début Tests Unitaires sur le QueryService
continuous-integration/drone/push Build is failing Details
1 year ago
Johnny RATTON 18e7df02f3 Ajout des test unitaires pour les nouveaux controller et services
continuous-integration/drone/push Build is passing Details
1 year ago
Maxime SAPOUNTZIS 0161832d9e Ajout de getTables et getColumns pour le queryController
continuous-integration/drone/push Build is passing Details
1 year ago
Johnny RATTON 08bdb01b18 Merge branch 'master' of codefirst.iut.uca.fr:johnny.ratton/API_SQLuedo
1 year ago
Johnny RATTON f9f98e5705 Ajout des controller notepad, solution et des services associés + modification des controllers et services actuels pour se conformer au site PHP
1 year ago
Maxime SAPOUNTZIS 4e60b51384 Ajout QueryController et route ExecuteQuery qui renvoie un Json bien formaté bien mignon
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 92ea8b4686 Suppression des endpoints via kernel
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU ae50e581b1 Suppression du profil https
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU d980c972a4 Debug
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU ce8ab1cf36 Ajout de settings pour swagger
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 488ab60b9c Tentative d'ajout de route pour les inquiries
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU dd5d0e2231 Suppression des options de swaggerui
continuous-integration/drone/push Build was killed Details
1 year ago
Clement CHIEU b5e511efd0 Ajout de swagger vers la bonne route
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU ef14986ef7 Ajout du port 8080
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU a5538bdc50 Changement de port exposé
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 6f38993d98 Modification de la connection string
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 076deea67f Ajout debug string
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 15cd6fb57b Debug avec une autre env
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU e889bedde1 Ajout var env pour la connection string
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 6074be56d2 Ajout swagger hors developpement
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 44c858e749 Tentative d'ajout dans le appsettings
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 596fc3da4f Ajout port 8080
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 9897d78582 Ajout du port 5015 comme port exposé
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 81a387bab3 Debug
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 37547cc6da Suppression écoute port 8080 http
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 556d002f21 Suppression profil http
continuous-integration/drone/push Build was killed Details
1 year ago
Clement CHIEU af7ccc2eb4 Suppression de la variable d'envrionnement
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 3f955b9ae9 Debug pour le port de l'api
continuous-integration/drone/push Build was killed Details
1 year ago
Clement CHIEU aa8d36ab9b Ajout variable env
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 4fa79eabb2 Test de debug
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU 373ddaeb49 Ajout de create
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 5a6561d9b3 Ajout du mirror
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 1a2e5cd3de Ajout replace à la place de create
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 73e1aed1a0 Modification de l'image
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU d42f7acb9f Reproduction de la doc
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 77f28e7e1a Ajout du create à la fin
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU b39257855e Suppression du create
continuous-integration/drone/push Build is passing Details
1 year ago
Clement CHIEU cdc73c5716 Changement nom du container
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 30c9c158e0 Suppression espace blanc
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU bba3bdffef Refomat du code
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU b8ade38df4 Reformat du code et ajout entrypoint
continuous-integration/drone/push Build was killed Details
1 year ago
Clement CHIEU 284d380e99 Debug en supprimant la commande shell
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 3008b02f44 Ajout du bon chemin pour la commande dotnet et suppression du build
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 0c8003c4a3 Déplacement du fichier dll l'exécuter
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 2b149e3613 Ajout du bon chemin vers le secret
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU b2cf52502c Ajout du bon chemin vers le csproj
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 388b6edcfb Debug du chemin de copie
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU dce7d39ca4 Debug du chemin de copie
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 5ffdb91573 Ajout dockerignore pour tout copier avant le restore
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU f00adb968e Debug du chemin vers l'api
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 1b1ff43d33 Debug du chemin vers l'api
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 8a9cd73a1f Debug du chemin vers la copie des fichiers
continuous-integration/drone/push Build was killed Details
1 year ago
Clement CHIEU f6624b4b5b Debug du chemin vers le csproj
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 92d7f0556c Debug du chemin vers le csproj
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU fd1826d324 Debug du chemin vers le csproj
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 5ea246fb4c Debug du chemin vers le csproj
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 20b94d67bb Debug du chemin vers le csproj
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 156bf23d6b Debug du chemin vers le csproj
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 8734e08051 Debug du chemin vers le csproj
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 7fbe9d425c Debug du chemin
continuous-integration/drone/push Build was killed Details
1 year ago
Clement CHIEU 9a834c8300 Debug du chemin
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 2352ebc5b5 Ajustement du chemin vers le fichier
continuous-integration/drone/push Build is failing Details
1 year ago
Clement CHIEU 475de804eb Ajout du dockerfile et du déploiement de l'api
continuous-integration/drone/push Build is failing Details
1 year ago

@ -30,7 +30,7 @@ steps:
sonar_token:
from_secret: SECRET_SONAR_LOGIN
project_key: API_SQLuedo
coverage_exclusions: "**/Test*/**,**/*Context*/**,**/Program.cs"
coverage_exclusions: "**/Test*/**,**/*Context*/**,**/Program.cs,**/Migrations/**"
commands:
- cd API_SQLuedo/
- dotnet restore API_SQLuedo.sln
@ -57,3 +57,37 @@ steps:
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 ]

3
.gitignore vendored

@ -492,8 +492,7 @@ fabric.properties
.idea/caches/build_file_checksums.ser
# Migrations et fichiers db
**/Migrations/**
# Fichier db
*.db
/**/.idea/

@ -21,6 +21,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

@ -1,11 +1,9 @@
using Asp.Versioning;
using Dto;
using Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Model.OrderCriteria;
using Shared;
using Shared.Mapper;
namespace API.Controllers;
@ -13,7 +11,8 @@ namespace API.Controllers;
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class BlackListController(ILogger<UsersController> logger, IBlackListService<BlackListDto> blackListService) : ControllerBase
public class BlackListController(ILogger<UsersController> logger, IBlackListService<BlackListDto> blackListService)
: ControllerBase
{
[HttpGet("user/ban/{page:int}/{number:int}")]
[ProducesResponseType(typeof(IEnumerable<BlackListDto>), 200)]
@ -52,6 +51,7 @@ public class BlackListController(ILogger<UsersController> logger, IBlackListServ
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é !");
}

@ -5,8 +5,8 @@ using Model.OrderCriteria;
using Shared;
using Asp.Versioning;
namespace API.Controllers
{
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
@ -39,16 +39,6 @@ namespace API.Controllers
return Ok(_inquiryDataService.GetInquiries(page, number, orderCriteria));
}
[HttpGet("inquiries/number")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetNumberOfInquiries()
{
var nbInquiry = _inquiryDataService.GetNumberOfInquiries();
_logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry);
return Ok(new KeyValuePair<string,int>("nbInquiries", nbInquiry));
}
[HttpGet("inquiry/{id:int}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 404)]
@ -146,5 +136,14 @@ namespace API.Controllers
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
return NotFound();
}
[HttpGet("inquiries/number")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetNumberOfInquiries()
{
var nbInquiry = _inquiryDataService.GetNumberOfInquiries();
_logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry);
return Ok(new KeyValuePair<string, int>("nbInquiries", nbInquiry));
}
}

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

@ -1,13 +1,12 @@
using System.Net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Dto;
using Model.OrderCriteria;
using Shared;
using Asp.Versioning;
namespace API.Controllers
{
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
@ -40,6 +39,22 @@ namespace API.Controllers
return Ok(_lessonDataService.GetLessons(page, number, orderCriteria));
}
[HttpGet("lessons/number")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetNumberOfLessons()
{
var nbLesson = _lessonDataService.GetNumberOfLessons();
if (nbLesson == 0)
{
_logger.LogError("[ERREUR] Aucune leçon trouvée.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Leçon(s) trouvée(s)", nbLesson);
return Ok(new KeyValuePair<string,int>("nbLessons", nbLesson));
}
[HttpGet("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 404)]
@ -102,9 +117,11 @@ namespace API.Controllers
{
return BadRequest();
}
try
{
var createdLesson = _lessonDataService.CreateLesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit ?? DateOnly.FromDateTime(DateTime.Now));
var createdLesson = _lessonDataService.CreateLesson(dto.Id, dto.Title, dto.LastPublisher,
dto.LastEdit ?? DateOnly.FromDateTime(DateTime.Now));
if (createdLesson != null)
{
_logger.LogInformation(
@ -142,6 +159,7 @@ namespace API.Controllers
id);
return BadRequest();
}
if (LessonDto != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour de la leçon avec l'id {id} a été effectuée", id);
@ -152,4 +170,3 @@ namespace API.Controllers
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();
}
}
}

@ -5,8 +5,8 @@ using Model.OrderCriteria;
using Shared;
using Asp.Versioning;
namespace API.Controllers
{
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
@ -40,6 +40,22 @@ namespace API.Controllers
return Ok(_paragraphDataService.GetParagraphs(page, number, orderCriteria));
}
[HttpGet("paragraphs/lesson/{id:int}")]
[ProducesResponseType(typeof(IEnumerable<ParagraphDto>), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetParagraphsByLessonId(int id)
{
var paragraphs = _paragraphDataService.GetParagraphsByLessonId(id);
if (paragraphs.Count() == 0)
{
_logger.LogError("[ERREUR] Aucun paragraphe trouvé.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Paragraphe(s) trouvé(s)", paragraphs.Count());
return Ok(paragraphs);
}
[HttpGet("paragraph/{id:int}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 404)]
@ -97,7 +113,8 @@ namespace API.Controllers
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateParagraph([FromBody] ParagraphDto dto)
{
if (dto.ContentTitle == null || dto.ContentContent == null || dto.Title == null || dto.Content == null || dto.Info == null || dto.Query == null ||
if (dto.ContentTitle == null || dto.ContentContent == null || dto.Title == null || dto.Content == null ||
dto.Info == null || dto.Query == null ||
dto.Comment == null)
{
return BadRequest();
@ -107,7 +124,8 @@ namespace API.Controllers
"[INFORMATION] Un paragraphe a été créé : title - {title}, content - {content}, info - {info}, query - {query}, comment - {comment}",
dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment);
return Created(nameof(GetParagraphs),
_paragraphDataService.CreateParagraph(dto.ContentTitle, dto.ContentContent,dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment,
_paragraphDataService.CreateParagraph(dto.ContentTitle, dto.ContentContent, dto.Title, dto.Content,
dto.Info, dto.Query, dto.Comment,
dto.LessonId));
}
@ -140,4 +158,3 @@ namespace API.Controllers
return NotFound();
}
}
}

@ -0,0 +1,65 @@
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 QueryController(ILogger<QueryController> logger, IQueryService<QueryDto> queryService) : ControllerBase
{
[HttpPost("{database}/execute")]
[ProducesResponseType(typeof(QueryDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult ExecuteQuery([FromBody]string query, string database)
{
var queryResult = queryService.ExecuteQuery(query, database);
if (queryResult == null)
{
logger.LogError("[ERREUR] La requête n'a rien renvoyé.");
return StatusCode(204);
}
logger.LogInformation("[INFORMATION] La requête a renvoyé : {result} ", queryResult);
return Content(queryResult.Result, "application/json");
}
[HttpGet("{database}/Tables")]
[ProducesResponseType(typeof(QueryDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetTables(string database)
{
var queryResult = queryService.GetTables(database);
if (queryResult == null)
{
logger.LogError("[ERREUR] La requête n'a rien renvoyé.");
return StatusCode(204);
}
logger.LogInformation("[INFORMATION] La requête a renvoyé : {result} ", queryResult);
return Content(queryResult.Result, "application/json");
}
[HttpGet("{database}/{table}/Columns")]
[ProducesResponseType(typeof(QueryDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetColumns(string database,string table)
{
var queryResult = queryService.GetColumns(database,table);
if (queryResult == null)
{
logger.LogError("[ERREUR] La requête n'a rien renvoyé.");
return StatusCode(204);
}
logger.LogInformation("[INFORMATION] La requête a renvoyé : {result} ", queryResult);
return Content(queryResult.Result, "application/json");
}
}
}

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

@ -5,8 +5,8 @@ using Model.OrderCriteria;
using Shared;
using Asp.Versioning;
namespace API.Controllers
{
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
@ -204,4 +204,3 @@ namespace API.Controllers
}
}
}
}

@ -5,8 +5,8 @@ using Microsoft.AspNetCore.Mvc;
using Shared;
using Model.OrderCriteria;
namespace API.Controllers
{
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
@ -94,6 +94,7 @@ namespace API.Controllers
return NotFound("Utilisateur non trouvé !");
}
}
[HttpGet("user/email/{email}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
@ -137,7 +138,8 @@ namespace API.Controllers
var success = userService.DeleteUserByUsername(username);
if (success)
{
logger.LogInformation("[INFORMATION] L'utilisateur avec le pseudo {username} a été supprimé.", username);
logger.LogInformation("[INFORMATION] L'utilisateur avec le pseudo {username} a été supprimé.",
username);
return Ok();
}
else
@ -206,6 +208,7 @@ namespace API.Controllers
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é");
}
@ -230,4 +233,3 @@ namespace API.Controllers
}
}
}
}

@ -1,10 +1,7 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
@ -29,4 +26,6 @@ RUN dotnet publish "./API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:Use
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"]

@ -8,17 +8,21 @@ using Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Model;
using Shared;
using StubbedContextLib;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IQueryService<QueryDto>, QueryDataServiceApi>();
builder.Services.AddScoped<IUserService<UserEntity>, UserDataService>();
builder.Services.AddScoped<IUserService<UserDto>, UserDataServiceApi>();
@ -28,6 +32,12 @@ builder.Services.AddScoped<IBlackListService<BlackListDto>, BlackListDataService
builder.Services.AddScoped<IInquiryService<InquiryEntity>, InquiryDataService>();
builder.Services.AddScoped<IInquiryService<InquiryDto>, InquiryDataServiceApi>();
builder.Services.AddScoped<ISolutionService<SolutionEntity>, SolutionDataService>();
builder.Services.AddScoped<ISolutionService<SolutionDto>, SolutionDataServiceAPI>();
builder.Services.AddScoped<IInquiryTableService<InquiryTableEntity>, InquiryTableDataService>();
builder.Services.AddScoped<IInquiryTableService<InquiryTableDto>, InquiryTableDataServiceAPI>();
builder.Services.AddScoped<IParagraphService<ParagraphEntity>, ParagraphDataService>();
builder.Services.AddScoped<IParagraphService<ParagraphDto>, ParagraphDataServiceApi>();
@ -37,9 +47,34 @@ builder.Services.AddScoped<ISuccessService<SuccessDto>, SuccessDataServiceApi>()
builder.Services.AddScoped<ILessonService<LessonEntity>, LessonDataService>();
builder.Services.AddScoped<ILessonService<LessonDto>, LessonDataServiceApi>();
builder.Services.AddDbContext<DbContext, UserDbContext>();
builder.Services.AddDbContext<WebAPIDbContext>(options => options.UseInMemoryDatabase("appDb"));
builder.Services.AddIdentityApiEndpoints<IdentityUser>().AddEntityFrameworkStores<WebAPIDbContext>();
builder.Services.AddScoped<INotepadService<NotepadEntity>, NotepadDataService>();
builder.Services.AddScoped<INotepadService<NotepadDto>, NotepadDataServiceAPI>();
builder.Services.AddDbContext<DbContext,UserDbContext>((serviceProvider, options) =>
{
if (builder.Environment.IsProduction())
{
Console.WriteLine("I am in production mode");
var address = Environment.GetEnvironmentVariable("DB_HOST", EnvironmentVariableTarget.Process)
?? throw new ArgumentException("Missing DB_HOST environment variable");
var database = Environment.GetEnvironmentVariable("DB_DATABASE", EnvironmentVariableTarget.Process)
?? throw new ArgumentException("Missing DB_DATABASE environment variable");
var user = Environment.GetEnvironmentVariable("DB_USER", EnvironmentVariableTarget.Process)
?? throw new ArgumentException("Missing DB_USER environment variable");
var password = Environment.GetEnvironmentVariable("DB_PASSWORD", EnvironmentVariableTarget.Process)
?? throw new ArgumentException("Missing DB_PASSWORD environment variable");
var coString = $"Host={address};Database={database};Username={user};Password={password}";
options.UseNpgsql(coString);
}
else
{
Console.WriteLine("I am in development mode");
options.UseNpgsql("Host=localhost;Database=SQLuedo;Username=admin;Password=motdepasse");
}
});
builder.Services.AddIdentityApiEndpoints<IdentityUser>().AddEntityFrameworkStores<UserDbContext>();
builder.Services.AddAuthorization();
builder.Services.AddApiVersioning(o =>
@ -93,6 +128,13 @@ builder.Services.AddCors(options =>
});
});
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
builder.Services.AddSingleton(configuration);
var app = builder.Build();
@ -103,6 +145,10 @@ app.UseCors("AllowSpecificOrigin");
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
// Création base de données via les migrations
await using var dbContext = services.GetRequiredService<UserDbContext>();
//await dbContext.Database.MigrateAsync();
var userManager = services.GetRequiredService<UserManager<IdentityUser>>();
try
@ -128,12 +174,9 @@ using (var scope = app.Services.CreateScope())
}
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();

@ -16,7 +16,10 @@
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5015",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"DB_HOST": "localhost",
"DB_DATABASE": "SQLuedo",
"DB_USER": "admin",
"DB_PASSWORD" : "motdepasse"
}
},
"https": {
@ -24,17 +27,23 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7259;http://localhost:5015",
"applicationUrl": "https://localhost:8081;http://localhost:5015",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"DB_HOST": "localhost",
"DB_DATABASE": "SQLuedo",
"DB_USER": "admin",
"DB_PASSWORD" : "motdepasse"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"launchUrl": "containers/johnnyratton-sqluedo-api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"DB_HOST": "localhost",
"DB_DATABASE": "SQLuedo",
"DB_USER": "admin",
"DB_PASSWORD" : "motdepasse"
}
}
}

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

@ -14,6 +14,11 @@ public class LessonDataServiceApi(ILessonService<LessonEntity> lessonService) :
return lessonsEntities.Select(e => e.FromEntityToDto()).ToList();
}
public int GetNumberOfLessons()
{
return lessonService.GetNumberOfLessons();
}
public LessonDto GetLessonById(int id) => lessonService.GetLessonById(id).FromEntityToDto();
public LessonDto GetLessonByTitle(string title) => lessonService.GetLessonByTitle(title).FromEntityToDto();

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

@ -15,6 +15,11 @@ public class ParagraphDataServiceApi(IParagraphService<ParagraphEntity> paragrap
return paragraphsEntities.Select(e => e.FromEntityToDto()).ToList();
}
public IEnumerable<ParagraphDto> GetParagraphsByLessonId(int lessonId)
{
return paragraphService.GetParagraphsByLessonId(lessonId).Select(p => p.FromEntityToDto());
}
public ParagraphDto GetParagraphById(int id) => paragraphService.GetParagraphById(id).FromEntityToDto();
public ParagraphDto GetParagraphByTitle(string title) =>

@ -0,0 +1,176 @@
using Dto;
using Entities;
using Model.OrderCriteria;
using Npgsql;
using Shared;
using Shared.Mapper;
using Microsoft.Extensions.Configuration;
using System.Text;
using Newtonsoft.Json;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace API.Service;
public class QueryDataServiceApi : IQueryService<QueryDto>{
private readonly IConfiguration _configuration;
public QueryDataServiceApi(IConfiguration configuration)
{
_configuration = configuration;
}
public QueryDto ExecuteQuery(string query, string database)
{
string connectionString = _configuration.GetConnectionString("DefaultConnection");
connectionString = connectionString.Replace("{database}", database);
if (string.IsNullOrEmpty(database))
{
return new QueryDto { Result = "Le nom de la base de données est requis." };
}
try
{
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
connection.Open();
using (NpgsqlCommand command = new NpgsqlCommand(query, connection))
{
using (NpgsqlDataReader reader = command.ExecuteReader())
{
List<Dictionary<string, object>> resultList = new List<Dictionary<string, object>>();
List<string> columnNames = new List<string>();
for (int i = 0; i < reader.FieldCount; i++)
{
columnNames.Add(reader.GetName(i));
}
while (reader.Read())
{
Dictionary<string, object> row = new Dictionary<string, object>();
for (int i = 0; i < reader.FieldCount; i++)
{
row[columnNames[i]] = reader[i].ToString();
}
resultList.Add(row);
}
string resultJson = JsonConvert.SerializeObject(resultList);
QueryDto queryDto = new QueryDto { Result = resultJson };
return queryDto;
}
}
}
}
catch (Exception ex)
{
return new QueryDto { Result = ex.Message };
}
}
public QueryDto GetTables(string database)
{
string connectionString = _configuration.GetConnectionString("DefaultConnection");
connectionString = connectionString.Replace("{database}", database);
try
{
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
connection.Open();
using (NpgsqlCommand command = new NpgsqlCommand())
{
command.Connection = connection;
// Donner et exclure les bonnes permissions au rôle en question
// GRANT SELECT ON TABLE information_schema.tables TO votre_utilisateur;
// GRANT SELECT ON TABLE information_schema.columns TO votre_utilisateur;
// REVOKE ALL ON SCHEMA information_schema FROM PUBLIC;
command.CommandText =
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';";
using (NpgsqlDataReader reader = command.ExecuteReader())
{
List<string> tableNames = new List<string>();
while (reader.Read())
{
tableNames.Add(reader["table_name"].ToString());
}
List<object> tablesDict = new List<object>();
foreach (string tableName in tableNames)
{
tablesDict.Add(new { TableName = tableName});
}
string tablesJson = JsonConvert.SerializeObject(tablesDict);
QueryDto queryDto = new QueryDto { Result = tablesJson };
return queryDto;
}
}
}
}
catch (Exception ex)
{
return new QueryDto { Result = ex.Message };
}
}
public QueryDto GetColumns(string database, string table)
{
string connectionString = _configuration.GetConnectionString("DefaultConnection");
connectionString = connectionString.Replace("{database}", database);
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
connection.Open();
using (NpgsqlCommand command = new NpgsqlCommand())
{
command.Connection = connection;
// Donner et exclure les bonnes permissions au rôle en question
//GRANT SELECT ON TABLE information_schema.tables TO votre_utilisateur;
//GRANT SELECT ON TABLE information_schema.columns TO votre_utilisateur;
//REVOKE ALL ON SCHEMA information_schema FROM PUBLIC;
command.CommandText =
$"SELECT column_name FROM information_schema.columns WHERE table_name = '{table}';";
Console.WriteLine(command.CommandText);
using (NpgsqlDataReader reader = command.ExecuteReader())
{
List<string> columnsNames = new List<string>();
while (reader.Read())
{
columnsNames.Add(reader["column_name"].ToString());
}
/*List<object> columnsDict = new List<object>();
foreach (string colName in columnsNames)
{
columnsDict.Add(new { ColumnName = colName});
}*/
string tablesJson = JsonConvert.SerializeObject(columnsNames);
Console.WriteLine(tablesJson);
QueryDto queryDto = new QueryDto { Result = tablesJson };
return queryDto;
}
}
}
}
}

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

@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Username=admin;Password=motdepasse;Database={database}"
}
}

@ -0,0 +1,595 @@
// <auto-generated />
using System;
using DbContextLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DbContextLib.Migrations
{
[DbContext(typeof(UserDbContext))]
[Migration("20240403065352_v1")]
partial class v1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.HasSequence("ContentLessonEntitySequence");
modelBuilder.Entity("Entities.BlackListEntity", b =>
{
b.Property<string>("Email")
.HasColumnType("text");
b.Property<DateOnly>("ExpirationDate")
.HasColumnType("date");
b.HasKey("Email");
b.ToTable("BlackList");
});
modelBuilder.Entity("Entities.ContentLessonEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValueSql("nextval('\"ContentLessonEntitySequence\"')");
NpgsqlPropertyBuilderExtensions.UseSequence(b.Property<int>("Id"));
b.Property<string>("ContentContent")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContentTitle")
.IsRequired()
.HasColumnType("text");
b.Property<int>("LessonId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("LessonId");
b.ToTable((string)null);
b.UseTpcMappingStrategy();
});
modelBuilder.Entity("Entities.InquiryEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsUser")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Inquiries");
});
modelBuilder.Entity("Entities.InquiryTableEntity", b =>
{
b.Property<int>("OwnerId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("ConnectionInfo")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DatabaseName")
.IsRequired()
.HasColumnType("text");
b.HasKey("OwnerId");
b.ToTable("InquiryTable");
});
modelBuilder.Entity("Entities.LessonEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateOnly>("LastEdit")
.HasColumnType("date");
b.Property<string>("LastPublisher")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Lesson");
});
modelBuilder.Entity("Entities.NotepadEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("InquiryId")
.HasColumnType("integer");
b.Property<string>("Notes")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("InquiryId");
b.HasIndex("UserId");
b.ToTable("Notepad");
});
modelBuilder.Entity("Entities.SolutionEntity", b =>
{
b.Property<int>("OwnerId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("Explaination")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurderPlace")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurderWeapon")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurdererFirstName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurdererLastName")
.IsRequired()
.HasColumnType("text");
b.HasKey("OwnerId");
b.ToTable("Solution");
});
modelBuilder.Entity("Entities.SuccessEntity", b =>
{
b.Property<int>("InquiryId")
.HasColumnType("integer");
b.Property<bool>("IsFinished")
.HasColumnType("boolean");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("InquiryId");
b.HasIndex("UserId");
b.ToTable("Success");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsAdmin")
.HasColumnType("boolean");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("User");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Entities.ParagraphEntity", b =>
{
b.HasBaseType("Entities.ContentLessonEntity");
b.Property<string>("Comment")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Query")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.ToTable("Paragraph");
});
modelBuilder.Entity("Entities.ContentLessonEntity", b =>
{
b.HasOne("Entities.LessonEntity", "Lesson")
.WithMany("Content")
.HasForeignKey("LessonId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lesson");
});
modelBuilder.Entity("Entities.InquiryTableEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("Entities.NotepadEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Inquiry")
.WithMany()
.HasForeignKey("InquiryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Inquiry");
b.Navigation("User");
});
modelBuilder.Entity("Entities.SolutionEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("Entities.SuccessEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Inquiry")
.WithMany()
.HasForeignKey("InquiryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Inquiry");
b.Navigation("User");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.LessonEntity", b =>
{
b.Navigation("Content");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,452 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DbContextLib.Migrations
{
/// <inheritdoc />
public partial class v1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateSequence(
name: "ContentLessonEntitySequence");
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
UserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: true),
SecurityStamp = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "BlackList",
columns: table => new
{
Email = table.Column<string>(type: "text", nullable: false),
ExpirationDate = table.Column<DateOnly>(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BlackList", x => x.Email);
});
migrationBuilder.CreateTable(
name: "Inquiries",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
IsUser = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Inquiries", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Lesson",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: false),
LastPublisher = table.Column<string>(type: "text", nullable: false),
LastEdit = table.Column<DateOnly>(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Lesson", x => x.Id);
});
migrationBuilder.CreateTable(
name: "User",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Username = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
IsAdmin = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RoleId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "text", nullable: false),
ProviderKey = table.Column<string>(type: "text", nullable: false),
ProviderDisplayName = table.Column<string>(type: "text", nullable: true),
UserId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
RoleId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
LoginProvider = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Value = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "InquiryTable",
columns: table => new
{
OwnerId = table.Column<int>(type: "integer", nullable: false),
DatabaseName = table.Column<string>(type: "text", nullable: false),
ConnectionInfo = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_InquiryTable", x => x.OwnerId);
table.ForeignKey(
name: "FK_InquiryTable_Inquiries_OwnerId",
column: x => x.OwnerId,
principalTable: "Inquiries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Solution",
columns: table => new
{
OwnerId = table.Column<int>(type: "integer", nullable: false),
MurdererFirstName = table.Column<string>(type: "text", nullable: false),
MurdererLastName = table.Column<string>(type: "text", nullable: false),
MurderPlace = table.Column<string>(type: "text", nullable: false),
MurderWeapon = table.Column<string>(type: "text", nullable: false),
Explaination = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Solution", x => x.OwnerId);
table.ForeignKey(
name: "FK_Solution_Inquiries_OwnerId",
column: x => x.OwnerId,
principalTable: "Inquiries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Paragraph",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false, defaultValueSql: "nextval('\"ContentLessonEntitySequence\"')"),
ContentContent = table.Column<string>(type: "text", nullable: false),
ContentTitle = table.Column<string>(type: "text", nullable: false),
LessonId = table.Column<int>(type: "integer", nullable: false),
Title = table.Column<string>(type: "text", nullable: false),
Content = table.Column<string>(type: "text", nullable: false),
Info = table.Column<string>(type: "text", nullable: false),
Query = table.Column<string>(type: "text", nullable: false),
Comment = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Paragraph", x => x.Id);
table.ForeignKey(
name: "FK_Paragraph_Lesson_LessonId",
column: x => x.LessonId,
principalTable: "Lesson",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Notepad",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
InquiryId = table.Column<int>(type: "integer", nullable: false),
Notes = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Notepad", x => x.Id);
table.ForeignKey(
name: "FK_Notepad_Inquiries_InquiryId",
column: x => x.InquiryId,
principalTable: "Inquiries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Notepad_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Success",
columns: table => new
{
InquiryId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false),
IsFinished = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Success", x => x.InquiryId);
table.ForeignKey(
name: "FK_Success_Inquiries_InquiryId",
column: x => x.InquiryId,
principalTable: "Inquiries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Success_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId",
table: "AspNetRoleClaims",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "AspNetRoles",
column: "NormalizedName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AspNetUserClaims_UserId",
table: "AspNetUserClaims",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserLogins_UserId",
table: "AspNetUserLogins",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserRoles_RoleId",
table: "AspNetUserRoles",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "EmailIndex",
table: "AspNetUsers",
column: "NormalizedEmail");
migrationBuilder.CreateIndex(
name: "UserNameIndex",
table: "AspNetUsers",
column: "NormalizedUserName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Notepad_InquiryId",
table: "Notepad",
column: "InquiryId");
migrationBuilder.CreateIndex(
name: "IX_Notepad_UserId",
table: "Notepad",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Paragraph_LessonId",
table: "Paragraph",
column: "LessonId");
migrationBuilder.CreateIndex(
name: "IX_Success_UserId",
table: "Success",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AspNetRoleClaims");
migrationBuilder.DropTable(
name: "AspNetUserClaims");
migrationBuilder.DropTable(
name: "AspNetUserLogins");
migrationBuilder.DropTable(
name: "AspNetUserRoles");
migrationBuilder.DropTable(
name: "AspNetUserTokens");
migrationBuilder.DropTable(
name: "BlackList");
migrationBuilder.DropTable(
name: "InquiryTable");
migrationBuilder.DropTable(
name: "Notepad");
migrationBuilder.DropTable(
name: "Paragraph");
migrationBuilder.DropTable(
name: "Solution");
migrationBuilder.DropTable(
name: "Success");
migrationBuilder.DropTable(
name: "AspNetRoles");
migrationBuilder.DropTable(
name: "AspNetUsers");
migrationBuilder.DropTable(
name: "Lesson");
migrationBuilder.DropTable(
name: "Inquiries");
migrationBuilder.DropTable(
name: "User");
migrationBuilder.DropSequence(
name: "ContentLessonEntitySequence");
}
}
}

@ -0,0 +1,592 @@
// <auto-generated />
using System;
using DbContextLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DbContextLib.Migrations
{
[DbContext(typeof(UserDbContext))]
partial class UserDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.HasSequence("ContentLessonEntitySequence");
modelBuilder.Entity("Entities.BlackListEntity", b =>
{
b.Property<string>("Email")
.HasColumnType("text");
b.Property<DateOnly>("ExpirationDate")
.HasColumnType("date");
b.HasKey("Email");
b.ToTable("BlackList");
});
modelBuilder.Entity("Entities.ContentLessonEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValueSql("nextval('\"ContentLessonEntitySequence\"')");
NpgsqlPropertyBuilderExtensions.UseSequence(b.Property<int>("Id"));
b.Property<string>("ContentContent")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContentTitle")
.IsRequired()
.HasColumnType("text");
b.Property<int>("LessonId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("LessonId");
b.ToTable((string)null);
b.UseTpcMappingStrategy();
});
modelBuilder.Entity("Entities.InquiryEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsUser")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Inquiries");
});
modelBuilder.Entity("Entities.InquiryTableEntity", b =>
{
b.Property<int>("OwnerId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("ConnectionInfo")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DatabaseName")
.IsRequired()
.HasColumnType("text");
b.HasKey("OwnerId");
b.ToTable("InquiryTable");
});
modelBuilder.Entity("Entities.LessonEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateOnly>("LastEdit")
.HasColumnType("date");
b.Property<string>("LastPublisher")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Lesson");
});
modelBuilder.Entity("Entities.NotepadEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("InquiryId")
.HasColumnType("integer");
b.Property<string>("Notes")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("InquiryId");
b.HasIndex("UserId");
b.ToTable("Notepad");
});
modelBuilder.Entity("Entities.SolutionEntity", b =>
{
b.Property<int>("OwnerId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("Explaination")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurderPlace")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurderWeapon")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurdererFirstName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurdererLastName")
.IsRequired()
.HasColumnType("text");
b.HasKey("OwnerId");
b.ToTable("Solution");
});
modelBuilder.Entity("Entities.SuccessEntity", b =>
{
b.Property<int>("InquiryId")
.HasColumnType("integer");
b.Property<bool>("IsFinished")
.HasColumnType("boolean");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("InquiryId");
b.HasIndex("UserId");
b.ToTable("Success");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsAdmin")
.HasColumnType("boolean");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("User");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Entities.ParagraphEntity", b =>
{
b.HasBaseType("Entities.ContentLessonEntity");
b.Property<string>("Comment")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Query")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.ToTable("Paragraph");
});
modelBuilder.Entity("Entities.ContentLessonEntity", b =>
{
b.HasOne("Entities.LessonEntity", "Lesson")
.WithMany("Content")
.HasForeignKey("LessonId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lesson");
});
modelBuilder.Entity("Entities.InquiryTableEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("Entities.NotepadEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Inquiry")
.WithMany()
.HasForeignKey("InquiryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Inquiry");
b.Navigation("User");
});
modelBuilder.Entity("Entities.SolutionEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("Entities.SuccessEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Inquiry")
.WithMany()
.HasForeignKey("InquiryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Inquiry");
b.Navigation("User");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.LessonEntity", b =>
{
b.Navigation("Content");
});
#pragma warning restore 612, 618
}
}
}

@ -26,8 +26,8 @@ namespace DbContextLib
base.OnConfiguring(optionsBuilder);
if (!optionsBuilder.IsConfigured)
{
//optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_STRING", EnvironmentVariableTarget.Process));
optionsBuilder.UseNpgsql("Host=localhost;Database=SQLuedo;Username=admin;Password=motdepasse");
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CO_STRING", EnvironmentVariableTarget.Process));
//optionsBuilder.UseNpgsql("Host=localhost;Database=SQLuedo;Username=admin;Password=motdepasse");
}
}

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

@ -57,6 +57,11 @@ public class LessonDataService : ILessonService<LessonEntity>
return lessons;
}
public int GetNumberOfLessons()
{
return DbContext.Lessons.Count();
}
public LessonEntity GetLessonById(int id)
{
var lessonEntity = DbContext.Lessons.FirstOrDefault(u => u.Id == id);

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

@ -54,6 +54,17 @@ public class ParagraphDataService : IParagraphService<ParagraphEntity>
return paragraphs;
}
public IEnumerable<ParagraphEntity> GetParagraphsByLessonId(int lessonId)
{
var lesson = DbContext.Lessons.FirstOrDefault(l => l.Id == lessonId);
if (lesson == null)
{
throw new ArgumentException($"Erreur, la leçon ayant pour id {lessonId} est introuvable.");
}
var list = DbContext.Paragraphs.Where(p => p.LessonId == lessonId);
return list;
}
public ParagraphEntity GetParagraphById(int id)
{
var paragraphEntity = DbContext.Paragraphs.FirstOrDefault(u => u.Id == id);

@ -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,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dto
{
public class QueryDto
{
public string Result { get; set; }
}
}

@ -0,0 +1,6 @@
namespace Shared;
public interface IInquiryTableService<TInquiryTable>
{
public string GetDatabaseNameByInquiryId(int id);
}

@ -5,6 +5,7 @@ namespace Shared;
public interface ILessonService<TLesson>
{
public IEnumerable<TLesson> GetLessons(int page, int number, LessonOrderCriteria orderCriteria);
public int GetNumberOfLessons();
public TLesson GetLessonById(int id);
public TLesson GetLessonByTitle(string title);
public bool DeleteLesson(int id);

@ -0,0 +1,10 @@
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);
}

@ -5,6 +5,7 @@ namespace Shared
public interface IParagraphService<TParagraph>
{
public IEnumerable<TParagraph> GetParagraphs(int page, int number, ParagraphOrderCriteria orderCriteria);
public IEnumerable<TParagraph> GetParagraphsByLessonId(int lessonId);
public TParagraph GetParagraphById(int id);
public TParagraph GetParagraphByTitle(string title);
public bool DeleteParagraph(int id);

@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Mvc;
using Model.OrderCriteria;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dto;
namespace Shared
{
public interface IQueryService<TQuery>
{
public TQuery ExecuteQuery(string query, string database);
public QueryDto GetTables(string database);
public QueryDto GetColumns(string database,string table);
}
}

@ -0,0 +1,6 @@
namespace Shared;
public interface ISolutionService<TSolution>
{
public TSolution GetSolutionByInquiryId(int id);
}

@ -16,10 +16,6 @@ public static class LessonMapper
return new LessonDto(model.Id, model.Title, model.LastPublisher, model.LastEdit, model.Content.Select(c => c.FromEntityToDto()).ToList());
}
public static LessonDto FromEntityToDtoPost(this LessonEntity model)
{
return new LessonDto(model.Id, model.Title, model.LastPublisher, model.LastEdit);
}
public static LessonEntity FromModelToEntity(this Lesson model)
{

@ -0,0 +1,643 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using StubbedContextLib;
#nullable disable
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubbedContext))]
[Migration("20240624134431_Initial")]
partial class Initial
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.HasSequence("ContentLessonEntitySequence");
modelBuilder.Entity("Entities.BlackListEntity", b =>
{
b.Property<string>("Email")
.HasColumnType("text");
b.Property<DateOnly>("ExpirationDate")
.HasColumnType("date");
b.HasKey("Email");
b.ToTable("BlackList");
});
modelBuilder.Entity("Entities.ContentLessonEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValueSql("nextval('\"ContentLessonEntitySequence\"')");
NpgsqlPropertyBuilderExtensions.UseSequence(b.Property<int>("Id"));
b.Property<string>("ContentContent")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContentTitle")
.IsRequired()
.HasColumnType("text");
b.Property<int>("LessonId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("LessonId");
b.ToTable((string)null);
b.UseTpcMappingStrategy();
});
modelBuilder.Entity("Entities.InquiryEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsUser")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Inquiries");
});
modelBuilder.Entity("Entities.InquiryTableEntity", b =>
{
b.Property<int>("OwnerId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("ConnectionInfo")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DatabaseName")
.IsRequired()
.HasColumnType("text");
b.HasKey("OwnerId");
b.ToTable("InquiryTable");
});
modelBuilder.Entity("Entities.LessonEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateOnly>("LastEdit")
.HasColumnType("date");
b.Property<string>("LastPublisher")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Lesson");
});
modelBuilder.Entity("Entities.NotepadEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("InquiryId")
.HasColumnType("integer");
b.Property<string>("Notes")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("InquiryId");
b.HasIndex("UserId");
b.ToTable("Notepad");
});
modelBuilder.Entity("Entities.SolutionEntity", b =>
{
b.Property<int>("OwnerId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("Explaination")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurderPlace")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurderWeapon")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurdererFirstName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurdererLastName")
.IsRequired()
.HasColumnType("text");
b.HasKey("OwnerId");
b.ToTable("Solution");
});
modelBuilder.Entity("Entities.SuccessEntity", b =>
{
b.Property<int>("InquiryId")
.HasColumnType("integer");
b.Property<bool>("IsFinished")
.HasColumnType("boolean");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("InquiryId");
b.HasIndex("UserId");
b.ToTable("Success");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsAdmin")
.HasColumnType("boolean");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("Email")
.IsUnique();
b.HasIndex("Username")
.IsUnique();
b.ToTable("User");
b.HasData(
new
{
Id = 1,
Email = "Johnny.RATTON@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$7Dq.5Bf5WlHBMRqHBp5Ag.5PCCnvLrBXsuMGGJnV4l4WdngeDBpnW",
Username = "johnny"
},
new
{
Id = 2,
Email = "Maxime.SAPOUNTZIS@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$OT8g325JcE9mIdc.DiEKpem3kwNBdRcQ22vT2i5IB7KmfBfek4662",
Username = "maxime"
},
new
{
Id = 3,
Email = "Clement.CHIEU@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$Qc40bG8aCDvRSVjlWIn.1Orkd52fVMxBM2uQypVVwgu/mkeM8rnVK",
Username = "clement"
},
new
{
Id = 4,
Email = "Erwan.MENAGER@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$AW23BQcrS7d//LK0CtHuH.599OfYinEKCLkTz8Sbrtn.XYWE0u0BO",
Username = "erwan"
},
new
{
Id = 5,
Email = "Victor.GABORIT@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$ZOly/r95doGABtnypi8CAun1VnMRP1ct.idsUpXGe3pwjRYqv3ZQy",
Username = "victor"
});
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Entities.ParagraphEntity", b =>
{
b.HasBaseType("Entities.ContentLessonEntity");
b.Property<string>("Comment")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Query")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.ToTable("Paragraph");
});
modelBuilder.Entity("Entities.ContentLessonEntity", b =>
{
b.HasOne("Entities.LessonEntity", "Lesson")
.WithMany("Content")
.HasForeignKey("LessonId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lesson");
});
modelBuilder.Entity("Entities.InquiryTableEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("Entities.NotepadEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Inquiry")
.WithMany()
.HasForeignKey("InquiryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Inquiry");
b.Navigation("User");
});
modelBuilder.Entity("Entities.SolutionEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("Entities.SuccessEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Inquiry")
.WithMany()
.HasForeignKey("InquiryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Inquiry");
b.Navigation("User");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.LessonEntity", b =>
{
b.Navigation("Content");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,478 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateSequence(
name: "ContentLessonEntitySequence");
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
UserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: true),
SecurityStamp = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "BlackList",
columns: table => new
{
Email = table.Column<string>(type: "text", nullable: false),
ExpirationDate = table.Column<DateOnly>(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BlackList", x => x.Email);
});
migrationBuilder.CreateTable(
name: "Inquiries",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
IsUser = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Inquiries", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Lesson",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: false),
LastPublisher = table.Column<string>(type: "text", nullable: false),
LastEdit = table.Column<DateOnly>(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Lesson", x => x.Id);
});
migrationBuilder.CreateTable(
name: "User",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Username = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
IsAdmin = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RoleId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "text", nullable: false),
ProviderKey = table.Column<string>(type: "text", nullable: false),
ProviderDisplayName = table.Column<string>(type: "text", nullable: true),
UserId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
RoleId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
LoginProvider = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Value = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "InquiryTable",
columns: table => new
{
OwnerId = table.Column<int>(type: "integer", nullable: false),
DatabaseName = table.Column<string>(type: "text", nullable: false),
ConnectionInfo = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_InquiryTable", x => x.OwnerId);
table.ForeignKey(
name: "FK_InquiryTable_Inquiries_OwnerId",
column: x => x.OwnerId,
principalTable: "Inquiries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Solution",
columns: table => new
{
OwnerId = table.Column<int>(type: "integer", nullable: false),
MurdererFirstName = table.Column<string>(type: "text", nullable: false),
MurdererLastName = table.Column<string>(type: "text", nullable: false),
MurderPlace = table.Column<string>(type: "text", nullable: false),
MurderWeapon = table.Column<string>(type: "text", nullable: false),
Explaination = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Solution", x => x.OwnerId);
table.ForeignKey(
name: "FK_Solution_Inquiries_OwnerId",
column: x => x.OwnerId,
principalTable: "Inquiries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Paragraph",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false, defaultValueSql: "nextval('\"ContentLessonEntitySequence\"')"),
ContentContent = table.Column<string>(type: "text", nullable: false),
ContentTitle = table.Column<string>(type: "text", nullable: false),
LessonId = table.Column<int>(type: "integer", nullable: false),
Title = table.Column<string>(type: "text", nullable: false),
Content = table.Column<string>(type: "text", nullable: false),
Info = table.Column<string>(type: "text", nullable: false),
Query = table.Column<string>(type: "text", nullable: false),
Comment = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Paragraph", x => x.Id);
table.ForeignKey(
name: "FK_Paragraph_Lesson_LessonId",
column: x => x.LessonId,
principalTable: "Lesson",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Notepad",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
InquiryId = table.Column<int>(type: "integer", nullable: false),
Notes = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Notepad", x => x.Id);
table.ForeignKey(
name: "FK_Notepad_Inquiries_InquiryId",
column: x => x.InquiryId,
principalTable: "Inquiries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Notepad_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Success",
columns: table => new
{
InquiryId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false),
IsFinished = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Success", x => x.InquiryId);
table.ForeignKey(
name: "FK_Success_Inquiries_InquiryId",
column: x => x.InquiryId,
principalTable: "Inquiries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Success_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "User",
columns: new[] { "Id", "Email", "IsAdmin", "Password", "Username" },
values: new object[,]
{
{ 1, "Johnny.RATTON@etu.uca.fr", true, "$2a$10$7Dq.5Bf5WlHBMRqHBp5Ag.5PCCnvLrBXsuMGGJnV4l4WdngeDBpnW", "johnny" },
{ 2, "Maxime.SAPOUNTZIS@etu.uca.fr", true, "$2a$10$OT8g325JcE9mIdc.DiEKpem3kwNBdRcQ22vT2i5IB7KmfBfek4662", "maxime" },
{ 3, "Clement.CHIEU@etu.uca.fr", true, "$2a$10$Qc40bG8aCDvRSVjlWIn.1Orkd52fVMxBM2uQypVVwgu/mkeM8rnVK", "clement" },
{ 4, "Erwan.MENAGER@etu.uca.fr", true, "$2a$10$AW23BQcrS7d//LK0CtHuH.599OfYinEKCLkTz8Sbrtn.XYWE0u0BO", "erwan" },
{ 5, "Victor.GABORIT@etu.uca.fr", true, "$2a$10$ZOly/r95doGABtnypi8CAun1VnMRP1ct.idsUpXGe3pwjRYqv3ZQy", "victor" }
});
migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId",
table: "AspNetRoleClaims",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "AspNetRoles",
column: "NormalizedName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AspNetUserClaims_UserId",
table: "AspNetUserClaims",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserLogins_UserId",
table: "AspNetUserLogins",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserRoles_RoleId",
table: "AspNetUserRoles",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "EmailIndex",
table: "AspNetUsers",
column: "NormalizedEmail");
migrationBuilder.CreateIndex(
name: "UserNameIndex",
table: "AspNetUsers",
column: "NormalizedUserName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Notepad_InquiryId",
table: "Notepad",
column: "InquiryId");
migrationBuilder.CreateIndex(
name: "IX_Notepad_UserId",
table: "Notepad",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Paragraph_LessonId",
table: "Paragraph",
column: "LessonId");
migrationBuilder.CreateIndex(
name: "IX_Success_UserId",
table: "Success",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_User_Email",
table: "User",
column: "Email",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_User_Username",
table: "User",
column: "Username",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AspNetRoleClaims");
migrationBuilder.DropTable(
name: "AspNetUserClaims");
migrationBuilder.DropTable(
name: "AspNetUserLogins");
migrationBuilder.DropTable(
name: "AspNetUserRoles");
migrationBuilder.DropTable(
name: "AspNetUserTokens");
migrationBuilder.DropTable(
name: "BlackList");
migrationBuilder.DropTable(
name: "InquiryTable");
migrationBuilder.DropTable(
name: "Notepad");
migrationBuilder.DropTable(
name: "Paragraph");
migrationBuilder.DropTable(
name: "Solution");
migrationBuilder.DropTable(
name: "Success");
migrationBuilder.DropTable(
name: "AspNetRoles");
migrationBuilder.DropTable(
name: "AspNetUsers");
migrationBuilder.DropTable(
name: "Lesson");
migrationBuilder.DropTable(
name: "Inquiries");
migrationBuilder.DropTable(
name: "User");
migrationBuilder.DropSequence(
name: "ContentLessonEntitySequence");
}
}
}

@ -0,0 +1,640 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using StubbedContextLib;
#nullable disable
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubbedContext))]
partial class StubbedContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.HasSequence("ContentLessonEntitySequence");
modelBuilder.Entity("Entities.BlackListEntity", b =>
{
b.Property<string>("Email")
.HasColumnType("text");
b.Property<DateOnly>("ExpirationDate")
.HasColumnType("date");
b.HasKey("Email");
b.ToTable("BlackList");
});
modelBuilder.Entity("Entities.ContentLessonEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValueSql("nextval('\"ContentLessonEntitySequence\"')");
NpgsqlPropertyBuilderExtensions.UseSequence(b.Property<int>("Id"));
b.Property<string>("ContentContent")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContentTitle")
.IsRequired()
.HasColumnType("text");
b.Property<int>("LessonId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("LessonId");
b.ToTable((string)null);
b.UseTpcMappingStrategy();
});
modelBuilder.Entity("Entities.InquiryEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsUser")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Inquiries");
});
modelBuilder.Entity("Entities.InquiryTableEntity", b =>
{
b.Property<int>("OwnerId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("ConnectionInfo")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DatabaseName")
.IsRequired()
.HasColumnType("text");
b.HasKey("OwnerId");
b.ToTable("InquiryTable");
});
modelBuilder.Entity("Entities.LessonEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateOnly>("LastEdit")
.HasColumnType("date");
b.Property<string>("LastPublisher")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Lesson");
});
modelBuilder.Entity("Entities.NotepadEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("InquiryId")
.HasColumnType("integer");
b.Property<string>("Notes")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("InquiryId");
b.HasIndex("UserId");
b.ToTable("Notepad");
});
modelBuilder.Entity("Entities.SolutionEntity", b =>
{
b.Property<int>("OwnerId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("Explaination")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurderPlace")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurderWeapon")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurdererFirstName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MurdererLastName")
.IsRequired()
.HasColumnType("text");
b.HasKey("OwnerId");
b.ToTable("Solution");
});
modelBuilder.Entity("Entities.SuccessEntity", b =>
{
b.Property<int>("InquiryId")
.HasColumnType("integer");
b.Property<bool>("IsFinished")
.HasColumnType("boolean");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("InquiryId");
b.HasIndex("UserId");
b.ToTable("Success");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsAdmin")
.HasColumnType("boolean");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("Email")
.IsUnique();
b.HasIndex("Username")
.IsUnique();
b.ToTable("User");
b.HasData(
new
{
Id = 1,
Email = "Johnny.RATTON@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$7Dq.5Bf5WlHBMRqHBp5Ag.5PCCnvLrBXsuMGGJnV4l4WdngeDBpnW",
Username = "johnny"
},
new
{
Id = 2,
Email = "Maxime.SAPOUNTZIS@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$OT8g325JcE9mIdc.DiEKpem3kwNBdRcQ22vT2i5IB7KmfBfek4662",
Username = "maxime"
},
new
{
Id = 3,
Email = "Clement.CHIEU@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$Qc40bG8aCDvRSVjlWIn.1Orkd52fVMxBM2uQypVVwgu/mkeM8rnVK",
Username = "clement"
},
new
{
Id = 4,
Email = "Erwan.MENAGER@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$AW23BQcrS7d//LK0CtHuH.599OfYinEKCLkTz8Sbrtn.XYWE0u0BO",
Username = "erwan"
},
new
{
Id = 5,
Email = "Victor.GABORIT@etu.uca.fr",
IsAdmin = true,
Password = "$2a$10$ZOly/r95doGABtnypi8CAun1VnMRP1ct.idsUpXGe3pwjRYqv3ZQy",
Username = "victor"
});
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Entities.ParagraphEntity", b =>
{
b.HasBaseType("Entities.ContentLessonEntity");
b.Property<string>("Comment")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Query")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.ToTable("Paragraph");
});
modelBuilder.Entity("Entities.ContentLessonEntity", b =>
{
b.HasOne("Entities.LessonEntity", "Lesson")
.WithMany("Content")
.HasForeignKey("LessonId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lesson");
});
modelBuilder.Entity("Entities.InquiryTableEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("Entities.NotepadEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Inquiry")
.WithMany()
.HasForeignKey("InquiryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Inquiry");
b.Navigation("User");
});
modelBuilder.Entity("Entities.SolutionEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("Entities.SuccessEntity", b =>
{
b.HasOne("Entities.InquiryEntity", "Inquiry")
.WithMany()
.HasForeignKey("InquiryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Inquiry");
b.Navigation("User");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.LessonEntity", b =>
{
b.Navigation("Content");
});
#pragma warning restore 612, 618
}
}
}

@ -88,7 +88,7 @@ public class StubbedContext : UserDbContext
IsAdmin = true
});
builder.Entity<InquiryTableEntity>().HasData(
/*builder.Entity<InquiryTableEntity>().HasData(
new InquiryTableEntity
{
OwnerId = 1,
@ -184,5 +184,29 @@ public class StubbedContext : UserDbContext
IsFinished = true
}
);
builder.Entity<LessonEntity>().HasData(
new LessonEntity
{
Id = 1, Title = "Lesson N°1", LastEdit = DateOnly.FromDateTime(DateTime.Now), LastPublisher = "Clément"
},
new LessonEntity
{
Id = 2, Title = "Lesson N°2", LastEdit = DateOnly.FromDateTime(DateTime.Now), LastPublisher = "Clément"
},
new LessonEntity
{
Id = 3, Title = "Lesson N°3", LastEdit = DateOnly.FromDateTime(DateTime.Now), LastPublisher = "Clément"
},
new LessonEntity
{
Id = 4, Title = "Lesson N°4", LastEdit = DateOnly.FromDateTime(DateTime.Now), LastPublisher = "Clément"
}
);
builder.Entity<ParagraphEntity>().HasData(
new ParagraphEntity { Id = 1, LessonId = 1, ContentTitle = "Paragraph N°1", ContentContent = "Content of paragraph N°1", Title = "Title Paragraph N°1", Content = "Content of paragraph N°1", Info = "Infos", Query = "SELECT * FROM Table", Comment = "Comment of paragraph N°1"},
new ParagraphEntity { Id = 2, LessonId = 1, ContentTitle = "Paragraph N°2", ContentContent = "Content of paragraph N°2", Title = "Title Paragraph N°2", Content = "Content of paragraph N°2", Info = "Infos", Query = "SELECT * FROM Table", Comment = "Comment of paragraph N°2"},
new ParagraphEntity { Id = 3, LessonId = 1, ContentTitle = "Paragraph N°3", ContentContent = "Content of paragraph N°3", Title = "Title Paragraph N°3", Content = "Content of paragraph N°3", Info = "Infos", Query = "SELECT * FROM Table", Comment = "Comment of paragraph N°3"},
new ParagraphEntity { Id = 4, LessonId = 2, ContentTitle = "Paragraph N°1", ContentContent = "Content of paragraph N°1", Title = "Title Paragraph N°1", Content = "Content of paragraph N°1", Info = "Infos", Query = "SELECT * FROM Table", Comment = "Comment of paragraph N°1"}
);*/
}
}

@ -154,6 +154,23 @@ public class BlackListUnitTest
}
}
[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()
{

@ -0,0 +1,51 @@
using API.Controllers;
using Dto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Shared;
namespace TestAPI;
public class InquiryTableUnitTest
{
private readonly Mock<IInquiryTableService<InquiryTableDto>> _inquiryTableService;
public InquiryTableUnitTest()
{
_inquiryTableService = new Mock<IInquiryTableService<InquiryTableDto>>();
}
[Fact]
public void GetDatabaseNameFromInquiryId_Success()
{
var database = "Inquiry1";
_inquiryTableService.Setup(x => x.GetDatabaseNameByInquiryId(42))
.Returns(database);
var inquiryTableController =
new InquiryTableController(_inquiryTableService.Object, new NullLogger<InquiryTableController>());
var inquiryTableResult = inquiryTableController.GetDatabaseNameByInquiryById(42);
if (inquiryTableResult is OkObjectResult okObjectResult)
{
var valeur = okObjectResult.Value;
Assert.NotNull(valeur);
Assert.Equal(database, ((KeyValuePair<string,string>)valeur).Value);
}
}
[Fact]
public void GetDatabaseNameFromInquiryId_Throws_ArgumentException()
{
_inquiryTableService.Setup(x => x.GetDatabaseNameByInquiryId(42))
.Throws<ArgumentException>();
var inquiryTableController =
new InquiryTableController(_inquiryTableService.Object, new NullLogger<InquiryTableController>());
var inquiryTableResult = inquiryTableController.GetDatabaseNameByInquiryById(42);
Assert.NotNull(inquiryTableResult);
Assert.Equal(typeof(NotFoundResult), inquiryTableResult.GetType());
}
}

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Shared;
using TestAPI.Extensions;
using Xunit.Sdk;
namespace TestAPI;
@ -101,6 +102,22 @@ public class LessonUnitTest
}
}
[Fact]
public void GetLessonIdFail_Argument_Exception()
{
_lessonService.Setup(x => x.GetLessonById(10000))
.Throws<ArgumentException>();
var lessonsController = new LessonsController(_lessonService.Object, new NullLogger<LessonsController>());
var result = lessonsController.GetLessonById(10000);
if (result is NotFoundObjectResult nfObjectResult)
{
Assert.NotNull(nfObjectResult);
}
}
[Fact]
public void GetLessonTitleSuccess()
{
@ -145,6 +162,21 @@ public class LessonUnitTest
}
}
[Fact]
public void GetLessonTitleFail_Argument_Exception()
{
_lessonService.Setup(x => x.GetLessonByTitle("title"))
.Throws<ArgumentException>();
var lessonsController = new LessonsController(_lessonService.Object, new NullLogger<LessonsController>());
var result = lessonsController.GetLessonByTitle("title");
if (result is NotFoundObjectResult nfObjectResult)
{
Assert.NotNull(nfObjectResult);
}
}
[Fact]
public void DeleteLessonSuccess()
{
@ -213,6 +245,21 @@ public class LessonUnitTest
}
}
[Fact]
public void CreateLessonFail_Argument_Exception()
{
_lessonService.Setup(x => x.CreateLesson(35672653, "duehduheudheu nouveau titre", "Le deudhe éditeur", new DateOnly(2024, 03, 16)))
.Throws<ArgumentException>();
var lessonsController = new LessonsController(_lessonService.Object, new NullLogger<LessonsController>());
var result = lessonsController.CreateLesson(new LessonDto(35672653, "duehduheudheu nouveau titre", "Le deudhe éditeur", new DateOnly(2024, 03, 16)));
if (result is NotFoundObjectResult nfObjectResult)
{
Assert.NotNull(nfObjectResult);
}
}
[Fact]
public void UpdateLessonSuccess()
{

@ -0,0 +1,183 @@
using API.Controllers;
using Dto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Shared;
using TestAPI.Extensions;
namespace TestAPI;
public class NotepadUnitTest
{
private readonly Mock<INotepadService<NotepadDto>> _notepadService;
public NotepadUnitTest()
{
_notepadService = new Mock<INotepadService<NotepadDto>>();
}
[Fact]
public void GetNotepadFromUserAndInquiryId()
{
var notepad = new NotepadDto(42, 42, "These are notes example.");
_notepadService.Setup(x => x.GetNotepadFromUserAndInquiryId(42, 42))
.Returns(notepad);
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.GetNotepadByUserAndInquiryById(42,42);
if (notepadResult is OkObjectResult okObjectResult)
{
var valeur = okObjectResult.Value;
Assert.NotNull(valeur);
Assert.Equal(notepad, valeur);
}
}
[Fact]
public void GetNotepadFromUserAndInquiryId_ThrowingArgumentException()
{
var notepad = new NotepadDto(42, 42, "These are notes example.");
_notepadService.Setup(x => x.GetNotepadFromUserAndInquiryId(42, 10))
.Throws<ArgumentException>();
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.GetNotepadByUserAndInquiryById(42,10);
Assert.NotNull(notepadResult);
Assert.Equal(typeof(NotFoundResult),notepadResult.GetType());
}
[Fact]
public void SetNotepadFromUserAndInquiryId_Success()
{
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(42, 42,"These are notes example."));
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
Assert.NotNull(notepadResult);
Assert.Equal(typeof(OkResult),notepadResult.GetType());
Assert.Equal(typeof(OkObjectResult) , notepadController.GetNotepadByUserAndInquiryById(42,42).GetType());
}
[Fact]
public void SetNotepadFromUserAndInquiryId_Negative_UserId()
{
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(-42, 42,"These are notes example.")).Throws<ArgumentException>();
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(-42,42, "These are notes example."));
Assert.NotNull(notepadResult);
Assert.Equal(typeof(BadRequestResult),notepadResult.GetType());
}
[Fact]
public void SetNotepadFromUserAndInquiryId_Negative_InquiryId()
{
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(42, -42,"These are notes example.")).Throws<ArgumentException>();
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,-42, "These are notes example."));
Assert.NotNull(notepadResult);
Assert.Equal(typeof(BadRequestResult),notepadResult.GetType());
}
[Fact]
public void SetNotepadFromUserAndInquiryId_Null_Notes()
{
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(42, 42,"These are notes example.")).Throws<ArgumentException>();
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, null));
Assert.NotNull(notepadResult);
Assert.Equal(typeof(BadRequestResult),notepadResult.GetType());
}
[Fact]
public void SetNotepadFromUserAndInquiryId_Throws_ArgumentException()
{
var notepad = new NotepadDto(42, 42, "These are notes example.");
_notepadService.Setup(x => x.SetNotepadFromUserAndInquiryId(42, 42,"These are notes example.")).Throws<ArgumentException>();
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(notepad);
Assert.NotNull(notepadResult);
Assert.Equal(typeof(NotFoundResult),notepadResult.GetType());
}
[Fact]
public void UpdateNotepadFromUserAndInquiryId_Success()
{
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, 42,"These are the new notes"));
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
Assert.NotNull(notepadResult);
Assert.Equal(typeof(OkResult),notepadResult.GetType());
Assert.Equal(typeof(OkObjectResult) , notepadController.GetNotepadByUserAndInquiryById(42,42).GetType());
var updateResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are the new notes"));
Assert.NotNull(updateResult);
Assert.Equal(typeof(OkResult),updateResult.GetType());
}
[Fact]
public void UpdateNotepadFromUserAndInquiryId_Negative_UserId()
{
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, 42,"These are the new notes"));
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
var updateResult = notepadController.UpdateNotepadByUserAndInquiryById(new NotepadDto(-42,42, "These are the new notes"));
Assert.NotNull(updateResult);
Assert.Equal(typeof(BadRequestResult),updateResult.GetType());
}
[Fact]
public void UpdateNotepadFromUserAndInquiryId_Negative_InquiryId()
{
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, -42,"These are the new notes"));
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
var updateResult = notepadController.UpdateNotepadByUserAndInquiryById(new NotepadDto(42,-42, "These are the new notes"));
Assert.NotNull(updateResult);
Assert.Equal(typeof(BadRequestResult),updateResult.GetType());
}
[Fact]
public void UpdateNotepadFromUserAndInquiryId_Null_Notes()
{
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, 42,null)).Throws<ArgumentException>();
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
var updateResult = notepadController.UpdateNotepadByUserAndInquiryById(new NotepadDto(42,42, null));
Assert.NotNull(updateResult);
Assert.Equal(typeof(BadRequestResult),updateResult.GetType());
}
[Fact]
public void UpdateNotepadFromUserAndInquiryId_Throws_ArgumentException()
{
_notepadService.Setup(x => x.UpdateNotepadFromUserAndInquiryId(42, 10,"These are the new notes")).Throws<ArgumentException>();
var notepadController =
new NotepadController(_notepadService.Object, new NullLogger<NotepadController>());
var notepadResult = notepadController.SetNotepadByUserAndInquiryById(new NotepadDto(42,42, "These are notes example."));
var updateResult = notepadController.UpdateNotepadByUserAndInquiryById(new NotepadDto(42,10, "These are the new notes"));
Assert.NotNull(updateResult);
Assert.Equal(typeof(NotFoundResult),updateResult.GetType());
}
}

@ -0,0 +1,206 @@
using API.Controllers;
using Castle.Components.DictionaryAdapter.Xml;
using Dto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Shared;
using TestAPI.Extensions;
namespace TestAPI;
public class QueryUnitTest
{
private readonly Mock<IQueryService<QueryDto>> _queryService;
public QueryUnitTest()
{
_queryService = new Mock<IQueryService<QueryDto>>();
}
[Fact]
public void Select_Users_Success()
{
var userList = GetUsersData();
_queryService.Setup(x => x.ExecuteQuery("Select * from \"User\";","SQLuedo"))
.Returns(new QueryDto{Result = userList.ToString()});
var queryController = new QueryController(new NullLogger<QueryController>(), _queryService.Object);
var queryResult = queryController.ExecuteQuery("Select * from \"User\";", "SQLuedo");
if (queryResult is OkObjectResult okObjectResult)
{
Assert.NotNull(okObjectResult);
}
}
[Fact]
public void Select_Users_Failed_Cause_Database_Doesnt_Exists()
{
var userList = GetUsersData();
_queryService.Setup(x => x.ExecuteQuery("Select * from \"User\";", "SQLuedo"))
.Returns(new QueryDto { Result = userList.ToString() });
var queryController = new QueryController(new NullLogger<QueryController>(), _queryService.Object);
var queryResult = queryController.ExecuteQuery("Select * from \"User\";", "LABASEDEDONNEES");
if (queryResult is StatusCodeResult statusCodeResult && statusCodeResult.StatusCode == 204)
{
Assert.IsNotType<OkObjectResult>(queryResult);
}
}
[Fact]
public void Get_Tables_Success()
{
var tablesList = GetTables();
_queryService.Setup(x => x.GetTables("SQLuedo"))
.Returns(new QueryDto { Result = tablesList.ToString() });
var queryController = new QueryController(new NullLogger<QueryController>(), _queryService.Object);
var queryResult = queryController.GetTables("SQLuedo");
if (queryResult is OkObjectResult okObjectResult)
{
Assert.NotNull(okObjectResult);
}
}
[Fact]
public void Get_Tables_Failed_Cause_Database_Doesnt_Exist()
{
var tablesList = GetTables();
_queryService.Setup(x => x.GetTables("SQLuedo"))
.Returns(new QueryDto { Result = tablesList.ToString() });
var queryController = new QueryController(new NullLogger<QueryController>(), _queryService.Object);
var queryResult = queryController.GetTables("LABSEEEEEEEEEEEEEEEEEEEE");
if (queryResult is OkObjectResult okObjectResult)
{
Assert.NotNull(okObjectResult);
}
}
[Fact]
public void Get_Columns_Success()
{
var tablesList = GetColumns();
_queryService.Setup(x => x.GetColumns("SQLuedo","User"))
.Returns(new QueryDto { Result = tablesList.ToString() });
var queryController = new QueryController(new NullLogger<QueryController>(), _queryService.Object);
var queryResult = queryController.GetColumns("SQLuedo","User");
if (queryResult is OkObjectResult okObjectResult)
{
Assert.NotNull(okObjectResult);
}
}
[Fact]
public void Get_Columns_Failed_Cause_Database_Doesnt_Exist()
{
var tablesList = GetColumns();
_queryService.Setup(x => x.GetColumns("SQLuedo", "User"))
.Returns(new QueryDto { Result = tablesList.ToString() });
var queryController = new QueryController(new NullLogger<QueryController>(), _queryService.Object);
var queryResult = queryController.GetColumns("UDHUE", "User");
if (queryResult is OkObjectResult okObjectResult)
{
Assert.NotNull(okObjectResult);
}
}
[Fact]
public void Get_Columns_Failed_Cause_Table_Doesnt_Exist()
{
var tablesList = GetColumns();
_queryService.Setup(x => x.GetColumns("SQLuedo", "User"))
.Returns(new QueryDto { Result = tablesList.ToString() });
var queryController = new QueryController(new NullLogger<QueryController>(), _queryService.Object);
var queryResult = queryController.GetColumns("SQLuedo", "GEGEIU");
if (queryResult is OkObjectResult okObjectResult)
{
Assert.NotNull(okObjectResult);
}
}
private List<UserDto> GetUsersData()
{
List<UserDto> usersData = new List<UserDto>(4)
{
new(
0,
"Useruser",
"motdepasse",
"adressemail@gmail.com",
true
),
new
(
1,
"Leuser",
"motdepasse",
"deuxadresse@gmail.com",
false
),
new
(
2,
"gygyggyg",
"ennodlavehc",
"thirdadress@gmail.com",
false
),
new
(
"ferferf",
"h_nh_78",
"fourthadress@gmail.com",
false
),
};
return usersData;
}
private List<string> GetColumns()
{
List<string> columns = new List<string>(4)
{
"Id",
"Name",
"Password",
"IsAdmin"
};
return columns;
}
private List<string> GetTables()
{
List<string> columns = new List<string>(4)
{
"User",
"Solution",
"Inquiry",
"Success"
};
return columns;
}
}

@ -0,0 +1,52 @@
using API.Controllers;
using Dto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Shared;
namespace TestAPI;
public class SolutionUnitTest
{
private readonly Mock<ISolutionService<SolutionDto>> _solutionService;
public SolutionUnitTest()
{
_solutionService = new Mock<ISolutionService<SolutionDto>>();
}
[Fact]
public void GetSolutionFromInquiryId_Success()
{
var solution = new SolutionDto(42,"Maxime","Sapountzis","La cuisine","Le couteau", "L'explication");
_solutionService.Setup(x => x.GetSolutionByInquiryId(42))
.Returns(solution);
var solutionController =
new SolutionController(_solutionService.Object, new NullLogger<SolutionController>());
var solutionResult = solutionController.GetSolutionByInquiryById(42);
if (solutionResult is OkObjectResult okObjectResult)
{
var valeur = okObjectResult.Value;
Assert.NotNull(valeur);
Assert.Equal(solution, valeur);
}
}
[Fact]
public void GetSolutionFromInquiryId_Throws_ArgumentException()
{
var solution = new SolutionDto(42,"Maxime","Sapountzis","La cuisine","Le couteau", "L'explication");
_solutionService.Setup(x => x.GetSolutionByInquiryId(42))
.Throws<ArgumentException>();
var solutionController =
new SolutionController(_solutionService.Object, new NullLogger<SolutionController>());
var solutionResult = solutionController.GetSolutionByInquiryById(42);
Assert.NotNull(solutionResult);
Assert.Equal(typeof(NotFoundResult), solutionResult.GetType());
}
}

@ -145,6 +145,23 @@ public class SuccessesUnitTest
}
}
[Fact]
public void GetSuccessInquiryIdFail_Argument_Exception()
{
_successService.Setup(x => x.GetSuccessesByInquiryId(1000))
.Throws<ArgumentException>();
var successesController =
new SuccessesController(_successService.Object, new NullLogger<SuccessesController>());
var sucessesResult = successesController.GetSuccessByInquiryId(1000);
if (sucessesResult is NotFoundObjectResult nfObjectResult)
{
var valeur = nfObjectResult.Value;
Assert.NotNull(valeur);
}
}
[Fact]
public void GetSuccessUserIdSuccess()
{
@ -217,6 +234,23 @@ public class SuccessesUnitTest
}
}
[Fact]
public void GetSuccessUserIdFail_Argument_Exception()
{
_successService.Setup(x => x.GetSuccessesByUserId(1000))
.Throws<ArgumentException>();
var successesController =
new SuccessesController(_successService.Object, new NullLogger<SuccessesController>());
var sucessesResult = successesController.GetSuccessByUserId(1000);
if (sucessesResult is NotFoundObjectResult nfObjectResult)
{
var valeur = nfObjectResult.Value;
Assert.NotNull(valeur);
}
}
[Fact]
public void DeleteSuccessSuccess()
{
@ -318,6 +352,22 @@ public class SuccessesUnitTest
}
}
[Fact]
public void CreateSuccessFail_Exception()
{
_successService.Setup(x => x.CreateSuccess(89889, 82837, true))
.Throws<Exception>();
var successesController =
new SuccessesController(_successService.Object, new NullLogger<SuccessesController>());
var successesResult = successesController.CreateSuccess(new SuccessDto(89889, 82837, true));
if (successesResult is NotFoundObjectResult notFoundObjectResult)
{
Assert.NotNull(notFoundObjectResult);
}
}
[Fact]
public void UpdateSuccessSuccess()
{
@ -386,6 +436,22 @@ public class SuccessesUnitTest
}
}
[Fact]
public void UpdateSuccessFail_Throw_Exception()
{
_successService.Setup(x => x.UpdateSuccess(108871, 117683, new SuccessDto(1, 2, true)))
.Throws<Exception>();
var successesController =
new SuccessesController(_successService.Object, new NullLogger<SuccessesController>());
var successesResult = successesController.UpdateSuccess(108871, 117683, new SuccessDto(1, 2, true));
if (successesResult is NotFoundObjectResult notFoundObjectResult)
{
Assert.NotNull(notFoundObjectResult);
}
}
private List<SuccessDto> GetSuccessesData()

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Asp.Versioning.Mvc" Version="8.0.0" />
<PackageReference Include="Docker.DotNet" Version="3.125.15" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>

@ -171,7 +171,7 @@ public class UserUnitTest
[Fact]
public void GetUserIdFail__Argument_Exception_Negative_Id()
public void GetUserIdFail_Negative_Id()
{
var userList = GetUsersData();
_userService.Setup(x => x.GetUserById(1))
@ -189,6 +189,22 @@ public class UserUnitTest
}
}
[Fact]
public void GetUserIdFail_Argument_Exception()
{
_userService.Setup(x => x.GetUserById(10000))
.Throws<ArgumentException>();
var usersController = new UsersController(new NullLogger<UsersController>(), _userService.Object);
var userResult = usersController.GetUserById(10000);
if (userResult is NotFoundObjectResult nfObjectResult)
{
var valeur = nfObjectResult.Value;
Assert.NotNull(valeur);
}
}
[Fact]
public void GetUserUsernameSuccess()
{
@ -212,6 +228,22 @@ public class UserUnitTest
}
}
[Fact]
public void GetUserUsernameFail_Argument_Exception()
{
_userService.Setup(x => x.GetUserByUsername("Usererererrere"))
.Throws<ArgumentException>();
var usersController = new UsersController(new NullLogger<UsersController>(), _userService.Object);
var userResult = usersController.GetUserByUsername("Usererererrere");
if (userResult is NotFoundObjectResult nfObjectResult)
{
var valeur = nfObjectResult.Value;
Assert.NotNull(valeur);
}
}
[Fact]
public void GetUserEmailSuccess()
{
@ -308,6 +340,34 @@ public class UserUnitTest
}
}
[Fact]
public void DeleteUser_By_Username_Success()
{
_userService.Setup(x => x.DeleteUserByUsername("Damn"))
.Returns(true);
var usersController = new UsersController(new NullLogger<UsersController>(), _userService.Object);
var userResult = usersController.DeleteUserByUsername("Damn");
if (userResult is OkObjectResult okObjectResult)
{
Assert.Null(okObjectResult.Value);
}
}
[Fact]
public void DeleteUser_By_Username_Failed()
{
_userService.Setup(x => x.DeleteUserByUsername("IUDHEIUHDEHUDH"))
.Returns(false);
var usersController = new UsersController(new NullLogger<UsersController>(), _userService.Object);
var userResult = usersController.DeleteUserByUsername("IUDHEIUHDEHUDH");
if (userResult is NotFoundObjectResult notFoundObjectResult)
{
Assert.Null(notFoundObjectResult.Value);
}
}
[Fact]
public void CreateUserSuccess()
{

@ -78,10 +78,10 @@ namespace TestEF.Mapper
public void TestDtoToModel()
{
InquiryDto inquiry = new InquiryDto(_id, _title, _description, _isUser);
var inquiryMod = inquiry.FromDtoToEntity();
var inquiryMod = inquiry.FromDtoToModel();
Assert.NotNull(inquiryMod);
Assert.IsType<InquiryEntity>(inquiryMod);
Assert.IsType<Inquiry>(inquiryMod);
Assert.Equal(1, inquiryMod.Id);
Assert.Equal(_title, inquiryMod.Title);
Assert.Equal(_description, inquiryMod.Description);

@ -109,7 +109,7 @@ public class TestBlackListDataService
}
[Fact]
public void GetBannedUser_Success_Positive_Value()
public void GetBannedUser_Success_Positive_Value_Ordered_None()
{
_dbContext.BlackLists.Add(new BlackListEntity { Email = "email@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.BlackLists.Add(new BlackListEntity { Email = "eemail@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
@ -119,6 +119,42 @@ public class TestBlackListDataService
Assert.Equal(3, banResult.Count());
}
[Fact]
public void GetBannedUser_Success_Positive_Value_Ordered_Email()
{
_dbContext.BlackLists.Add(new BlackListEntity { Email = "email@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.BlackLists.Add(new BlackListEntity { Email = "eemail@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.BlackLists.Add(new BlackListEntity { Email = "eeemail@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.SaveChanges();
var banResult = _blackListDataService.GetBannedUsers(1, 3, BlackListOdrerCriteria.ByEmail);
Assert.Equal(3, banResult.Count());
}
[Fact]
public void GetBannedUser_Success_Positive_Value_Ordered_ExpirationDate()
{
_dbContext.BlackLists.Add(new BlackListEntity { Email = "email@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.BlackLists.Add(new BlackListEntity { Email = "eemail@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.BlackLists.Add(new BlackListEntity { Email = "eeemail@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.SaveChanges();
var banResult = _blackListDataService.GetBannedUsers(1, 3, BlackListOdrerCriteria.ByExpirationDate);
Assert.Equal(3, banResult.Count());
}
[Fact]
public void GetBannedUser_Success_Positive_Value_Ordered_Default()
{
_dbContext.BlackLists.Add(new BlackListEntity { Email = "email@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.BlackLists.Add(new BlackListEntity { Email = "eemail@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.BlackLists.Add(new BlackListEntity { Email = "eeemail@email.com", ExpirationDate = new DateOnly(2024, 03, 30) });
_dbContext.SaveChanges();
var banResult = _blackListDataService.GetBannedUsers(1, 3,default);
Assert.Equal(3, banResult.Count());
}
[Fact]
public void GetBannedUser_Success_Negative_Value()
{

@ -89,6 +89,45 @@ public class TestInquiryDataService
Assert.Equal(2, result.Count());
}
[Fact]
public void GetInquiries_OrderedById_ReturnsCorrectNumberOfInquiries()
{
_dbContext.Inquiries.Add(new InquiryEntity { Id = 1, Title = "Test1", Description = "Desc1", IsUser = true });
_dbContext.Inquiries.Add(new InquiryEntity { Id = 2, Title = "Test2", Description = "Desc2", IsUser = false });
_dbContext.Inquiries.Add(new InquiryEntity { Id = 3, Title = "Test3", Description = "Desc3", IsUser = true });
_dbContext.SaveChanges();
var result = _inquiryDataService.GetInquiries(1, 2, InquiryOrderCriteria.ById);
Assert.Equal(2, result.Count());
}
[Fact]
public void GetInquiries_OrderedByDefault_ReturnsCorrectNumberOfInquiries()
{
_dbContext.Inquiries.Add(new InquiryEntity { Id = 1, Title = "Test1", Description = "Desc1", IsUser = true });
_dbContext.Inquiries.Add(new InquiryEntity { Id = 2, Title = "Test2", Description = "Desc2", IsUser = false });
_dbContext.Inquiries.Add(new InquiryEntity { Id = 3, Title = "Test3", Description = "Desc3", IsUser = true });
_dbContext.SaveChanges();
var result = _inquiryDataService.GetInquiries(1, 2, default);
Assert.Equal(2, result.Count());
}
[Fact]
public void GetInquiries_OrderedDefault_ReturnsCorrectNumberOfInquiries()
{
_dbContext.Inquiries.Add(new InquiryEntity { Id = 1, Title = "Test1", Description = "Desc1", IsUser = true });
_dbContext.Inquiries.Add(new InquiryEntity { Id = 2, Title = "Test2", Description = "Desc2", IsUser = false });
_dbContext.Inquiries.Add(new InquiryEntity { Id = 3, Title = "Test3", Description = "Desc3", IsUser = true });
_dbContext.SaveChanges();
var result = _inquiryDataService.GetInquiries(1, 2, default);
Assert.Equal(2, result.Count());
}
[Fact]
public void GetInquiryById_ReturnsCorrectInquiry()
{

@ -0,0 +1,62 @@
using DbContextLib;
using DbDataManager.Service;
using Entities;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace TestEF.Service;
public class TestInquiryTableDataService
{
private readonly UserDbContext _dbContext;
private readonly InquiryTableDataService _inquiryTableDataService;
public TestInquiryTableDataService()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<UserDbContext>()
.UseSqlite(connection)
.Options;
_dbContext = new UserDbContext(options);
_inquiryTableDataService = new InquiryTableDataService(_dbContext);
}
[Fact]
public void GetDatabaseFromInquiryId_Success()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Description", IsUser = false });
var inquiryTable = new InquiryTableEntity()
{
OwnerId = 42,
DatabaseName = "Database",
ConnectionInfo = "ConnectionString"
};
_dbContext.InquiryTables.Add(inquiryTable);
_dbContext.SaveChanges();
var result = _inquiryTableDataService.GetDatabaseNameByInquiryId(42);
Assert.Equal("Database",result);
}
[Fact]
public void GetSolution_NotFound()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Description", IsUser = false });
var inquiryTable = new InquiryTableEntity()
{
OwnerId = 42,
DatabaseName = "Database",
ConnectionInfo = "ConnectionString"
};
_dbContext.InquiryTables.Add(inquiryTable);
_dbContext.SaveChanges();
Assert.Throws<ArgumentException>(() =>
{
_inquiryTableDataService.GetDatabaseNameByInquiryId(10);
});
}
}

@ -0,0 +1,169 @@
using DbContextLib;
using DbDataManager.Service;
using Entities;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Model.OrderCriteria;
namespace TestEF.Service;
public class TestNotepadDataService
{
private readonly UserDbContext _dbContext;
private readonly NotepadDataService _notepadDataService;
public TestNotepadDataService()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<UserDbContext>()
.UseSqlite(connection)
.Options;
_dbContext = new UserDbContext(options);
_notepadDataService = new NotepadDataService(_dbContext);
}
[Fact]
public void GetNotepad_Success()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
_dbContext.Notepads.Add(notepad);
_dbContext.SaveChanges();
var result = _notepadDataService.GetNotepadFromUserAndInquiryId(42, 42);
Assert.Equal(notepad,result);
}
[Fact]
public void GetNotepad_Fail_UserNotFound()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
_dbContext.Notepads.Add(notepad);
_dbContext.SaveChanges();
Assert.Throws<ArgumentException>(() =>
{
_notepadDataService.GetNotepadFromUserAndInquiryId(10, 42);
});
}
[Fact]
public void GetNotepad_Fail_InquiryNotFound()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
_dbContext.Notepads.Add(notepad);
_dbContext.SaveChanges();
Assert.Throws<ArgumentException>(() =>
{
_notepadDataService.GetNotepadFromUserAndInquiryId(42, 10);
});
}
[Fact]
public void GetNotepad_Fail_NotepadNotFound()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 1, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
_dbContext.SaveChanges();
Assert.Throws<ArgumentException>(() =>
{
_notepadDataService.GetNotepadFromUserAndInquiryId(42, 1);
});
}
[Fact]
public void SetNotepad_Success()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
_dbContext.SaveChanges();
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "Some notes again" };
_notepadDataService.SetNotepadFromUserAndInquiryId(42,42, "Some notes again");
_dbContext.SaveChanges();
var result = _notepadDataService.GetNotepadFromUserAndInquiryId(42, 42);
Assert.Equal(notepad.UserId,result.UserId);
Assert.Equal(notepad.InquiryId,result.InquiryId);
Assert.Equal(notepad.Notes,result.Notes);
}
[Fact]
public void SetNotepad_Fail_UserNotFound()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
_dbContext.SaveChanges();
Assert.Throws<ArgumentException>(() =>
{
_notepadDataService.SetNotepadFromUserAndInquiryId(10, 42, "Some notes");
});
}
[Fact]
public void SetNotepad_Fail_InquiryNotFound()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "These are some notes" };
_dbContext.SaveChanges();
Assert.Throws<ArgumentException>(() =>
{
_notepadDataService.SetNotepadFromUserAndInquiryId(42, 10, "Some notes");
});
}
[Fact]
public void SetNotepad_Fail_NotepadAlreadyExists()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "Some notes" };
_dbContext.Notepads.Add(notepad);
_dbContext.SaveChanges();
Assert.Throws<ArgumentException>(() =>
{
_notepadDataService.SetNotepadFromUserAndInquiryId(42, 42, "Some notes");
});
}
[Fact]
public void UpdateNotepad_Success()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Descritpion", IsUser = false });
_dbContext.Users.Add(new UserEntity
{ Id = 42, Username = "Username", Email = "email@example.com", Password = "password", IsAdmin = true });
var notepad = new NotepadEntity { UserId = 42, InquiryId = 42, Notes = "Some notes" };
_dbContext.Notepads.Add(notepad);
_dbContext.SaveChanges();
_notepadDataService.UpdateNotepadFromUserAndInquiryId(42,42, "New Notes");
_dbContext.SaveChanges();
Assert.Equal("New Notes", _notepadDataService.GetNotepadFromUserAndInquiryId(42,42).Notes);
}
}

@ -0,0 +1,75 @@
using DbContextLib;
using DbDataManager.Service;
using Entities;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace TestEF.Service;
public class TestSolutionDataService
{
private readonly UserDbContext _dbContext;
private readonly SolutionDataService _solutionDataService;
public TestSolutionDataService()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<UserDbContext>()
.UseSqlite(connection)
.Options;
_dbContext = new UserDbContext(options);
_solutionDataService = new SolutionDataService(_dbContext);
}
[Fact]
public void GetSolution_Success()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Description", IsUser = false });
var solution = new SolutionEntity
{
MurdererFirstName = "Maxime",
MurdererLastName = "Sapountzis",
MurderPlace = "La cuisine",
MurderWeapon = "Le couteau",
Explaination = "Parce que",
OwnerId = 42,
};
_dbContext.Solutions.Add(solution);
_dbContext.SaveChanges();
var result = _solutionDataService.GetSolutionByInquiryId(42);
Assert.Equal(solution.MurdererFirstName,result.MurdererFirstName);
Assert.Equal(solution.MurdererLastName,result.MurdererLastName);
Assert.Equal(solution.MurderPlace,result.MurderPlace);
Assert.Equal(solution.MurderWeapon,result.MurderWeapon);
Assert.Equal(solution.Explaination,result.Explaination);
Assert.Equal(solution.OwnerId,result.OwnerId);
}
[Fact]
public void GetSolution_NotFound()
{
_dbContext.Inquiries.Add(new InquiryEntity
{ Id = 42, Title = "Titre", Description = "Description", IsUser = false });
var solution = new SolutionEntity
{
MurdererFirstName = "Maxime",
MurdererLastName = "Sapountzis",
MurderPlace = "La cuisine",
MurderWeapon = "Le couteau",
Explaination = "Parce que",
OwnerId = 42,
};
_dbContext.Solutions.Add(solution);
_dbContext.SaveChanges();
Assert.Throws<ArgumentException>(() =>
{
_solutionDataService.GetSolutionByInquiryId(10);
});
}
}
Loading…
Cancel
Save