Ajout des controller notepad, solution et des services associés + modification des controllers et services actuels pour se conformer au site PHP
parent
7730b09d3c
commit
f9f98e5705
@ -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 GetSolutionByInquiryById(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(new KeyValuePair<string,string>("database", _inquiryTableService.GetDatabaseNameByInquiryId(id)));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError("[ERREUR] Aucune base de données trouvée pour l'enquête avec l'id {id}.", id);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
using Asp.Versioning;
|
||||||
|
using Dto;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[ApiController]
|
||||||
|
public class NotepadController : Controller
|
||||||
|
{
|
||||||
|
private readonly INotepadService<NotepadDto> _notepadDataService;
|
||||||
|
|
||||||
|
private readonly ILogger<NotepadController> _logger;
|
||||||
|
|
||||||
|
public NotepadController(INotepadService<NotepadDto> notepadService, ILogger<NotepadController> logger)
|
||||||
|
{
|
||||||
|
_notepadDataService = notepadService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("notepad/{userId:int}/{inquiryId:int}")]
|
||||||
|
[ProducesResponseType(typeof(NotepadDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(void), 404)]
|
||||||
|
public IActionResult GetNotepadByUserAndInquiryById(int userId, int inquiryId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"[INFORMATION] Le bloc-notes de l'utilisateur avec l'id {id} et l'enquête avec l'id {idInquiry} a été trouvé.",
|
||||||
|
userId, inquiryId);
|
||||||
|
return Ok(_notepadDataService.GetNotepadFromUserAndInquiryId(userId,inquiryId));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError(
|
||||||
|
"[ERREUR] Aucun bloc-notes trouvé pour l'utilisateur avec l'id {id} et l'enquête avec l'id {inquiryId}.",
|
||||||
|
userId, inquiryId);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("notepad")]
|
||||||
|
[ProducesResponseType(typeof(void), 200)]
|
||||||
|
[ProducesResponseType(typeof(void), 404)]
|
||||||
|
public IActionResult SetNotepadByUserAndInquiryById([FromBody] NotepadDto notepad)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (notepad.InquiryId == null || notepad.UserId == null || 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 == null || notepad.UserId == null || notepad.Notes == null)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
_notepadDataService.UpdateNotepadFromUserAndInquiryId(notepad.UserId, notepad.InquiryId, notepad.Notes);
|
||||||
|
_logger.LogInformation(
|
||||||
|
"[INFORMATION] Le bloc-notes de l'utilisateur avec l'id {id} et l'enquête avec l'id {idInquiry} a été mis à jour.",
|
||||||
|
notepad.UserId, notepad.InquiryId);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError(
|
||||||
|
"[ERREUR] Aucun bloc-notes n'a pu être mis à jour pour l'utilisateur avec l'id {id} et l'enquête avec l'id {inquiryId}.",
|
||||||
|
notepad.UserId, notepad.InquiryId);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Dto;
|
||||||
|
using Model.OrderCriteria;
|
||||||
|
using Shared;
|
||||||
|
using Asp.Versioning;
|
||||||
|
|
||||||
|
namespace API.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[ApiController]
|
||||||
|
public class SolutionController : Controller
|
||||||
|
{
|
||||||
|
private readonly ISolutionService<SolutionDto> _solutionDataService;
|
||||||
|
|
||||||
|
private readonly ILogger<SolutionController> _logger;
|
||||||
|
|
||||||
|
public SolutionController(ISolutionService<SolutionDto> solutionDataService, ILogger<SolutionController> logger)
|
||||||
|
{
|
||||||
|
_solutionDataService = solutionDataService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("solution/{id:int}")]
|
||||||
|
[ProducesResponseType(typeof(SolutionDto), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
public IActionResult GetSolutionByInquiryById(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("[INFORMATION] L'enquête avec l'id {id} a été trouvé.", id);
|
||||||
|
return Ok(_solutionDataService.GetSolutionByInquiryId(id));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
using Dto;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace API.Service;
|
||||||
|
|
||||||
|
public class InquiryTableDataServiceAPI(IInquiryTableService<InquiryTableEntity> inquiryTableService) : IInquiryTableService<InquiryTableDto>
|
||||||
|
{
|
||||||
|
public string GetDatabaseNameByInquiryId(int id)
|
||||||
|
{
|
||||||
|
return inquiryTableService.GetDatabaseNameByInquiryId(id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using Dto;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
using Shared.Mapper;
|
||||||
|
|
||||||
|
namespace API.Service;
|
||||||
|
|
||||||
|
public class NotepadDataServiceAPI(INotepadService<NotepadEntity> notepadService) : INotepadService<NotepadDto>
|
||||||
|
{
|
||||||
|
public NotepadDto GetNotepadFromUserAndInquiryId(int userId, int inquiryId)
|
||||||
|
{
|
||||||
|
return notepadService.GetNotepadFromUserAndInquiryId(userId, inquiryId).FromEntityToDto();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||||
|
{
|
||||||
|
notepadService.SetNotepadFromUserAndInquiryId(userId,inquiryId,notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||||
|
{
|
||||||
|
notepadService.UpdateNotepadFromUserAndInquiryId(userId,inquiryId,notes);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using Dto;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
using Shared.Mapper;
|
||||||
|
|
||||||
|
namespace API.Service;
|
||||||
|
|
||||||
|
public class SolutionDataServiceAPI(ISolutionService<SolutionEntity> solutionService) : ISolutionService<SolutionDto>
|
||||||
|
{
|
||||||
|
public SolutionDto GetSolutionByInquiryId(int id)
|
||||||
|
{
|
||||||
|
return solutionService.GetSolutionByInquiryId(id).FromEntityToDto();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace DbDataManager.Service;
|
||||||
|
|
||||||
|
public class InquiryTableDataService : IInquiryTableService<InquiryTableEntity>
|
||||||
|
{
|
||||||
|
private UserDbContext DbContext { get; set; }
|
||||||
|
|
||||||
|
public InquiryTableDataService(UserDbContext context)
|
||||||
|
{
|
||||||
|
DbContext = context;
|
||||||
|
context.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetDatabaseNameByInquiryId(int id)
|
||||||
|
{
|
||||||
|
var inquiryTable = DbContext.InquiryTables.FirstOrDefault(i => i.OwnerId == id);
|
||||||
|
if (inquiryTable == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Erreur, impossible de trouver l'objet InquiryTable pour l'enquête d'id {id}",
|
||||||
|
nameof(id));
|
||||||
|
}
|
||||||
|
return inquiryTable.DatabaseName;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
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)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Erreur, un bloc-notes existe déjà pour l'utilisateur et l'enquête donnés");
|
||||||
|
}
|
||||||
|
DbContext.Notepads.Add(new NotepadEntity { UserId = userId, InquiryId = inquiryId, Notes = notes });
|
||||||
|
DbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateNotepadFromUserAndInquiryId(int userId, int inquiryId, string notes)
|
||||||
|
{
|
||||||
|
var notepad = GetNotepadFromUserAndInquiryId(userId, inquiryId);
|
||||||
|
notepad.Notes = notes;
|
||||||
|
DbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
using DbContextLib;
|
||||||
|
using Entities;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace DbDataManager.Service;
|
||||||
|
|
||||||
|
public class SolutionDataService : ISolutionService<SolutionEntity>
|
||||||
|
{
|
||||||
|
private UserDbContext DbContext { get; set; }
|
||||||
|
|
||||||
|
public SolutionDataService(UserDbContext context)
|
||||||
|
{
|
||||||
|
DbContext = context;
|
||||||
|
context.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SolutionEntity GetSolutionByInquiryId(int id)
|
||||||
|
{
|
||||||
|
var solution = DbContext.Solutions.FirstOrDefault(s => s.OwnerId == id);
|
||||||
|
if (solution == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Impossible de trouver la solution pour l'enquête d'id {id}", nameof(id));
|
||||||
|
}
|
||||||
|
return solution;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public interface IInquiryTableService<TInquiryTable>
|
||||||
|
{
|
||||||
|
public string GetDatabaseNameByInquiryId(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);
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public interface ISolutionService<TSolution>
|
||||||
|
{
|
||||||
|
public TSolution GetSolutionByInquiryId(int id);
|
||||||
|
}
|
Loading…
Reference in new issue