Add comprehensive validation system with runtime configuration
Implements a flexible validation framework for student rankings, team assignments, and team composition with administrator-configurable rules and thresholds. Validation System: - Reflection-based rule discovery eliminates manual registration - Base classes (RequiredEventTypeRuleBase, EventCountThresholdRuleBase) reduce code duplication by ~250 lines - 12 validation rules covering event requirements, counts, and team constraints - Configurable severity levels (Warning/Error) per rule type - ValidationService with caching for optimal performance - Rules apply contextually (StudentRanking, StudentAssignment, TeamComposition) Configuration & Admin UI: - ValidationSettings admin page for editing thresholds and severity levels - ChapterSettings admin page for editing chapter information - Settings stored in Data/appsettings.json for runtime configuration - JSON config works in both development and production environments - Auto-creates Data directory and config template on first run User Experience: - ValidationWarnings component displays inline warnings/errors - Integrated in Event Ranking, Registration, and Team Assignment pages - Color-coded severity indicators (warning yellow, error red) - Includes "Too Many Regional Events" rule (max 3 recommended) Technical Improvements: - Template Method pattern for rule base classes - Singleton rule instances with lazy initialization - Configuration loaded via IConfiguration with fallback to defaults - Safe JSON updates preserve other appsettings sections
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Core.Entities;
|
||||
using Core.Validation.Rules.BaseRules;
|
||||
|
||||
namespace Core.Validation.Rules.StudentAssignmentRules;
|
||||
|
||||
/// <summary>
|
||||
/// Validation rule that checks if a student has too few event assignments
|
||||
/// </summary>
|
||||
public class TooFewEventsRule : EventCountThresholdRuleBase
|
||||
{
|
||||
protected override int GetCount(StudentEventStatistics statistics) => statistics.EventCount;
|
||||
|
||||
protected override int GetThreshold(ValidationConfiguration config) => config.MinRecommendedEvents;
|
||||
|
||||
protected override bool ViolatesThreshold(int count, int threshold) => count < threshold;
|
||||
|
||||
protected override ValidationSeverity GetBaseSeverity(ValidationConfiguration config) => config.EventCountSeverity;
|
||||
|
||||
protected override int? GetCriticalThreshold(ValidationConfiguration config) => config.MinCriticalEvents;
|
||||
|
||||
protected override bool ViolatesCriticalThreshold(int count, int criticalThreshold) => count < criticalThreshold;
|
||||
|
||||
protected override string Code => "TOO_FEW_EVENTS";
|
||||
|
||||
protected override string GetMessage(int count, int threshold) =>
|
||||
$"Student has {count} events (min recommended: {threshold})";
|
||||
|
||||
protected override Dictionary<string, object> BuildAdditionalMetadata(StudentEventStatistics statistics, ValidationConfiguration config)
|
||||
{
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
{ "MinRecommended", config.MinRecommendedEvents },
|
||||
{ "MinCritical", config.MinCriticalEvents }
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user