-
Notifications
You must be signed in to change notification settings - Fork 0
Feature: Add Commander Management System #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- 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
There was a problem hiding this 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.
| var results = _commanders | ||
| .Where(c => c.ColorIdentity.OrderBy(x => x).SequenceEqual(colors.OrderBy(x => x))) |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
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.
| 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)) |
| var colorList = colors.Split(',') | ||
| .Select(c => Enum.Parse<ManaColor>(c.Trim(), true)) | ||
| .ToList(); |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
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.
| 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}."); | |
| } |
| } | ||
|
|
||
| var commander = await _commanderService.GetCommanderByIdAsync(id); | ||
| return Ok(new { CommanderId = id, CurrentZone = commander!.CurrentZone, CommanderTaxCount = commander.CommanderTaxCount }); |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
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.
| 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 }); |
Description
Ajout complet de la fonctionnalité de gestion des Commanders pour Magic: The Gathering.
Modifications apportées
✅ Modèle TotoCommander créé avec :
✅ ITotoCommanderService : Interface de service complète
✅ TotoCommanderService : Implémentation avec :
✅ 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 commandersGET /api/TotoCommanders/{id}- Commander par IDGET /api/TotoCommanders/search/{name}- Recherche par nomGET /api/TotoCommanders/color-identity- Filtrage par identité de couleurGET /api/TotoCommanders/color/{color}- Filtrage par couleurGET /api/TotoCommanders/type/{type}- Filtrage par typeGET /api/TotoCommanders/power/{minPower}- Filtrage par puissance minimaleGET /api/TotoCommanders/toughness/{minToughness}- Filtrage par endurance minimaleGET /api/TotoCommanders/partner- Liste des commanders avec partnerGET /api/TotoCommanders/ability/{ability}- Filtrage par capacitéPOST /api/TotoCommanders- Ajout d'un nouveau commanderPUT /api/TotoCommanders/{id}- Mise à jour d'un commanderDELETE /api/TotoCommanders/{id}- Suppression d'un commanderGET /api/TotoCommanders/{id}/tax- Calcul du commander taxPOST /api/TotoCommanders/{id}/damage- Enregistrement de dommagesGET /api/TotoCommanders/{id}/damage/{playerId}- Dommages totaux à un joueurPOST /api/TotoCommanders/{id}/move- Déplacement de zoneCompilation
✅ Le build compile sans erreur ni warning
Tests
Checklist
Closes #2