Browse Source

调整验证逻辑

guqiang 4 days ago
parent
commit
d5308d25b3

+ 1 - 1
src/Hotline.Api/config/appsettings.Development.json

@@ -110,7 +110,7 @@
     }
   },
   "DatabaseConfiguration": {
-    "ApplyDbMigrations": false,
+    "ApplyDbMigrations": true,
     "ApplySeed": false
   },
   "MqConfiguration": {

+ 1 - 1
src/Hotline/Validators/Exams/ExamManages/AddExtractRuleDtoValidator.cs

@@ -15,7 +15,7 @@ namespace Hotline.Validators.Exams.ExamManages
         public AddExtractRuleDtoValidator()
         {
             RuleFor(m => m.Name).NotEmpty().WithMessage(x=>string.Format(ExamErrorMessage.IsRequired,x.GetType().GetDescription(nameof(ExtractRuleDto.Name))));
-            RuleFor(m => m.RuleType).NotEmpty().WithMessage(x=>string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.RuleType))));
+            RuleFor(m => m.RuleType).NotNull().WithMessage(x=>string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.RuleType))));
 
             RuleForEach(m => m.TagQuestionDtos).SetValidator(new AddTagQuestionDtoValidator());
 

+ 1 - 1
src/Hotline/Validators/Exams/ExamManages/AddTagQuestionDtoValidator.cs

@@ -10,7 +10,7 @@ namespace Hotline.Validators.Exams.ExamManages
     {
         public AddTagQuestionDtoValidator()
         {
-            RuleFor(m => m.QuestionType).NotEmpty().WithMessage(x=>string.Format(ExamErrorMessage.IsRequired,x.GetType().GetDescription(nameof(ExamTagQuestion.QuestionType))));
+            RuleFor(m => m.QuestionType).NotNull().WithMessage(x=>string.Format(ExamErrorMessage.IsRequired,x.GetType().GetDescription(nameof(ExamTagQuestion.QuestionType))));
             RuleFor(m=>m.Count).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.Count))));
             RuleFor(m => m.TagId).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, typeof(ExamTag).GetDescription()));
         }

+ 1 - 1
src/Hotline/Validators/Exams/ExamManages/UpdateExtractRuleDtoValidator.cs

@@ -13,7 +13,7 @@ namespace Hotline.Validators.Exams.ExamManages
             RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.Id))));
 
             RuleFor(m => m.Name).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.Name))));
-            RuleFor(m => m.RuleType).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.RuleType))));
+            RuleFor(m => m.RuleType).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.RuleType))));
 
             RuleForEach(m => m.TagQuestionDtos).SetValidator(new UpdateTagQuestionDtoValidator());
 

+ 1 - 1
src/Hotline/Validators/Exams/ExamManages/UpdateTagQuestionDtoValidator.cs

@@ -12,7 +12,7 @@ namespace Hotline.Validators.Exams.ExamManages
         public UpdateTagQuestionDtoValidator()
         {
             RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.Id))));
-            RuleFor(m => m.QuestionType).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.QuestionType))));
+            RuleFor(m => m.QuestionType).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.QuestionType))));
             RuleFor(m => m.Count).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.Count))));
             RuleFor(m => m.TagId).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, typeof(ExamTag).GetDescription()));
         }

+ 3 - 3
src/Hotline/Validators/Exams/Questions/AddQuestionDtoValidator.cs

@@ -11,9 +11,9 @@ namespace Hotline.Validators.Exams
         public AddQuestionDtoValidator()
         {
             RuleFor(m => m.Title).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Title))));
-            RuleFor(m => m.DifficultyLevel).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.DifficultyLevel))));
-            RuleFor(m => m.FormalEnable).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.FormalEnable))));
-            RuleFor(m => m.SimulateEnable).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.SimulateEnable))));
+            RuleFor(m => m.DifficultyLevel).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.DifficultyLevel))));
+            RuleFor(m => m.FormalEnable).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.FormalEnable))));
+            RuleFor(m => m.SimulateEnable).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.SimulateEnable))));
 
             RuleForEach(m => m.QuestionSourcewareDtos).SetValidator(new AddQuestionSourcewareDtoValidator());
 

+ 3 - 3
src/Hotline/Validators/Exams/Questions/UpdateQuestionDtoValidator.cs

@@ -13,9 +13,9 @@ namespace Hotline.Validators.Exams
         {
             RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Id))));
             RuleFor(m => m.Title).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Title))));
-            RuleFor(m => m.DifficultyLevel).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.DifficultyLevel))));
-            RuleFor(m => m.FormalEnable).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.FormalEnable))));
-            RuleFor(m => m.SimulateEnable).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.SimulateEnable))));
+            RuleFor(m => m.DifficultyLevel).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.DifficultyLevel))));
+            RuleFor(m => m.FormalEnable).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.FormalEnable))));
+            RuleFor(m => m.SimulateEnable).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.SimulateEnable))));
 
             RuleForEach(m => m.QuestionSourcewareDtos).SetValidator(new UpdateQuestionSourcewareDtoValidator());