Skip to content

Conversation

@evan-boissonnot
Copy link
Contributor

Description

Ajout complet de la fonctionnalité de gestion des Commanders pour Magic: The Gathering.

Modifications apportées

Modèle TotoCommander créé avec :

  • Propriétés standards (nom, coût, puissance, endurance, etc.)
  • Color identity pour les restrictions de deck
  • Gestion du partner et "partner with"
  • Système de commander tax
  • Suivi des dommages de commander par joueur
  • Gestion des zones (Command Zone, Battlefield, etc.)

ITotoCommanderService : Interface de service complète

TotoCommanderService : Implémentation avec :

  • CRUD complet
  • 6 commanders de démonstration (Atraxa, Muldrotha, Thrasios, Edgar Markov, Kenrith, Tymna)
  • Filtres avancés (couleur, type, puissance, endurance, capacités, partner)
  • Calcul automatique du commander tax
  • Enregistrement des dommages de commander
  • Gestion du déplacement entre zones

TotoCommandersController : API REST complète avec 16 endpoints

Enregistrement du service dans Program.cs

Fichier commanders.http avec 40 scénarios de test

Endpoints ajoutés

  • GET /api/TotoCommanders - Liste tous les commanders
  • GET /api/TotoCommanders/{id} - Commander par ID
  • GET /api/TotoCommanders/search/{name} - Recherche par nom
  • GET /api/TotoCommanders/color-identity - Filtrage par identité de couleur
  • GET /api/TotoCommanders/color/{color} - Filtrage par couleur
  • GET /api/TotoCommanders/type/{type} - Filtrage par type
  • GET /api/TotoCommanders/power/{minPower} - Filtrage par puissance minimale
  • GET /api/TotoCommanders/toughness/{minToughness} - Filtrage par endurance minimale
  • GET /api/TotoCommanders/partner - Liste des commanders avec partner
  • GET /api/TotoCommanders/ability/{ability} - Filtrage par capacité
  • POST /api/TotoCommanders - Ajout d'un nouveau commander
  • PUT /api/TotoCommanders/{id} - Mise à jour d'un commander
  • DELETE /api/TotoCommanders/{id} - Suppression d'un commander
  • GET /api/TotoCommanders/{id}/tax - Calcul du commander tax
  • POST /api/TotoCommanders/{id}/damage - Enregistrement de dommages
  • GET /api/TotoCommanders/{id}/damage/{playerId} - Dommages totaux à un joueur
  • POST /api/TotoCommanders/{id}/move - Déplacement de zone

Compilation

✅ Le build compile sans erreur ni warning

Tests

⚠️ Tests unitaires créés mais nécessitent refactoring de la structure des projets de test (hors scope de cette PR)

Checklist

  • Code suit les conventions de nommage Microsoft .NET
  • Préfixe "Toto" appliqué à toutes les classes
  • Service enregistré dans l'injection de dépendances
  • Build compile sans erreur
  • Documentation XML complète
  • Fichier HTTP de test fourni
  • Commit suit la convention Conventional Commits

Closes #2

- Add TotoCommander model with color identity, partner abilities, commander tax, and damage tracking
- Add ITotoCommanderService interface
- Implement TotoCommanderService with sample data
- Add TotoCommandersController with complete REST API endpoints
- Register service in Program.cs
- Add commanders.http file with 40 test scenarios

Closes #2
Copilot AI review requested due to automatic review settings October 16, 2025 15:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a complete Commander management system for Magic: The Gathering, implementing a comprehensive REST API for managing commander cards with support for game mechanics such as commander tax, damage tracking, and zone management.

Key changes:

  • Added TotoCommander model with full Magic: The Gathering commander properties including color identity, partner mechanics, and game state tracking
  • Implemented ITotoCommanderService interface and TotoCommanderService with 14 methods covering CRUD operations and game-specific features
  • Created TotoCommandersController with 16 REST endpoints for complete commander management

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
game-sessions/Models/Commander.cs Defines TotoCommander model and CommanderZone enum with properties for card attributes and game state
game-sessions/Services/ICommanderService.cs Declares ITotoCommanderService interface with methods for commander operations
game-sessions/Services/CommanderService.cs Implements commander service with in-memory storage and 6 sample commanders
game-sessions/Controllers/CommandersController.cs Provides 16 REST API endpoints for commander management operations
game-sessions/Program.cs Registers ITotoCommanderService and ITotoLandService in dependency injection
game-sessions/commanders.http Contains 40 test scenarios for the commander API endpoints

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +45 to +46
var results = _commanders
.Where(c => c.ColorIdentity.OrderBy(x => x).SequenceEqual(colors.OrderBy(x => x)))
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The color identity comparison performs ordering on every iteration. Consider pre-sorting the input colors list once before the LINQ query, or use a HashSet-based comparison for better performance when filtering large collections.

Suggested change
var results = _commanders
.Where(c => c.ColorIdentity.OrderBy(x => x).SequenceEqual(colors.OrderBy(x => x)))
var colorSet = new HashSet<ManaColor>(colors);
var results = _commanders
.Where(c => new HashSet<ManaColor>(c.ColorIdentity).SetEquals(colorSet))

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +76
var colorList = colors.Split(',')
.Select(c => Enum.Parse<ManaColor>(c.Trim(), true))
.ToList();
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum.Parse will throw an exception for invalid color values. Wrap this in a try-catch block and return a BadRequest with a descriptive error message listing valid ManaColor values when parsing fails.

Suggested change
var colorList = colors.Split(',')
.Select(c => Enum.Parse<ManaColor>(c.Trim(), true))
.ToList();
var colorStrings = colors.Split(',').Select(c => c.Trim()).ToList();
var colorList = new List<ManaColor>();
var invalidColors = new List<string>();
foreach (var colorStr in colorStrings)
{
if (Enum.TryParse<ManaColor>(colorStr, true, out var colorValue))
{
colorList.Add(colorValue);
}
else
{
invalidColors.Add(colorStr);
}
}
if (invalidColors.Any())
{
var validValues = string.Join(", ", Enum.GetNames(typeof(ManaColor)));
return BadRequest($"Invalid color value(s): {string.Join(", ", invalidColors)}. Valid ManaColor values are: {validValues}.");
}

Copilot uses AI. Check for mistakes.
}

var commander = await _commanderService.GetCommanderByIdAsync(id);
return Ok(new { CommanderId = id, CurrentZone = commander!.CurrentZone, CommanderTaxCount = commander.CommanderTaxCount });
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null-forgiving operator (!) is used after checking success, but there's no guarantee the commander still exists between the MoveCommanderToZoneAsync call and this GetCommanderByIdAsync call in a concurrent environment. The service uses in-memory storage without thread safety, creating a potential race condition.

Suggested change
return Ok(new { CommanderId = id, CurrentZone = commander!.CurrentZone, CommanderTaxCount = commander.CommanderTaxCount });
if (commander == null)
{
return NotFound($"Commander with ID {id} not found after move.");
}
return Ok(new { CommanderId = id, CurrentZone = commander.CurrentZone, CommanderTaxCount = commander.CommanderTaxCount });

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Ajout d'un Commander

2 participants