Don't seperately parse status, let the JSON decoder do this for now
This commit is contained in:
@@ -26,8 +26,7 @@ public class CreateMissionLaunch(MissionControlContext dbContext)
|
||||
var missionLaunch = new MissionLaunch
|
||||
{
|
||||
ScheduledFor = req.ScheduledFor,
|
||||
// Validated in `CreateMissionLaunchRequestValidator`
|
||||
Status = Enum.Parse<MissionLaunchStatus>(req.Status, true),
|
||||
Status = req.Status,
|
||||
MissionId = req.MissionId,
|
||||
};
|
||||
|
||||
@@ -43,9 +42,7 @@ public record CreateMissionLaunchRequest
|
||||
public Guid MissionId { get; init; }
|
||||
public required DateTimeOffset ScheduledFor { get; init; }
|
||||
|
||||
// Define as a string here so it can be safely deserialized into its enum type, with a validation message when unable to do so
|
||||
// Otherwise, we return a serialization error that is not assigned to a specific field
|
||||
public required string Status { get; init; }
|
||||
public required MissionLaunchStatus Status { get; init; }
|
||||
}
|
||||
|
||||
public class CreateMissionLaunchRequestValidator : Validator<CreateMissionLaunchRequest>
|
||||
@@ -55,6 +52,5 @@ public class CreateMissionLaunchRequestValidator : Validator<CreateMissionLaunch
|
||||
RuleFor(req => req.MissionId)
|
||||
.NotEqual(Guid.Empty)
|
||||
.WithMessage("Please provide a non-zero GUID.");
|
||||
RuleFor(req => req.Status).IsEnumName(typeof(MissionLaunchStatus), false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user