Merge branch 'j2/ajout_repo' of https://10.4.0.131/gitea/DI1-P4-E1/Webzine into j2/feat/repository-commentaire

This commit is contained in:
b.nodon
2026-03-26 17:50:29 +01:00
39 changed files with 1216 additions and 482 deletions

View File

@@ -18,7 +18,7 @@
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE

View File

@@ -0,0 +1,99 @@
name: Deploy Webzine
on:
push:
branches:
- main
- dev
jobs:
# ─────────────────────────────────────────────
# COMPILATION — commun aux deux branches
# ─────────────────────────────────────────────
build:
name: Build & Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Le tag d'image dépend de la branche :
# main → webzine:latest
- name: Set image tag
id: vars
run: |
echo "IMAGE_TAG=latest" >> $GITHUB_OUTPUT
echo "ENV_LABEL=production" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Connexion au registry Gitea intégré
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
# Construction et publication de l'image Docker
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Webzine.WebApplication/Dockerfile
push: true
tags: ${{ vars.REGISTRY_URL }}/webzine/webzine:${{ steps.vars.outputs.IMAGE_TAG }}
cache-from: type=registry,ref=${{ vars.REGISTRY_URL }}/webzine/webzine:buildcache-${{ steps.vars.outputs.IMAGE_TAG }}
cache-to: type=registry,ref=${{ vars.REGISTRY_URL }}/webzine/webzine:buildcache-${{ steps.vars.outputs.IMAGE_TAG }},mode=max
outputs:
image_tag: ${{ steps.vars.outputs.IMAGE_TAG }}
env_label: ${{ steps.vars.outputs.ENV_LABEL }}
# ─────────────────────────────────────────────
# DÉPLOIEMENT — Serveur de PRODUCTION (branche main)
# ─────────────────────────────────────────────
deploy-production:
name: Deploy to Production
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy via SSH to PRODUCTION server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USER }}
key: ${{ secrets.PROD_SSH_KEY }}
port: ${{ secrets.PROD_SSH_PORT || 22 }}
script: |
set -e
echo "=== [PROD] Récupération de l'image ==="
docker login ${{ vars.REGISTRY_URL }} \
-u ${{ secrets.REGISTRY_USERNAME }} \
-p ${{ secrets.REGISTRY_PASSWORD }}
docker pull ${{ vars.REGISTRY_URL }}/webzine/webzine:latest
echo "=== [PROD] Arrêt de l'ancien conteneur ==="
docker stop webzine-prod 2>/dev/null || true
docker rm webzine-prod 2>/dev/null || true
echo "=== [PROD] Démarrage du nouveau conteneur ==="
docker run -d \
--name webzine-prod \
--restart unless-stopped \
-p 80:8080 \
-p 443:8081 \
-v /opt/webzine/prod/data:/app/Data \
-v /opt/webzine/prod/logs:/Logs \
-e ASPNETCORE_ENVIRONMENT=Production \
${{ vars.REGISTRY_URL }}/webzine/webzine:latest
echo "=== [PROD] Nettoyage des anciennes images ==="
docker image prune -f
echo "=== [PROD] Déploiement terminé ==="

View File

@@ -0,0 +1,132 @@
name: PR Endpoint Performance Check
on:
pull_request:
branches:
- main
- master
- develop
jobs:
endpoint-performance-check:
name: Test All Endpoints (< 1s)
runs-on: ubuntu-latest
steps:
# ─────────────────────────────────────────────
# Récupération du code source
# ─────────────────────────────────────────────
- name: Checkout PR branch
uses: actions/checkout@v4
# ─────────────────────────────────────────────
# Installation de .NET 10
# ─────────────────────────────────────────────
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
# ─────────────────────────────────────────────
# Restauration des dépendances et compilation
# ─────────────────────────────────────────────
- name: Restore dependencies
run: dotnet restore Webzine.sln
- name: Build solution
run: dotnet build Webzine.sln --no-restore --configuration Release
# ─────────────────────────────────────────────
# Exécution des tests unitaires (entités)
# ─────────────────────────────────────────────
- name: Run unit tests
run: |
dotnet test Webzine.Entity.Tests/Webzine.Entity.Tests.csproj \
--no-build \
--configuration Release \
--logger "console;verbosity=normal"
# ─────────────────────────────────────────────
# Démarrage de l'application web en arrière-plan
# ─────────────────────────────────────────────
- name: Start Webzine application
run: |
dotnet run \
--project Webzine.WebApplication/Webzine.WebApplication.csproj \
--configuration Release \
--no-build \
-- --urls "http://localhost:5038" &
echo "Attente du démarrage de l'application..."
timeout 60 bash -c '
until curl -sf http://localhost:5038 > /dev/null 2>&1; do
sleep 1
done
'
echo "Application prête !"
# ─────────────────────────────────────────────
# Exécution des tests de performance des endpoints
# ─────────────────────────────────────────────
- name: Test endpoint response times
id: perf_test
run: |
chmod +x scripts/test-endpoints.sh
bash scripts/test-endpoints.sh http://localhost:5038 1000 || true
FAIL_COUNT=$(grep -c "^\[FAIL\]\|^\[SLOW\]" /tmp/webzine_endpoint_report.txt || echo 0)
echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT"
# ─────────────────────────────────────────────
# Publication du rapport en commentaire de PR
# ─────────────────────────────────────────────
- name: Post performance report as PR comment
if: always()
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_SERVER_URL: ${{ gitea.server_url }}
REPO: ${{ gitea.repository }}
PR_NUMBER: ${{ gitea.event.pull_request.number }}
run: |
REPORT_CONTENT=$(cat /tmp/webzine_endpoint_report.txt 2>/dev/null || echo "Aucun rapport généré.")
FAILED_COUNT="${{ steps.perf_test.outputs.failed }}"
if [ "${FAILED_COUNT:-0}" -gt 0 ]; then
HEADER="## ❌ Vérification des performances ÉCHOUÉE"
INTRO="${FAILED_COUNT} endpoint(s) ont dépassé 1 seconde ou retourné une erreur serveur."
else
HEADER="## ✅ Vérification des performances RÉUSSIE"
INTRO="Tous les endpoints ont répondu en moins d'une seconde."
fi
BODY=$(cat <<EOF
$HEADER
$INTRO
\`\`\`
$REPORT_CONTENT
\`\`\`
> Seuil : **1000ms** | Vérifié par le workflow **PR Endpoint Performance**.
EOF
)
curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg body "$BODY" '{body: $body}')" \
"$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments"
# ─────────────────────────────────────────────
# Blocage de la PR si un endpoint a échoué
# ─────────────────────────────────────────────
- name: Enforce performance gate
run: |
FAILED="${{ steps.perf_test.outputs.failed }}"
if [ "${FAILED:-0}" -gt 0 ]; then
echo "❌ PR REJETÉE : ${FAILED} endpoint(s) n'ont pas respecté le seuil d'une seconde."
echo " Corrigez les endpoints lents ou en erreur avant de fusionner."
exit 1
else
echo "✅ Tous les endpoints ont passé le contrôle de performance."
fi

View File

@@ -49,5 +49,20 @@ namespace Webzine.Entity.Fixtures
return artisteFaker.Generate();
}
/// <summary>
/// Permet de retourner une liste d'artiste pour seeder la base
/// de données.
/// </summary>
/// <param name="nombre"></param>
/// <returns>Liste d'artiste.</returns>
public static List<Artiste> CreerListeArtiste(int nombre)
{
Faker<Artiste> faker = new Faker<Artiste>("fr")
.RuleFor(a => a.Nom, f => f.Person.FullName)
.RuleFor(a => a.Biographie, f => f.Lorem.Paragraph(2));
return faker.Generate(nombre);
}
}
}

View File

@@ -0,0 +1,33 @@
// <copyright file="CommentaireFactory.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
using Bogus;
namespace Webzine.Entity.Fixtures
{
public class CommentaireFactory
{
/// <summary>
/// Seeder pour la base de données.
/// </summary>
/// <param name="titre">Titre.</param>
/// <param name="min">Min.</param>
/// <param name="max">Max.</param>
/// <returns>Liste de commentaire.</returns>
public static List<Commentaire> CreerListeCommentaire(Titre titre, int min = 0, int max = 5)
{
Random random = new Random();
int count = random.Next(min, max + 1);
Faker<Commentaire> faker = new Faker<Commentaire>("fr")
.RuleFor(c => c.Auteur, f => f.Internet.UserName())
.RuleFor(c => c.Contenu, f => f.Lorem.Sentences(2))
.RuleFor(c => c.DateCreation, f => f.Date.Recent(60))
.RuleFor(c => c.Titre, _ => titre)
.RuleFor(c => c.IdTitre, _ => titre.IdTitre);
return faker.Generate(count);
}
}
}

View File

@@ -1,6 +1,14 @@
namespace Webzine.Entity.Fixtures;
// <copyright file="SeedDataLocal.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
public class SeedDataLocal
{
namespace Webzine.Entity.Fixtures
{
public class SeedDataLocal
{
public SeedDataLocal()
{
}
}
}

View File

@@ -0,0 +1,53 @@
// <copyright file="StyleFactory.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Webzine.Entity.Fixtures
{
using Webzine.Entity;
public class StyleFactory
{
/// <summary>
/// Générer une liste de style pour seeder la base
/// de données.
/// </summary>
/// <returns>Liste de style.</returns>
public static List<Style> CreerListeStyle(int minCount = 15, int maxCount = 20)
{
List<string> libelles = new List<string>
{
"Pop",
"Rock",
"Jazz",
"Blues",
"Hip-Hop",
"Rap",
"Electro",
"Techno",
"House",
"Metal",
"Funk",
"Soul",
"R&B",
"Classique",
"Reggae",
"Punk",
"Folk",
"Disco",
"Ambient",
"Indie",
};
Random random = new Random();
int count = random.Next(minCount, maxCount + 1);
return libelles
.Take(count)
.Select(libelle => new Style
{
Libelle = libelle,
})
.ToList();
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Bogus;
using Faker;
using System;
using System.Collections.Generic;
using Webzine.Entity;
namespace Webzine.Repository.Fake
@@ -73,4 +74,50 @@ namespace Webzine.Repository.Fake
return titres;
}
}
public class TitreFactory
{
/// <summary>
/// Initializes a new instance of the <see cref="TitreFactory"/> class.
/// </summary>
public TitreFactory()
{
}
public static List<Titre> CreerListeTitre(
int count,
List<Artiste> artistes,
List<Style> styles)
{
Random random = new Random();
Faker<Titre> faker = new Faker<Titre>("fr")
.RuleFor(t => t.Libelle, f => f.Lorem.Sentence(3).Replace(".", string.Empty))
.RuleFor(t => t.Chronique, f => f.Lorem.Paragraphs(3))
.RuleFor(t => t.DateCreation, f => f.Date.Recent(120))
.RuleFor(t => t.DateSortie, (f, t) => f.Date.Past(10, t.DateCreation))
.RuleFor(t => t.Duree, f => f.Random.Int(120, 420))
.RuleFor(t => t.UrlJaquette, f => $"https://picsum.photos/seed/{Guid.NewGuid():N}/640/640")
.RuleFor(t => t.UrlEcoute, f => $"https://example.com/listen/{Guid.NewGuid():N}")
.RuleFor(t => t.NbLectures, f => f.Random.Int(0, 5000))
.RuleFor(t => t.NbLikes, f => f.Random.Int(0, 1000))
.RuleFor(t => t.Album, f => f.Company.CatchPhrase())
.RuleFor(t => t.Artiste, f => f.PickRandom(artistes));
List<Titre> titres = faker.Generate(count);
foreach (Titre titre in titres)
{
int nbStyles = random.Next(1, 4);
titre.Styles = styles
.OrderBy(_ => Guid.NewGuid())
.Take(nbStyles)
.ToList();
titre.IdArtiste = titre.Artiste.IdArtiste;
}
return titres;
}
}
}

View File

@@ -1,5 +1,10 @@
namespace Webzine.Repository
// <copyright file="DbArtisteRepository.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Webzine.Repository
{
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Webzine.EntitiesContext;
@@ -12,19 +17,18 @@
/// </summary>
public class DbArtisteRepository : IArtisteRepository
{
private WebzineDbContext _context;
private readonly ILogger<LocalArtisteRepository> _logger;
private WebzineDbContext context;
private readonly ILogger<LocalArtisteRepository> logger;
/// <summary>
/// Initializes a new instance of the <see cref="DbArtisteRepository"/> class.
/// </summary>
/// <param name="context">Le contexte de base de données à utiliser pour accéder aux entités et effectuer des opérations de
/// persistance. Ne peut pas être null.</param>
public DbArtisteRepository(WebzineDbContext context, ILogger<LocalArtisteRepository> logger)
public DbArtisteRepository(WebzineDbContext context, ILogger<LocalArtisteRepository> logger)
{
this._logger = logger;
this._context = context;
this.logger = logger;
this.context = context;
}
/// <inheritdoc/>
@@ -32,17 +36,17 @@
{
try
{
if (artiste == null)
{
throw new ArgumentNullException(nameof(artiste), "L'artiste à ajouter ne peut pas être null.");
}
this._context.Artistes.Add(artiste);
this._context.SaveChanges();
this.context.Artistes.Add(artiste);
this.context.SaveChanges();
}
catch (DbUpdateException dbex)
{
this.logger.LogError(dbex, "Erreur de base de données lors de l'ajout de l'artiste: {id}", artiste.IdArtiste);
throw;
}
catch (Exception ex)
{
this._logger.LogError(ex, "Une erreur est survenue lors de l'ajout de l'artiste {Nom}.", artiste?.Nom);
this.logger.LogError(ex, "Une erreur est survenue lors de l'ajout de l'artiste {Nom}.", artiste?.Nom);
throw new Exception("Une erreur est survenue lors de l'ajout de l'artiste.", ex);
}
}
@@ -50,19 +54,24 @@
/// <inheritdoc/>
public void Delete(Artiste artiste)
{
try
try
{
if (artiste == null)
{
throw new ArgumentNullException(nameof(artiste), "L'artiste à supprimer ne peut pas être null.");
}
this._context.Artistes.Remove(artiste);
this._context.SaveChanges();
this.context.Artistes.Remove(artiste);
this.context.SaveChanges();
}
catch (DbUpdateException dbex)
{
this.logger.LogError(dbex, "Erreur de base de données lors de la suppression de l'artiste: {Id}", artiste.IdArtiste);
throw;
}
catch (Exception ex)
{
this._logger.LogError(ex, "Une erreur est survenue lors de la suppression de l'artiste {Nom}.", artiste?.Nom);
this.logger.LogError(ex, "Une erreur est survenue lors de la suppression de l'artiste {Nom}.", artiste?.Nom);
throw new Exception("Une erreur est survenue lors de la suppression de l'artiste.", ex);
}
}
@@ -70,35 +79,42 @@
/// <inheritdoc/>
public Artiste Find(int id)
{
Artiste artiste = this._context.Artistes
.Include(a => a.Titres)
.FirstOrDefault(a => a.IdArtiste == id);
if (artiste == null)
try
{
this._logger.LogWarning("Aucun artiste trouvé avec l'identifiant {Id}", id);
Artiste artiste = this.context.Artistes
.Include(a => a.Titres)
.First(a => a.IdArtiste == id);
return artiste;
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste: {Id}", id);
throw;
}
return artiste;
}
/// <inheritdoc/>
public Artiste FindByName(string nom)
{
if (string.IsNullOrWhiteSpace(nom))
try
{
this._logger.LogWarning("Tentative de recherche avec un nom vide ou null.");
return null;
var artiste = this.context.Artistes
.Include(a => a.Titres)
.FirstOrDefault(a => a.Nom == nom);
if (artiste == null)
{
this.logger.LogWarning("Pas d'artiste au nom {Nom}", nom);
artiste = new Artiste();
}
return artiste;
}
var artiste = this._context.Artistes
.Include(a => a.Titres)
.FirstOrDefault(a => a.Nom == nom);
if (artiste == null)
catch (Exception ex)
{
this._logger.LogWarning("Recherche Nom : Aucun artiste trouvé pour '{Nom}'.", nom);
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
throw;
}
return artiste;
}
/// <inheritdoc/>
@@ -107,13 +123,13 @@
try
{
// .AsNoTracking() rend la requête beaucoup plus rapide pour de la lecture
var artistes = this._context.Artistes.AsNoTracking().ToList();
this._logger.LogInformation("{Count} artistes récupérés de la base.", artistes.Count);
var artistes = this.context.Artistes.AsNoTracking().ToList();
this.logger.LogInformation("{Count} artistes récupérés de la base.", artistes.Count);
return artistes;
}
catch (Exception ex)
{
this._logger.LogError(ex, "Erreur lors de la récupération de tous les artistes.");
this.logger.LogError(ex, "Erreur lors de la récupération de tous les artistes.");
return Enumerable.Empty<Artiste>(); // Retourne une liste vide au lieu de faire crash l'UI
}
}
@@ -128,13 +144,18 @@
try
{
this._context.Artistes.Update(artiste);
this._context.SaveChanges();
this._logger.LogInformation("Artiste {Id} ({Nom}) mis à jour avec succès.", artiste.IdArtiste, artiste.Nom);
this.context.Artistes.Update(artiste);
this.context.SaveChanges();
this.logger.LogInformation("Artiste {Id} ({Nom}) mis à jour avec succès.", artiste.IdArtiste, artiste.Nom);
}
catch (DbUpdateException ex)
{
this.logger.LogError(ex, "Erreur de base de données lors de la mise à jour de l'artiste ID: {IdArtiste}", artiste.IdArtiste);
throw;
}
catch (Exception ex)
{
this._logger.LogError(ex, "Erreur lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
this.logger.LogError(ex, "Erreur lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
throw;
}
}

View File

@@ -0,0 +1,63 @@
// <copyright file="DbEntityRepository.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Webzine.Repository
{
using Webzine.EntitiesContext;
using Webzine.Entity;
using Webzine.Entity.Fixtures;
using Webzine.Repository.Fake;
public class DbEntityRepository
{
private readonly WebzineDbContext context;
public DbEntityRepository(WebzineDbContext context)
{
this.context = context;
}
public void SeedBaseDeDonnees(
int nbArtistes = 100,
int nbTitres = 500,
int minStyles = 15,
int maxStyles = 20,
int minCommentairesParTitre = 0,
int maxCommentairesParTitre = 5)
{
if (this.context.Artistes.Any() ||
this.context.Titres.Any() ||
this.context.Styles.Any() ||
this.context.Commentaires.Any())
{
return;
}
List<Artiste> artistes = ArtisteFactory.CreerListeArtiste(nbArtistes);
List<Style> styles = StyleFactory.CreerListeStyle(minStyles, maxStyles);
this.context.Artistes.AddRange(artistes);
this.context.Styles.AddRange(styles);
this.context.SaveChanges();
List<Titre> titres = TitreFactory.CreerListeTitre(nbTitres, artistes, styles);
this.context.Titres.AddRange(titres);
this.context.SaveChanges();
List<Commentaire> commentaires = new List<Commentaire>();
foreach (Titre titre in titres)
{
commentaires.AddRange(
CommentaireFactory.CreerListeCommentaire(
titre,
minCommentairesParTitre,
maxCommentairesParTitre));
}
this.context.Commentaires.AddRange(commentaires);
this.context.SaveChanges();
}
}
}

View File

@@ -1,4 +1,8 @@
namespace Webzine.Repository
// <copyright file="LocalArtisteRepository.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Webzine.Repository
{
using Microsoft.Extensions.Logging;
using Webzine.Entity;
@@ -10,8 +14,8 @@
/// </summary>
public class LocalArtisteRepository : IArtisteRepository
{
private readonly ILogger<LocalArtisteRepository> _logger;
private readonly List<Artiste> _artistes;
private readonly ILogger<LocalArtisteRepository> logger;
private readonly List<Artiste> artistes;
/// <summary>
/// Initializes a new instance of the <see cref="LocalArtisteRepository"/> class.
@@ -21,8 +25,8 @@
/// <param name="logger">Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null.</param>
public LocalArtisteRepository(List<Artiste> artistes, ILogger<LocalArtisteRepository> logger)
{
this._logger = logger;
this._artistes = artistes;
this.logger = logger;
this.artistes = artistes;
}
/// <inheritdoc/>
@@ -30,24 +34,18 @@
{
try
{
if (artiste == null)
if (this.artistes.Any(a => a.IdArtiste == artiste.IdArtiste))
{
this._logger.LogError("L'artiste à ajouter ne peut pas être null.");
throw new ArgumentNullException(nameof(artiste));
}
if (this._artistes.Any(a => a.IdArtiste == artiste.IdArtiste))
{
this._logger.LogWarning("Un artiste avec l'ID {Id} existe déjà. L'ajout est ignoré.", artiste.IdArtiste);
this.logger.LogWarning("Un artiste avec l'ID {Id} existe déjà. L'ajout est ignoré.", artiste.IdArtiste);
return;
}
this._artistes.Add(artiste);
this._logger.LogInformation("Artiste ajouté : {Nom}", artiste.Nom);
this.artistes.Add(artiste);
this.logger.LogInformation("Artiste ajouté : {Nom}", artiste.Nom);
}
catch (Exception ex)
{
this._logger.LogError(ex, "Erreur lors de l'ajout de l'artiste : {Nom}", artiste?.Nom);
this.logger.LogError(ex, "Erreur lors de l'ajout de l'artiste : {Nom}", artiste?.Nom);
throw;
}
}
@@ -57,12 +55,12 @@
{
try
{
this._artistes.Remove(artiste);
this._logger.LogInformation("Artiste supprimé : {Nom}", artiste.Nom);
this.artistes.Remove(artiste);
this.logger.LogInformation("Artiste supprimé : {Nom}", artiste.Nom);
}
catch (Exception ex)
{
this._logger.LogError(ex, "Erreur lors de la suppression de l'artiste : {Nom}", artiste.Nom);
this.logger.LogError(ex, "Erreur lors de la suppression de l'artiste : {Nom}", artiste.Nom);
throw;
}
}
@@ -70,44 +68,46 @@
/// <inheritdoc/>
public Artiste Find(int id)
{
Artiste artiste = this._artistes.FirstOrDefault(a => a.IdArtiste == id);
if (artiste == null)
try
{
this._logger.LogWarning("Aucun artiste trouvé avec l'identifiant {Id}", id);
Artiste artiste = this.artistes.First(a => a.IdArtiste == id);
return artiste;
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec ID: {Id}", id);
throw;
}
return artiste;
}
/// <inheritdoc/>
public Artiste FindByName(string nom)
{
Artiste artiste = this._artistes.FirstOrDefault(a => a.Nom == nom);
if (artiste == null)
try
{
this._logger.LogWarning("Aucun artiste trouvé avec le nom {Nom}", nom);
Artiste artiste = this.artistes.First(a => a.Nom == nom);
return artiste;
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
throw;
}
return artiste;
}
/// <inheritdoc/>
/// La liste retournée est une copie de la liste interne, donc elle ne peut être nulle.
public IEnumerable<Artiste> FindAll()
{
return this._artistes;
return this.artistes;
}
/// <inheritdoc/>
public void Update(Artiste artiste)
{
if (artiste == null)
{
this._logger.LogError("L'artiste à mettre à jour ne peut pas être null.");
throw new ArgumentNullException(nameof(artiste));
}
try
{
var artisteToUpdate = this._artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
var artisteToUpdate = this.artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
if (artisteToUpdate != null)
{
@@ -115,17 +115,17 @@
artisteToUpdate.Biographie = artiste.Biographie;
artisteToUpdate.Titres = artiste.Titres;
this._logger.LogInformation("Artiste {Id} mis à jour avec succès.", artiste.IdArtiste);
this.logger.LogInformation("Artiste {Id} mis à jour avec succès.", artiste.IdArtiste);
}
else
{
this._logger.LogWarning("Mise à jour impossible : l'artiste avec l'ID {Id} n'existe pas.", artiste.IdArtiste);
this.logger.LogWarning("Mise à jour impossible : l'artiste avec l'ID {Id} n'existe pas.", artiste.IdArtiste);
throw new KeyNotFoundException($"L'artiste {artiste.IdArtiste} est introuvable.");
}
}
catch (Exception ex)
{
this._logger.LogError(ex, "Une erreur est survenue lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
this.logger.LogError(ex, "Une erreur est survenue lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
throw;
}
}

View File

@@ -10,7 +10,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers;
public class ArtisteController : Controller
{
// Injection du logger via le constructeur
private readonly ILogger<ArtisteController> _logger;
private readonly ILogger<ArtisteController> logger;
private readonly IArtisteRepository _artisteRepository;
private readonly List<Artiste> _artistes = new List<Artiste>();
@@ -18,8 +18,8 @@ public class ArtisteController : Controller
public ArtisteController(ILogger<ArtisteController> logger,
IArtisteRepository artisteRepository)
{
this._logger = logger;
this._logger.LogDebug(1, "initialisation du ArtisteController d'administration");
this.logger = logger;
this.logger.LogDebug(1, "initialisation du ArtisteController d'administration");
this._artisteRepository = artisteRepository;
this._artistes.AddRange(this._artisteRepository.FindAll());
}

View File

@@ -54,7 +54,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
if (commentaire == null)
{
this._logger.LogWarning("Commentaire avec ID {Id} introuvable pour suppression.", id);
this.logger.LogWarning("Commentaire avec ID {Id} introuvable pour suppression.", id);
return RedirectToAction("Index");
}

View File

@@ -16,7 +16,7 @@
<thead class="table-active">
<tr>
<th scope="col" class="p-2">Nom</th>
<th scope="col" class="text-center p-2" style="width: 100px;">Actions</th>
<th scope="col" class="text-center p-2">Actions</th>
</tr>
</thead>
<tbody>

View File

@@ -2,7 +2,7 @@
<div class="container">
<!-- ARTISTE -->
<div class="row mb-3 align-items-center">
<div class="row mb-3">
<label class="col-md-3 col-form-label">Nom de l'artiste<span class="text-danger">*</span></label>
<div class="col-md-9">
<input asp-for="Nom" class="form-control" />
@@ -10,14 +10,15 @@
</div>
<!-- BIOGRAPHIE -->
<div class="row mb-3 align-items-center">
<label class="col-md-3 col-form-label">Biographie<span class="text-danger">*</span></label>
<div class="row mb-3">
<label class="col-md-3 col-form-label">Biographie</label>
<div class="col-md-9">
<input asp-for="Biographie" class="form-control"/>
<textarea asp-for="Biographie" class="form-control" rows="5"></textarea>
</div>
</div>
<!-- BOUTONS -->
<div class="row mt-4">
<div class="col-md-9 offset-md-3">

View File

@@ -14,10 +14,10 @@
<thead class="table-active">
<tr>
<th scope="col">Titre</th>
<th scope="col">Auteur</th>
<th scope="col">Nom</th>
<th scope="col">Commentaire</th>
<th scope="col">Date de création</th>
<th scope="col" class="text-center p-2" style="width: 100px" ;>Actions</th>
<th scope="col" class="text-center p-2">Actions</th>
</tr>
</thead>
<tbody>
@@ -25,7 +25,9 @@
{
<tr class="align-middle">
<td>
@commentaire.Titre.Libelle
<a asp-action="Details" asp-controller="Titre" asp-route-id="@commentaire.Titre.IdTitre">
@commentaire.Titre.Libelle
</a>
</td>
<td>
@commentaire.Auteur

View File

@@ -12,19 +12,19 @@
<div class="col-md-4">
<a asp-area="Administration"
asp-controller="Artiste">
<div class="ratio ratio-4x3">
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
<i class="fa fa-users fa-3x text-primary mb-3"></i>
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center text-primary">
<i class="fa fa-users fa-5x text-primary mb-3"></i>
<h3>
@Model.NombreArtistes
</h3>
<p>
artistes
</p>
<h2>
@Model.NombreArtistes
</h2>
<p>
artistes
</p>
</div>
</div>
</a>
</div>
@@ -33,17 +33,17 @@
<a asp-area=""
asp-controller="Artiste"
asp-route-nom="@Model.ArtisteLePlusChronique">
<div class="ratio ratio-4x3">
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center text-primary">
<i class="fa fa-user fa-5x text-primary mb-3"></i>
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
<i class="fa fa-user fa-3x text-primary mb-3"></i>
<h2>
@Model.ArtisteLePlusChronique
</h2>
<h3>
@Model.ArtisteLePlusChronique
</h3>
<p>artiste le plus chroniqué</p>
<p>artiste le plus chroniqué</p>
</div>
</div>
</a>
</div>
@@ -52,19 +52,20 @@
<a asp-area=""
asp-controller="Artiste"
asp-route-nom="@Model.AlbumLePlusChronique">
<div class="ratio ratio-4x3">
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
<i class="fa fa-trophy fa-3x text-primary mb-3"></i>
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center text-primary">
<i class="fa fa-trophy fa-5x text-primary mb-3"></i>
<h3>
<h2>
@Model.AlbumLePlusChronique
</h3>
</h2>
<p>
artiste avec le plus d'albums distincts
</p>
</div>
</div>
</a>
</div>
@@ -72,19 +73,20 @@
<div class="col-md-4">
<a asp-area="Administration"
asp-controller="Titre">
<div class="ratio ratio-4x3">
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
<i class="fa fa-book fa-3x text-primary mb-3"></i>
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center text-primary">
<i class="fa fa-book fa-5x text-primary mb-3"></i>
<h3>
<h2>
@Model.NombreBiographies
</h3>
</h2>
<p>
biographies d'artistes
</p>
</div>
</div>
</a>
</div>
@@ -94,19 +96,20 @@
asp-controller="Titre"
asp-action="Details"
asp-route-id="@Model.IdMusiqueLaPlusJouee">
<div class="ratio ratio-4x3">
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
<i class="fa fa-compact-disc fa-3x text-primary mb-3"></i>
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center text-primary">
<i class="fa fa-compact-disc fa-5x text-primary mb-3"></i>
<h4>
<h2>
@Model.MusiqueLaPlusJouee
</h4>
</h2>
<p>
titre le plus lu
</p>
</div>
</div>
</a>
</div>
@@ -114,19 +117,20 @@
<div class="col-md-4">
<a asp-area="Administration"
asp-controller="Titre">
<div class="ratio ratio-4x3">
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
<i class="fa fa-music fa-3x text-primary mb-3"></i>
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center text-primary">
<i class="fa fa-music fa-5x text-primary mb-3"></i>
<h3>
<h2>
@Model.NombreTitres
</h3>
</h2>
<p>
titres
</p>
</div>
</div>
</a>
</div>
@@ -134,50 +138,57 @@
<div class="col-md-4">
<a asp-area="Administration"
asp-controller="Styles">
<div class="ratio ratio-4x3">
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
<i class="fa fa-tags fa-3x text-primary mb-3"></i>
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center text-primary">
<i class="fa fa-tags fa-5x text-primary mb-3"></i>
<h3>
<h2>
@Model.NombreGenres
</h3>
</h2>
<p>
styles de musique
</p>
</div>
</div>
</a>
</div>
<!-- NOMBRE DE LECTURES -->
<div class="col-md-4">
<div class="card shadow-sm p-4 bg-light h-100">
<i class="fa fa-eye fa-3x text-dark mb-3"></i>
<div class="ratio ratio-4x3">
<h3>
@Model.NombreLectures
</h3>
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center">
<i class="fa fa-eye fa-5x text-dark mb-3"></i>
<p>
lectures
</p>
<h2>
@Model.NombreLectures
</h2>
<p>
lectures
</p>
</div>
</div>
</div>
<!-- TOTAL LIKES -->
<div class="col-md-4">
<div class="card shadow-sm p-4 bg-light h-100">
<i class="fa fa-thumbs-up fa-3x text-dark mb-3"></i>
<div class="ratio ratio-4x3">
<h3>
<div class="py-5 bg-light rounded-3 d-flex flex-column justify-content-center align-items-center">
<i class="fa fa-thumbs-up fa-5x text-dark mb-3"></i>
<h2>
@Model.NombreLikes
</h3>
</h2>
<p>
likes
</p>
</div>
</div>
</div>
</div>

View File

@@ -22,7 +22,7 @@
@* Input *@
<div class="me-3">
<input asp-for="Libelle" class="form-control" style="width: 250px;" />
<input asp-for="Libelle" class="form-control" />
</div>
@* Bouton *@

View File

@@ -25,7 +25,7 @@
@* Input *@
<div class="me-3">
<input asp-for="Libelle" class="form-control" style="width: 250px;" />
<input asp-for="Libelle" class="form-control" />
</div>
@* Bouton *@

View File

@@ -20,7 +20,7 @@
<thead class="table-active">
<tr>
<th scope="col" class="p-2">Libellé</th>
<th scope="col" class="text-center p-2" style="width: 100px;">Actions</th>
<th scope="col" class="text-center p-2">Actions</th>
</tr>
</thead>
<tbody>
@@ -28,11 +28,11 @@
{
@foreach (Webzine.Entity.Style style in Model)
{
<tr class="align-middle">
<td class="p-2">
<tr >
<td class="p-2 w-75">
@style.Libelle
</td>
<td class="text-center p-2">
<td class="text-center w-auto p-2">
<a asp-action="Edit" asp-route-id="@style.IdStyle" class="text-primary me-2" title="Éditer">
<i class="fas fa-edit"></i>
</a>

View File

@@ -62,7 +62,7 @@
<!-- JAQUETTE -->
<div class="row mb-3 align-items-center">
<label class="col-md-3 col-form-label">Jaquette<span class="text-danger">*</span></label>
<label class="col-md-3 col-form-label">Jaquette de l'album<span class="text-danger">*</span></label>
<div class="col-md-9">
<input asp-for="UrlJaquette"
class="form-control"/>
@@ -102,13 +102,13 @@
</div>
<!-- LECTURES / LIKES (AFFICHAGE UNIQUEMENT) -->
<div class="row mb-4 align-items-center">
<div class="row align-items-center">
<label class="col-md-3 col-form-label">Nb de lectures<span class="text-danger">*</span></label>
<div class="col-md-3">
@Model.NbLectures
</div>
</div>
<div class="row mb-4 align-items-center">
<div class="row align-items-center">
<label class="col-md-3 col-form-label">Nb de likes<span class="text-danger">*</span></label>
<div class="col-md-3">
@Model.NbLikes

View File

@@ -2,12 +2,10 @@
// Copyright (c) Equipe 1 - . All rights reserved.
// </copyright>
using Webzine.Repository.Contracts;
namespace Webzine.WebApplication.Controllers
{
using Microsoft.AspNetCore.Mvc;
using Webzine.Repository.Fake;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.ViewModels.Accueil;
/// <summary>
@@ -25,13 +23,16 @@ namespace Webzine.WebApplication.Controllers
/// </summary>
/// <param name="logger">Service de journalisation injecté pour enregistrer les événements et les erreurs.</param>
/// <param name="configuration">Service d'injection de configuration pour accéder aux paramètres de l'application.</param>
/// <param name="titreRepository">Repository des titres injecté pour accéder aux données des titres.</param>
public AccueilController(ILogger<AccueilController> logger, IConfiguration configuration, ITitreRepository titreRepository)
public AccueilController(
ILogger<AccueilController> logger,
IConfiguration configuration,
ITitreRepository titreRepository)
{
this.logger = logger;
this.configuration = configuration;
this.titreRepository = titreRepository;
this.logger.LogDebug(1, "initialisation du AccueilController");
this.titreRepository = titreRepository;
}
/// <summary>
@@ -43,20 +44,19 @@ namespace Webzine.WebApplication.Controllers
this.logger.LogInformation("Arrivée sur la page d'accueil");
var derniereChronique = this.configuration.GetValue<int>("Webzine:NombreDerniereChronique");
var topTitres = this.configuration.GetValue<int>("Webzine:NombreDeTopTitres");
var titres = this.titreRepository.FindAll()
.ToList();
var nbTopTitres = this.configuration.GetValue<int>("Webzine:NombreDeTopTitres");
// var titres = FakeDataFactory.GetTitres();
// var titres = this.titreRepository.FindTitres(derniereChronique, nbTopTitres);
var titres = this.titreRepository.FindAll();
var vm = new AccueilIndexViewModel
{
DerniersTitres = titres
.OrderByDescending(t => t.DateCreation)
.Take(derniereChronique)
.ToList(),
DerniersTitres = titres.Take(derniereChronique).ToList(),
TopTitres = titres
.OrderByDescending(t => t.NbLikes)
.Take(topTitres)
.Take(nbTopTitres)
.ToList(),
};

View File

@@ -28,7 +28,7 @@ public class ApiController : ControllerBase
return Ok(new
{
nom = "webzine",
version = "1.0",
version = "2.0",
});
}
}

View File

@@ -8,7 +8,7 @@
public class ArtisteController : Controller
{
// Injection du logger via le constructeur
private readonly ILogger<ArtisteController> _logger;
private readonly ILogger<ArtisteController> logger;
private readonly IArtisteRepository _artisteRepository;
/// <summary>
@@ -18,8 +18,8 @@
public ArtisteController(ILogger<ArtisteController> logger,
IArtisteRepository artisteRepository)
{
this._logger = logger;
this._logger.LogDebug("Initialisation du ArtisteController");
this.logger = logger;
this.logger.LogDebug("Initialisation du ArtisteController");
this._artisteRepository = artisteRepository;
}
@@ -35,7 +35,7 @@
if (string.IsNullOrEmpty(nom))
{
this._logger.LogWarning("Nom de l'artiste manquant dans la requête.");
this.logger.LogWarning("Nom de l'artiste manquant dans la requête.");
return RedirectToAction("Index");
}
@@ -48,7 +48,7 @@
if (artiste == null)
{
this._logger.LogWarning("Artiste non trouvé pour le nom : {NomArtiste}", nomPropre);
this.logger.LogWarning("Artiste non trouvé pour le nom : {NomArtiste}", nomPropre);
return RedirectToAction("Index");
}
var viewModel = new ArtisteDetailsViewModel
@@ -63,7 +63,7 @@
.OrderBy(g => g.Key),
};
this._logger.LogInformation("Artiste trouvé : {NomArtiste}", nom);
this.logger.LogInformation("Artiste trouvé : {NomArtiste}", nom);
return View(viewModel);
}

View File

@@ -1,75 +1,68 @@
using Microsoft.AspNetCore.Mvc;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.ViewModels.Recherche;
using Webzine.WebApplication.ViewModels.Titre;
// <copyright file="RechercheController.cs" company=" Equipe 1 - ">
// Copyright (c) Equipe 1 - . All rights reserved.
// </copyright>
namespace Webzine.WebApplication.Controllers;
/// <summary>
/// Controleur responsable de la recherche d'artistes et de titres musicaux.
/// </summary>
[Route("recherche")]
public class RechercheController : Controller
namespace Webzine.WebApplication.Controllers
{
private readonly ILogger<RechercheController> logger;
private readonly ITitreRepository titreRepository;
using Microsoft.AspNetCore.Mvc;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.ViewModels.Recherche;
using Webzine.WebApplication.ViewModels.Titre;
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="RechercheController"/>.
/// </summary>
/// <param name="logger">Service de journalisation injecté pour suivre les opérations du contrôleur.</param>
/// <param name="titreRepository">Repository des titres injecté pour effectuer les recherches d'artistes et de titres.</param>
public RechercheController(ILogger<RechercheController> logger, ITitreRepository titreRepository)
[Route("recherche")]
public class RechercheController : Controller
{
this.logger = logger;
this.titreRepository = titreRepository;
}
private readonly ILogger<RechercheController> logger;
private readonly ITitreRepository titreRepository;
/// <summary>
/// Affiche les résultats de la recherche d'artistes et de titres en fonction du mot-clé fourni.
/// </summary>
/// <param name="mot">Le mot-clé de recherche utilisé pour trouver les artistes et les titres correspondants.</param>
/// <returns>Une vue contenant les résultats de la recherche d'artistes et de titres.</returns>
[HttpPost("")]
public IActionResult Index(string mot)
{
this.logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot);
var titres = this.titreRepository.Search(mot)
.Concat(this.titreRepository.SearchByStyle(mot))
.DistinctBy(t => t.IdTitre)
.OrderBy(t => t.Libelle)
.Select(t => new TitreStyleItem
{
IdTitre = t.IdTitre,
Libelle = t.Libelle,
ArtisteNom = t.Artiste?.Nom,
UrlJaquette = t.UrlJaquette,
Duree = t.Duree,
})
.ToList();
var artistes = this.titreRepository.FindAll()
.Select(t => t.Artiste)
.Where(a => !string.IsNullOrWhiteSpace(a.Nom)
&& !string.IsNullOrWhiteSpace(mot)
&& a.Nom.Contains(mot, StringComparison.OrdinalIgnoreCase))
.DistinctBy(a => a!.IdArtiste)
.OrderBy(a => a!.Nom)
.Select(a => new RechercheArtisteItem
{
Nom = a!.Nom,
NombreDeTitres = a.Titres?.Count ?? 0,
})
.ToList();
var vm = new RechercheIndexViewModel
public RechercheController(ILogger<RechercheController> logger, ITitreRepository titreRepository)
{
Mot = mot,
Artistes = artistes,
Titres = titres,
};
this.logger = logger;
this.titreRepository = titreRepository;
}
return this.View(vm);
[HttpPost("")]
public IActionResult Index(string mot)
{
this.logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot);
var titres = this.titreRepository.Search(mot)
.Concat(this.titreRepository.SearchByStyle(mot))
.DistinctBy(t => t.IdTitre)
.OrderBy(t => t.Libelle)
.Select(t => new TitreStyleItem
{
IdTitre = t.IdTitre,
Libelle = t.Libelle,
ArtisteNom = t.Artiste?.Nom,
UrlJaquette = t.UrlJaquette,
Duree = t.Duree,
})
.ToList();
var artistes = this.titreRepository.FindAll()
.Select(t => t.Artiste)
.Where(a => a != null
&& !string.IsNullOrWhiteSpace(a.Nom)
&& !string.IsNullOrWhiteSpace(mot)
&& a.Nom.Contains(mot, StringComparison.OrdinalIgnoreCase))
.DistinctBy(a => a!.IdArtiste)
.OrderBy(a => a!.Nom)
.Select(a => new RechercheArtisteItem
{
Nom = a!.Nom,
NombreDeTitres = a.Titres?.Count ?? 0,
})
.ToList();
var vm = new RechercheIndexViewModel
{
Mot = mot,
Artistes = artistes,
Titres = titres,
};
return this.View(vm);
}
}
}

View File

@@ -1,166 +1,171 @@
using Microsoft.AspNetCore.Mvc;
using Webzine.Entity;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.ViewModels.Titre;
// <copyright file="TitreController.cs" company=" Equipe 1 - ">
// Copyright (c) Equipe 1 - . All rights reserved.
// </copyright>
namespace Webzine.WebApplication.Controllers;
/// <summary>
/// Controleur responsable de la gestion des titres musicaux :
/// affichage des details, filtrage par style,
/// ajout de likes, commentaires et recherche.
/// </summary>
[Route("titre")]
public class TitreController : Controller
namespace Webzine.WebApplication.Controllers
{
private readonly ILogger<TitreController> _logger;
private readonly ITitreRepository _titreRepository;
using Microsoft.AspNetCore.Mvc;
using Webzine.Entity;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.ViewModels.Titre;
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="TitreController"/>.
/// Controleur responsable de la gestion des titres musicaux :
/// affichage des details, filtrage par style,
/// ajout de likes, commentaires et recherche.
/// </summary>
/// <param name="logger">Service de journalisation injecte.</param>
/// <param name="titreRepository">Repository des titres injecte.</param>
public TitreController(ILogger<TitreController> logger, ITitreRepository titreRepository)
[Route("titre")]
public class TitreController : Controller
{
this._logger = logger;
this._titreRepository = titreRepository;
private readonly ILogger<TitreController> logger;
private readonly ITitreRepository titreRepository;
this._logger.LogInformation("Initialisation du controleur TitreController.");
}
/// <summary>
/// Affiche le detail d'un titre specifique.
/// </summary>
/// <param name="id">Identifiant du titre.</param>
/// <returns>Vue des details ou 404 si introuvable.</returns>
[HttpGet("{id}")]
public IActionResult Details(int id)
{
this._logger.LogInformation("Demande d'affichage du detail pour le titre ID {Id}.", id);
var titre = this._titreRepository.Find(id);
if (titre == null)
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="TitreController"/>.
/// </summary>
/// <param name="logger">Service de journalisation injecte.</param>
/// <param name="titreRepository">Repository des titres injecte.</param>
public TitreController(ILogger<TitreController> logger, ITitreRepository titreRepository)
{
this._logger.LogWarning("Titre avec ID {Id} introuvable.", id);
return this.RedirectToAction("Index");
this.logger = logger;
this.titreRepository = titreRepository;
this.logger.LogInformation("Initialisation du controleur TitreController.");
}
var vm = new TitreDetail
/// <summary>
/// Affiche le detail d'un titre specifique.
/// </summary>
/// <param name="id">Identifiant du titre.</param>
/// <returns>Vue des details ou 404 si introuvable.</returns>
[HttpGet("{id}")]
public IActionResult Details(int id)
{
Details = new TitreContent
this.logger.LogInformation("Demande d'affichage du detail pour le titre ID {Id}.", id);
var titre = this.titreRepository.Find(id);
if (titre == null)
{
IdTitre = titre.IdTitre,
Libelle = titre.Libelle,
Chronique = titre.Chronique,
DateSortie = titre.DateSortie,
NbLikes = titre.NbLikes,
UrlJaquette = titre.UrlJaquette,
UrlEcoute = titre.UrlEcoute,
ArtisteNom = titre.Artiste.Nom,
Styles = titre.Styles,
Commentaires = titre.Commentaires,
},
CommentForm = new TitreComment
this.logger.LogWarning("Titre avec ID {Id} introuvable.", id);
return this.RedirectToAction("Index");
}
var vm = new TitreDetail
{
IdTitre = titre.IdTitre,
},
};
Details = new TitreContent
{
IdTitre = titre.IdTitre,
Libelle = titre.Libelle,
Chronique = titre.Chronique,
DateSortie = titre.DateSortie,
NbLikes = titre.NbLikes,
UrlJaquette = titre.UrlJaquette,
UrlEcoute = titre.UrlEcoute,
ArtisteNom = titre.Artiste.Nom,
Styles = titre.Styles,
Commentaires = titre.Commentaires,
},
CommentForm = new TitreComment
{
IdTitre = titre.IdTitre,
},
};
return this.View(vm);
}
/// <summary>
/// Affiche les titres correspondant a un style musical donne.
/// </summary>
/// <param name="style">Nom du style musical.</param>
/// <returns>Vue contenant la liste filtree.</returns>
[HttpGet("style/{style}")]
public IActionResult Style(string style)
{
this._logger.LogInformation("Recherche des titres pour le style : {Style}.", style);
var titresFiltres = this._titreRepository.SearchByStyle(style).ToList();
var vm = new TitreStyle
{
StyleName = style,
Titres = titresFiltres.Select(MapTitreItem).ToList(),
};
return this.View(vm);
}
/// <summary>
/// Ajoute un like a un titre.
/// </summary>
/// <param name="model">Modele contenant l'identifiant du titre.</param>
/// <returns>Redirection vers la page detail.</returns>
[HttpPost("like")]
public IActionResult Like(TitreLike model)
{
this._logger.LogInformation("Ajout d'un like pour le titre ID {Id}.", model.IdTitre);
var titre = this._titreRepository.Find(model.IdTitre);
if (titre == null)
{
this._logger.LogWarning("Impossible d'ajouter un like. Titre ID {Id} introuvable.", model.IdTitre);
return this.RedirectToAction("Index");
return this.View(vm);
}
titre.NbLikes++;
return this.RedirectToAction("Details", new { id = model.IdTitre });
}
/// <summary>
/// Ajoute un commentaire a un titre.
/// </summary>
/// <param name="model">Donnees du commentaire.</param>
/// <returns>Redirection vers la page detail.</returns>
[HttpPost("comment")]
public IActionResult Comment(TitreComment model)
{
if (!this.ModelState.IsValid)
/// <summary>
/// Affiche les titres correspondant a un style musical donne.
/// </summary>
/// <param name="style">Nom du style musical.</param>
/// <returns>Vue contenant la liste filtree.</returns>
[HttpGet("style/{style}")]
public IActionResult Style(string style)
{
this._logger.LogWarning("Echec de validation du modele de commentaire pour le titre ID {Id}.", model.IdTitre);
this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style);
var titresFiltres = this.titreRepository.SearchByStyle(style).ToList();
var vm = new TitreStyle
{
StyleName = style,
Titres = titresFiltres.Select(MapTitreItem).ToList(),
};
return this.View(vm);
}
/// <summary>
/// Ajoute un like a un titre.
/// </summary>
/// <param name="model">Modele contenant l'identifiant du titre.</param>
/// <returns>Redirection vers la page detail.</returns>
[HttpPost("like")]
public IActionResult Like(TitreLike model)
{
this.logger.LogInformation("Ajout d'un like pour le titre ID {Id}.", model.IdTitre);
var titre = this.titreRepository.Find(model.IdTitre);
if (titre == null)
{
this.logger.LogWarning("Impossible d'ajouter un like. Titre ID {Id} introuvable.", model.IdTitre);
return this.RedirectToAction("Index");
}
titre.NbLikes++;
return this.RedirectToAction("Details", new { id = model.IdTitre });
}
var titre = this._titreRepository.Find(model.IdTitre);
if (titre == null)
/// <summary>
/// Ajoute un commentaire a un titre.
/// </summary>
/// <param name="model">Donnees du commentaire.</param>
/// <returns>Redirection vers la page detail.</returns>
[HttpPost("comment")]
public IActionResult Comment(TitreComment model)
{
this._logger.LogWarning("Impossible d'ajouter le commentaire. Titre ID {Id} introuvable.", model.IdTitre);
return this.RedirectToAction("Index");
if (!this.ModelState.IsValid)
{
this.logger.LogWarning("Echec de validation du modele de commentaire pour le titre ID {Id}.", model.IdTitre);
return this.RedirectToAction("Details", new { id = model.IdTitre });
}
var titre = this.titreRepository.Find(model.IdTitre);
if (titre == null)
{
this.logger.LogWarning("Impossible d'ajouter le commentaire. Titre ID {Id} introuvable.", model.IdTitre);
return this.RedirectToAction("Index");
}
var commentaire = new Commentaire
{
Auteur = model.Auteur,
Contenu = model.Contenu,
DateCreation = DateTime.Now,
IdTitre = model.IdTitre,
};
titre.Commentaires.Add(commentaire);
this.logger.LogInformation("Commentaire ajoute avec succes au titre ID {Id}.", model.IdTitre);
return this.RedirectToAction("Details", new { id = model.IdTitre });
}
var commentaire = new Commentaire
private static TitreStyleItem MapTitreItem(Titre titre)
{
Auteur = model.Auteur,
Contenu = model.Contenu,
DateCreation = DateTime.Now,
IdTitre = model.IdTitre,
};
titre.Commentaires.Add(commentaire);
this._logger.LogInformation("Commentaire ajoute avec succes au titre ID {Id}.", model.IdTitre);
return this.RedirectToAction("Details", new { id = model.IdTitre });
}
private static TitreStyleItem MapTitreItem(Titre titre)
{
return new TitreStyleItem
{
IdTitre = titre.IdTitre,
Libelle = titre.Libelle,
ArtisteNom = titre.Artiste?.Nom,
UrlJaquette = titre.UrlJaquette,
Duree = titre.Duree,
};
return new TitreStyleItem
{
IdTitre = titre.IdTitre,
Libelle = titre.Libelle,
ArtisteNom = titre.Artiste?.Nom,
UrlJaquette = titre.UrlJaquette,
Duree = titre.Duree,
};
}
}
}

View File

@@ -36,6 +36,7 @@ try
builder.Services.AddScoped<IStyleRepository, DbStyleRepository>();
builder.Services.AddScoped<IArtisteRepository, DbArtisteRepository>();
builder.Services.AddScoped<ICommentaireRepository, DbCommentaireRepository>();
builder.Services.AddScoped<DbEntityRepository>();
}
else
{
@@ -45,13 +46,21 @@ try
//builder.Services.AddScoped<ICommentaireRepository, LocalCommentaireRepository>();
}
// https://learn.microsoft.com/fr-fr/aspnet/core/performance/response-compression?view=aspnetcore-10.0#configuration
// Ajoute le service de compression des réponses HTTP pour réduire la taille des données envoyées au client et améliorer les performances de l'application.
builder.Services.AddResponseCompression();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
db.Database.EnsureDeleted();
db.Database.EnsureCreated();
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
repo.SeedBaseDeDonnees();
}
app.UseResponseCompression();
// Active la possibilite de servir des fichiers statiques presents dans
@@ -65,12 +74,6 @@ try
},
});
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
db.Database.EnsureCreated();
}
// Active le middleware permettant le routage des requetes entrantes.
app.UseRouting();

View File

@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc;
using Webzine.Repository.Contracts;
namespace Webzine.WebApplication.ViewComponents
{
/// <summary>
/// View component pour la sidebar, récupère les styles depuis le repository.
/// </summary>
public class SidebarViewComponent : ViewComponent
{
private readonly IStyleRepository styleRepository;
/// <summary>
/// Initializes a new instance of the <see cref="SidebarViewComponent"/> class.
/// </summary>
/// <param name="styleRepository">Repository des styles injecté.</param>
public SidebarViewComponent(IStyleRepository styleRepository)
{
this.styleRepository = styleRepository;
}
/// <summary>
/// Récupère tous les styles triés par libellé et les passe à la vue.
/// </summary>
/// <returns>Une vue contenant la liste des styles.</returns>
public IViewComponentResult Invoke()
{
var styles = this.styleRepository.FindAll()
.OrderBy(s => s.Libelle)
.ToList();
return this.View(styles);
}
}
}

View File

@@ -1,18 +1,30 @@
namespace Webzine.WebApplication.ViewModels.Accueil
{
using Webzine.Entity;
/// <summary>
/// ViewModel pour la page d'accueil du webzine, affichant les derniers titres et les titres les plus populaires.
/// </summary>
public class AccueilIndexViewModel
{
/// <summary>
/// Définit la liste des derniers titres ajoutés au webzine.
/// Obtient ou définit la liste des derniers titres ajoutés au webzine.
/// </summary>
public List<Entity.Titre> DerniersTitres { get; set; } = [];
public List<Titre> DerniersTitres { get; set; } = new List<Titre>();
/// <summary>
/// Définit la liste des titres les plus populaires du webzine.
/// Obtient ou définit la liste des titres les plus populaires du webzine.
/// </summary>
public List<Entity.Titre> TopTitres { get; set; } = [];
public List<Titre> TopTitres { get; set; } = new List<Titre>();
/// <summary>
/// Obtient ou définit le nombre de titre disponible.
/// </summary>
// public int NombreDeTitre { get; set; } = 0;
/// <summary>
/// Obtient ou définit le nombre de titre paginé.
/// </summary>
// public int Pagination { get; set; } = 0;
}
}

View File

@@ -38,7 +38,7 @@
<!-- Chronique -->
<p class="mt-2 mb-3 text-muted">
@titre.Chronique
@(titre.Chronique.Length > 200 ? titre.Chronique.Substring(0, 200) + "..." : titre.Chronique)
</p>
<!-- Footer -->
@@ -87,7 +87,7 @@
<div class="card-body">
<a asp-controller="Titre" asp-action="Details" asp-route-id="@titre.IdTitre" class="card-link">
@titre.Album
@titre.Libelle
</a>
<br />
par

View File

@@ -58,7 +58,7 @@ else
<a asp-controller="Titre"
asp-action="Details"
asp-route-id="@titre.IdTitre"
class="text-primary fw-bold">
class="text-primary">
@titre.Libelle
</a>
</td>

View File

@@ -4,14 +4,15 @@
<div class="container">
<h1>Contact</h1>
<div>
<div class="my-2">
C.U.C.D.B - DIIAGE <br />
69 Avenue Aristide Briand<br />
21000 Dijon
</div>
<div>
<div class ="my-2">
<i class="fa-solid fa-phone"></i> Phone : 03 80 40 50 60<br />
<i class="fa-solid fa-envelope"></i> secretariat@cucdb.fr
<i class="fa-solid fa-envelope"></i> <span class="text-primary">secretariat@cucdb.fr</span>
</div>
</div>
@@ -21,43 +22,43 @@
<h2>Suivez-nous</h2>
<div class="row g-4 text-center">
<div class="col-md-4">
<a href="#" class="card h-100 p-4 shadow-sm border-0 bg-light-subtle">
<i class="fa-solid fa-link fa-3x text-primary mb-3"></i>
<a href="#" class="card h-100 p-4 border-0 bg-light">
<i class="fa-solid fa-link fa-3x text-primary mb-3 align-self-center"></i>
<div class="fw-bold text-primary">Site officiel du DIIAGE</div>
</a>
</div>
<div class="col-md-4">
<a href="#" class="card h-100 p-4 shadow-sm border-0 bg-light-subtle">
<i class="fa-brands fa-facebook fa-3x text-primary mb-3"></i>
<a href="#" class="card h-100 p-4 border-0 bg-light">
<i class="fa-brands fa-facebook fa-3x text-primary mb-3 align-self-center"></i>
<div class="fw-bold text-primary">Facebook</div>
</a>
</div>
<div class="col-md-4">
<a href="#" class="card h-100 p-4 shadow-sm border-0 bg-light-subtle">
<i class="fa-brands fa-instagram fa-3x text-primary mb-3"></i>
<a href="#" class="card h-100 p-4 border-0 bg-light">
<i class="fa-brands fa-instagram fa-3x text-primary mb-3 align-self-center"></i>
<div class="fw-bold text-primary">Instagram</div>
</a>
</div>
<div class="col-md-4">
<a href="#" class="card h-100 p-4 shadow-sm border-0 bg-light-subtle">
<i class="fa-brands fa-linkedin fa-3x text-primary mb-3"></i>
<a href="#" class="card h-100 p-4 border-0 bg-light">
<i class="fa-brands fa-linkedin fa-3x text-primary mb-3 align-self-center"></i>
<div class="fw-bold text-primary">LinkedIn</div>
</a>
</div>
<div class="col-md-4">
<a href="#" class="card h-100 p-4 shadow-sm border-0 bg-light-subtle">
<i class="fa-solid fa-map fa-3x text-primary mb-3"></i>
<a href="#" class="card h-100 p-4 border-0 bg-light">
<i class="fa-solid fa-map fa-3x text-primary mb-3 align-self-center"></i>
<div class="fw-bold text-primary">Google Maps</div>
</a>
</div>
<div class="col-md-4">
<a href="#" class="card h-100 p-4 shadow-sm border-0 bg-light-subtle">
<i class="fa-brands fa-twitter fa-3x text-primary mb-3"></i>
<a href="#" class="card h-100 p-4 border-0 bg-light">
<i class="fa-brands fa-twitter fa-3x text-primary mb-3 align-self-center"></i>
<div class="fw-bold text-primary">Twitter</div>
</a>
</div>

View File

@@ -0,0 +1,23 @@
@model IEnumerable<Webzine.Entity.Style>
<aside class="col-lg-3 d-none d-lg-block">
<div>
<h2>À propos</h2>
<p>Retrouvez les dernières pépites sur notre webzine.</p>
</div>
<div>
<h2>Styles</h2>
<ul>
@foreach (var style in Model)
{
<li>
<a asp-controller="Titre"
asp-action="Style"
asp-route-style="@style.Libelle">
@style.Libelle
</a>
</li>
}
</ul>
</div>
</aside>

View File

@@ -11,19 +11,19 @@
<link rel="stylesheet" href="~/css/app.css">
</head>
<body>
<partial name="_Header"/>
<div class="container-fluid flex-grow-1 py-4">
<div class="row">
<main class="col mx-3">
@RenderBody()
</main>
@if(ViewContext.RouteData.Values["area"]?.ToString() != "Administration")
{
<partial name="_Sidebar" />
}
</div>
<partial name="_Header"/>
<div class="container-fluid flex-grow-1 py-4">
<div class="row">
<main class="col mx-3">
@RenderBody()
</main>
@if(ViewContext.RouteData.Values["area"]?.ToString() != "Administration")
{
@await Component.InvokeAsync("Sidebar")
}
</div>
<partial name="_Footer" />
</div>
<partial name="_Footer" />
</body>
</html>

View File

@@ -1,51 +0,0 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
<aside class="col-lg-3 d-none d-lg-block">
<div>
<h2>À propos</h2>
<p>Retrouvez les dernières pépites sur notre webzine.</p>
</div>
<div>
<h2>Styles</h2>
<ul>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Acid house">Acid house</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Ambient">Ambient</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Deep house">Deep house</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Disco">Disco</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Downtempo">Downtempo</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Drum n bass">Drum n bass</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Dub Techno">Dub Techno</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Electro">Electro</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Electronic">Electronic</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Experimental">Experimental</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Funk">Funk</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Garage">Garage</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Hardcore">Hardcore</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Hardstyle">Hardstyle</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Hip hop">Hip hop</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="House">House</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Indie">Indie</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Industrial">Industrial</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Jazz">Jazz</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Latin">Latin</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Metal">Metal</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Minimal">Minimal</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Pop">Pop</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Progressive">Progressive</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Punk">Punk</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="R&B">R&B</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Rap">Rap</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Reggae">Reggae</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Rock">Rock</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Soul">Soul</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Techno">Techno</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Trance">Trance</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="Trip hop">Trip hop</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="UK garage">UK garage</a></li>
<li><a asp-controller="Titre" asp-action="Style" asp-route-id="World">World</a></li>
</ul>
</div>
</aside>

View File

@@ -6,6 +6,7 @@
}
},
"Webzine": {
// TODO : préciser les modes environnement et repo
"NombreDerniereChronique": 3,
"NombreDeTopTitres": 3
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

227
scripts/test-endpoints.sh Normal file
View File

@@ -0,0 +1,227 @@
#!/usr/bin/env bash
# =============================================================================
# test-endpoints.sh
# Teste tous les endpoints du Webzine et signale ceux qui dépassent le seuil.
#
# Usage :
# ./scripts/test-endpoints.sh [URL_BASE] [MAX_MS]
#
# Exemples :
# ./scripts/test-endpoints.sh # défauts : localhost:5038, 1000ms
# ./scripts/test-endpoints.sh http://localhost:5038 500
# =============================================================================
set -euo pipefail
BASE_URL="${1:-http://localhost:5038}"
MAX_MS="${2:-1000}"
RAPPORT_FICHIER="/tmp/webzine_rapport_endpoints.txt"
ECHECS=0
TOTAL=0
# ── Couleurs ──────────────────────────────────────────────────────────────────
ROUGE='\033[0;31m'
JAUNE='\033[1;33m'
VERT='\033[0;32m'
CYAN='\033[0;36m'
GRAS='\033[1m'
RESET='\033[0m'
# ── Fonctions utilitaires ──────────────────────────────────────────────────────
log() { echo -e "$*"; }
succes() { log "${VERT}[OK]${RESET} $*"; }
echec() { log "${ROUGE}[ÉCHEC]${RESET} $*"; ECHECS=$((ECHECS + 1)); }
lent() { log "${JAUNE}[LENT]${RESET} $*"; ECHECS=$((ECHECS + 1)); }
info() { log "${CYAN}$*${RESET}"; }
# ── verifier_endpoint ─────────────────────────────────────────────────────────
# Arguments :
# $1 Méthode HTTP (GET | POST)
# $2 URL (absolue)
# $3 Libellé (texte lisible)
# $4 Corps (optionnel, pour POST)
# $5 Content-Type (optionnel, défaut : application/x-www-form-urlencoded)
# ─────────────────────────────────────────────────────────────────────────────
verifier_endpoint() {
local METHODE="${1:-GET}"
local URL="$2"
local LIBELLE="$3"
local CORPS="${4:-}"
local TYPE_CONTENU="${5:-application/x-www-form-urlencoded}"
TOTAL=$((TOTAL + 1))
# Exécution de la requête selon la méthode HTTP
if [ "$METHODE" = "POST" ] && [ -n "$CORPS" ]; then
REPONSE=$(curl -s -o /dev/null \
-w "%{http_code}|%{time_total}" \
-X POST \
-H "Content-Type: $TYPE_CONTENU" \
-d "$CORPS" \
--max-time 10 \
"$URL" 2>&1) || REPONSE="000|9.999"
else
REPONSE=$(curl -s -o /dev/null \
-w "%{http_code}|%{time_total}" \
-X GET \
--max-time 10 \
--location \
"$URL" 2>&1) || REPONSE="000|9.999"
fi
# Extraction du code HTTP et du temps de réponse
CODE_HTTP=$(echo "$REPONSE" | cut -d'|' -f1)
TEMPS_TOTAL=$(echo "$REPONSE" | cut -d'|' -f2)
# Conversion en millisecondes entières — awk évite les problèmes de locale décimale
TEMPS_MS=$(awk "BEGIN {printf \"%.0f\", $TEMPS_TOTAL * 1000}")
# Évaluation du résultat : erreur serveur, dépassement de seuil ou succès
if [ "${CODE_HTTP:-0}" -ge 500 ] 2>/dev/null; then
echec "$LIBELLE → HTTP $CODE_HTTP (${TEMPS_MS}ms)"
echo "[ÉCHEC] $LIBELLE → HTTP $CODE_HTTP (${TEMPS_MS}ms)" >> "$RAPPORT_FICHIER"
elif [ "${TEMPS_MS:-99999}" -gt "$MAX_MS" ] 2>/dev/null; then
lent "$LIBELLE${TEMPS_MS}ms dépasse le seuil de ${MAX_MS}ms"
echo "[LENT] $LIBELLE${TEMPS_MS}ms (limite : ${MAX_MS}ms)" >> "$RAPPORT_FICHIER"
else
succes "$LIBELLE${TEMPS_MS}ms"
echo "[OK] $LIBELLE${TEMPS_MS}ms" >> "$RAPPORT_FICHIER"
fi
}
# =============================================================================
# PROGRAMME PRINCIPAL
# =============================================================================
# Initialisation du fichier de rapport
> "$RAPPORT_FICHIER"
cat >> "$RAPPORT_FICHIER" <<EOF
=== Rapport de performance des endpoints Webzine ===
URL de base : $BASE_URL
Seuil : ${MAX_MS}ms
Date : $(date -u +"%Y-%m-%dT%H:%M:%SZ")
EOF
log ""
info "╔══════════════════════════════════════════════════════════╗"
info "║ Webzine Test de performance des endpoints ║"
info "╚══════════════════════════════════════════════════════════╝"
info " URL de base : $BASE_URL"
info " Seuil : ${MAX_MS}ms"
log ""
# ── SECTION PUBLIQUE ──────────────────────────────────────────────────────────
info "── Endpoints publics ─────────────────────────────────────"
verifier_endpoint GET "$BASE_URL/" "GET / (Accueil)"
verifier_endpoint GET "$BASE_URL/Accueil" "GET /Accueil"
verifier_endpoint GET "$BASE_URL/Contact" "GET /Contact"
log ""
info "── Titre Détails ───────────────────────────────────────"
# Test des pages de détail pour les 5 premiers titres
for ID in 1 2 3 4 5; do
verifier_endpoint GET "$BASE_URL/titre/$ID" "GET /titre/$ID"
done
log ""
info "── Titre Par style ─────────────────────────────────────"
# Test du filtrage par style musical
STYLES=("Rock" "Pop" "Rap" "Jazz" "Metal" "Electronic" "Hip-Hop" "Soul" "Funk")
for STYLE in "${STYLES[@]}"; do
ENCODE=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$STYLE'))" 2>/dev/null || echo "$STYLE")
verifier_endpoint GET "$BASE_URL/titre/style/$ENCODE" "GET /titre/style/$STYLE"
done
log ""
info "── Artiste ───────────────────────────────────────────────"
# Test des pages artiste avec des noms en kebab-case
ARTISTES=("fatal-bazooka" "daft-punk" "justice" "kraftwerk")
for ARTISTE in "${ARTISTES[@]}"; do
verifier_endpoint GET "$BASE_URL/artiste/$ARTISTE" "GET /artiste/$ARTISTE"
done
log ""
info "── Recherche (POST) ──────────────────────────────────────"
# Test de la recherche plein texte par mots-clés
MOTS=("rock" "jazz" "pop" "metal")
for MOT in "${MOTS[@]}"; do
verifier_endpoint POST "$BASE_URL/recherche" \
"POST /recherche (mot=$MOT)" \
"mot=$MOT"
done
log ""
# ── SECTION ADMINISTRATION ────────────────────────────────────────────────────
info "── Administration Tableau de bord ──────────────────────"
verifier_endpoint GET "$BASE_URL/Administration/Dashboard" "GET /Administration/Dashboard"
log ""
info "── Administration Artiste ──────────────────────────────"
verifier_endpoint GET "$BASE_URL/Administration/Artiste" "GET /Administration/Artiste (liste)"
verifier_endpoint GET "$BASE_URL/Administration/Artiste/Create" "GET /Administration/Artiste/Create"
verifier_endpoint GET "$BASE_URL/Administration/Artiste/Edit/1" "GET /Administration/Artiste/Edit/1"
verifier_endpoint GET "$BASE_URL/Administration/Artiste/Delete/1" "GET /Administration/Artiste/Delete/1"
log ""
info "── Administration Commentaire ──────────────────────────"
verifier_endpoint GET "$BASE_URL/Administration/Commentaire" "GET /Administration/Commentaire (liste)"
verifier_endpoint GET "$BASE_URL/Administration/Commentaire/Delete/1" "GET /Administration/Commentaire/Delete/1"
log ""
info "── Administration Style ────────────────────────────────"
verifier_endpoint GET "$BASE_URL/Administration/Style" "GET /Administration/Style (liste)"
verifier_endpoint GET "$BASE_URL/Administration/Style/Create" "GET /Administration/Style/Create"
verifier_endpoint GET "$BASE_URL/Administration/Style/Edit/1" "GET /Administration/Style/Edit/1"
verifier_endpoint GET "$BASE_URL/Administration/Style/Delete/1" "GET /Administration/Style/Delete/1"
log ""
info "── Administration Titre ────────────────────────────────"
verifier_endpoint GET "$BASE_URL/Administration/Titre" "GET /Administration/Titre (liste)"
verifier_endpoint GET "$BASE_URL/Administration/Titre/Create" "GET /Administration/Titre/Create"
verifier_endpoint GET "$BASE_URL/Administration/Titre/Edit/1" "GET /Administration/Titre/Edit/1"
verifier_endpoint GET "$BASE_URL/Administration/Titre/Delete/1" "GET /Administration/Titre/Delete/1"
# ── RÉCAPITULATIF ─────────────────────────────────────────────────────────────
REUSSIS=$((TOTAL - ECHECS))
log ""
info "╔══════════════════════════════════════════════════════════╗"
info "║ Résultats ║"
info "╚══════════════════════════════════════════════════════════╝"
log " Total : ${TOTAL}"
log " ${VERT}Réussis${RESET} : ${REUSSIS}"
if [ "$ECHECS" -gt 0 ]; then
log " ${ROUGE}Échecs${RESET} : ${ECHECS}"
log ""
log "${ROUGE}${GRAS}❌ ENDPOINTS EN ÉCHEC :${RESET}"
# Affichage de tous les endpoints ayant échoué ou dépassé le seuil
grep -E "^\[(ÉCHEC|LENT)\]" "$RAPPORT_FICHIER" | while IFS= read -r ligne; do
log " ${ROUGE}${RESET} $ligne"
done
log ""
log "${ROUGE}La PR doit être rejetée. Corrigez les endpoints ci-dessus.${RESET}"
else
log " ${VERT}Échecs${RESET} : 0"
log ""
log "${VERT}${GRAS}✅ Tous les endpoints respectent le seuil de ${MAX_MS}ms.${RESET}"
fi
log ""
log "Rapport complet enregistré dans : ${RAPPORT_FICHIER}"
log ""
# Écriture du récapitulatif dans le rapport
cat >> "$RAPPORT_FICHIER" <<EOF
=== Récapitulatif ===
Total : $TOTAL
Réussis : $REUSSIS
Échecs : $ECHECS
EOF
# Code de sortie non nul si des échecs ont été détectés — permet à la CI de bloquer
exit "$ECHECS"