Merge branch 'Converter'

pull/22/head
Maxime ROCHER 3 months ago
commit 54ab34216a

@ -0,0 +1,31 @@
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using System;
namespace WF_WebAdmin.Converter
{
public class QuoteDTO
{
public int Id { get; set; }
public string Content { get; set; }
public int Likes { get; set; }
public string Langue { get; set; }
public bool IsValide { get; set; }
public string? Reason { get; set; }
public int IdCaracter { get; set; }
public int IdSource { get; set; }
public int? IdUserVerif { get; set; }
public QuoteDTO(int id_quote, string content, int likes, string langue, bool isValide, string? reason, int id_caracter, int id_source, int? id_user_verif)
{
this.Id = id_quote;
this.Content = content;
this.Likes = likes;
this.Langue = langue;
this.IsValide = isValide;
this.Reason = reason;
this.IdCaracter = id_caracter;
this.IdSource = id_source;
this.IdUserVerif = id_user_verif;
}
}
}

@ -0,0 +1,19 @@
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Converter
{
public class QuoteExtension
{
public QuoteDTO QuoteToDTO(Quote q)
{
QuoteDTO quote = new QuoteDTO(q.Id, q.Content, q.Likes, q.Langue, q.IsValide, q.Reason, q.IdCaracter, q.IdSource, q.IdUserVerif);
return quote;
}
public Quote DTOToQuote(QuoteDTO q)
{
Quote quote = new Quote(q.Id, q.Content, q.Likes, q.Langue, q.IsValide, q.Reason, q.IdCaracter, q.IdSource, q.IdUserVerif);
return quote;
}
}
}

@ -0,0 +1,20 @@
namespace WF_WebAdmin.Converter
{
public class UserDTO
{
public int Id { get; set; }
public string Image { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public DateTime DateCreation { get; set; }
public UserDTO(int id, string image, string name, string email, DateTime dateCreation)
{
this.Id = id;
this.Image = image;
this.Name = name;
this.Email = email;
this.DateCreation = dateCreation;
}
}
}

@ -0,0 +1,19 @@
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Converter
{
public class UserExtension
{
public User UserToDTO(UserDTO u)
{
User user = new User(u.Id, u.Image, u.Name, u.Email, u.DateCreation);
return user;
}
public UserDTO DTOToUser(User u)
{
UserDTO user = new UserDTO(u.Id, u.Image, u.Name, u.Email, u.DateCreation);
return user;
}
}
}

@ -4,21 +4,27 @@
{
public int Id { get; set; }
public string Content { get; set; }
public string Charac { get; set; }
public string ImgPath { get; set; }
public string TitleSrc { get; set; }
public DateTime DateSrc { get; set; }
public int Like { get; set; }
public int Likes { get; set; }
public string Langue { get; set; }
<<<<<<< Updated upstream
public string UserProposition { get; set; }
=======
public bool IsValide { get; set; }
public string? Reason { get; set; }
public int IdCaracter { get; set; }
public int IdSource { get; set; }
public int? IdUserVerif { get; set; }
public Quote(int id, string content, int likes, string langue, bool isValide, string? reason, int idCaracter, int idSource, int idUserVerif)
{
Id = id;
Content = content;
Likes = likes;
Langue = langue;
IsValide = isValide;
Reason = reason;
IdCaracter = idCaracter;
IdSource = idSource;
IdUserVerif = idUserVerif;
}
public Quote(int id, string content, int likes, string langue, bool isValide, string? reason, int idCaracter, int idSource, int? idUserVerif)
{
Id = id;
@ -31,6 +37,5 @@
IdSource = idSource;
IdUserVerif = idUserVerif;
}
>>>>>>> Stashed changes
}
}

@ -9,7 +9,14 @@
public string Email { get; set; }
public DateTime DateCreation { get; set; }
public Boolean IsAdmin { get; set; }
public List<Commentary> Comments { get; set; }
public User(int id, string image, string name, string email, DateTime dateCreation)
{
this.Id = id;
this.Image = image;
this.Name = name;
this.Email = email;
this.DateCreation = dateCreation;
}
}
}

@ -21,13 +21,12 @@ else
<p><strong>ID :</strong> @quote.Id</p>
<p><strong>Contenu :</strong> @quote.Content</p>
<p><strong>Langue :</strong> @quote.Langue</p>
<p><strong>Likes :</strong> @quote.Like</p>
<p><strong>Personnage :</strong> @quote.Charac</p>
<p><strong>Image :</strong> @quote.ImgPath</p>
<p><strong>Source :</strong> @quote.TitleSrc</p>
<p><strong>Date de source :</strong> @quote.DateSrc.ToShortDateString()</p>
<p><strong>Utilisateur proposition :</strong> @quote.UserProposition</p>
<p><strong>Utilisateur :</strong> @quote.UserProposition</p>
<button @onclick="() => ValiderQuote(quote.Id)">Valider</button>
<button @onclick="() => RejeterQuote(quote.Id)">Rejeter</button>

@ -0,0 +1,27 @@
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service
{
public interface IQuoteService
{
public Task addQuote(Quote quote);
public Task removeQuote(Quote quote);
public Task validQuote(Quote quote);
public Task updateQuote(Quote quote);
public Task<List<Quote>> getAllQuote();
public Task<List<Quote>> getSomeQuote(int nb, int page);
public Task<List<Quote>> getOnequote(int id);
public Task<List<Quote>> reserchQuote(string reserch, List<string> argument);
public Task<List<Quote>> getAllQuoteInvalid();
public Task<List<Quote>> getSomeQuoteInvalid(int nb, int page);
}
}

@ -0,0 +1,21 @@
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service
{
public interface IUserService
{
public void removeUser(User user);
public void updateRole(User user);
public void downgradeRole(User user);
public List<User> getAllUser();
public List<User> getSomeUser(int nb, int page);
public User getOneUser(int id);
public List<User> reserchUsers(string reserch, List<string> args);
}
}

@ -0,0 +1,119 @@
using WF_WebAdmin.Converter;
using WF_WebAdmin.Model;
using Npgsql;
namespace WF_WebAdmin.Service
{
public class QuoteServiceLocal: IQuoteService
{
private readonly string? _connectionString = "Host=localhost;Port=5432;Username=loguichard3;Password=Reglisse15.;Database=dbloguichard3";
public async Task<QuoteDTO> AddQuoteAsync(Quote quote)
{
QuoteExtension extension = new QuoteExtension();
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
// Utilisation de NpgsqlConnection pour PostgreSQL
using (var connection = new NpgsqlConnection(_connectionString))
{
// Définir la requête SQL d'insertion
var commandText = "INSERT INTO Quote (content, langue, reason, id_source, id_caracter, id_user_verif, img_path) " +
"VALUES (@content, @langue, @reason, @source, @character, @user, @img_path)";
// Créer une commande Npgsql
var command = new NpgsqlCommand(commandText, connection);
// Ajouter des paramètres à la commande
command.Parameters.AddWithValue("@content", quote.Content);
command.Parameters.AddWithValue("@langue", quote.Langue);
command.Parameters.AddWithValue("@reason", "À vérifier"); // Vous pouvez changer ça si nécessaire
command.Parameters.AddWithValue("@source", quote.Source);
command.Parameters.AddWithValue("@character", quote.Character);
command.Parameters.AddWithValue("@user", quote.User); // Assurez-vous que `quote.User` est correctement défini
command.Parameters.AddWithValue("@img_path", quote.ImgPath);
try
{
// Ouvrir la connexion à la base de données
await connection.OpenAsync();
// Exécuter la commande d'insertion
await command.ExecuteNonQueryAsync();
}
catch (Exception ex)
{
// Gérer les erreurs ici (par exemple, afficher ou enregistrer les erreurs)
Console.WriteLine($"Une erreur est survenue lors de l'ajout de la citation : {ex.Message}");
}
finally
{
// Fermer la connexion (automatiquement géré avec `using`, mais ajouté pour explicitement montrer le processus)
await connection.CloseAsync();
}
}
// Retourner l'objet DTO pour que vous puissiez l'utiliser ailleurs dans votre application
return quoteDTO;
}
}
public Task RemoveQuote(Quote quote)
{
QuoteExtension extension = new QuoteExtension();
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
return Task.FromResult(quoteDTO);
}
public Task validQuote(Quote quote)
{
QuoteExtension extension = new QuoteExtension();
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
return Task.FromResult(quoteDTO);
}
public Task updateQuote(Quote quote)
{
QuoteExtension extension = new QuoteExtension();
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
return Task.FromResult(quoteDTO);
}
public Task<List<Quote>> getAllQuote()
{
}
public Task<List<Quote>> getSomeQuote(int nb, int page)
{
}
public Task<List<Quote>> getOnequote(int id)
{
}
public Task<List<Quote>> reserchQuote(string reserch, List<string> argument)
{
}
public Task<List<Quote>> getAllQuoteInvalid()
{
}
public Task<List<Quote>> getSomeQuoteInvalid(int nb, int page)
{
}
}
}

@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using WF_WebAdmin.Model;
using static System.Net.WebRequestMethods;
@ -12,5 +12,5 @@ namespace WF_WebAdmin.Service
[Inject]
public NavigationManager NavigationManager { get; set; }
}
}

@ -9,3 +9,4 @@
@using WF_WebAdmin
@using WF_WebAdmin.Shared
@using Blazorise.DataGrid

@ -1,9 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=wikifantasy3;Username=postgres;Password=postgres"
}
},
"AllowedHosts": "*"
}

Loading…
Cancel
Save