refactor: Change structure of processed QP object

json-serializing-nullable-fields-issue
Robert Dailey 9 months ago
parent de0c6be1d9
commit c033dd8a13

@ -7,8 +7,9 @@ namespace Recyclarr.Cli.Pipelines.QualityProfile.PipelinePhases;
public record ProcessedQualityProfileScore(string TrashId, string CfName, int FormatId, int Score);
public record ProcessedQualityProfileData(QualityProfileConfig Profile)
public record ProcessedQualityProfileData
{
public required QualityProfileConfig Profile { get; init; }
public bool ShouldCreate { get; init; } = true;
public IList<ProcessedQualityProfileScore> CfScores { get; init; } = new List<ProcessedQualityProfileScore>();
}
@ -39,7 +40,7 @@ public class QualityProfileConfigPhase
.Select(y => (x.Profile, Cf: y)));
var allProfiles = config.QualityProfiles
.Select(x => new ProcessedQualityProfileData(x))
.Select(x => new ProcessedQualityProfileData {Profile = x})
.ToDictionary(x => x.Profile.Name, x => x, StringComparer.InvariantCultureIgnoreCase);
foreach (var (profile, cf) in profileAndCfs)
@ -51,8 +52,9 @@ public class QualityProfileConfigPhase
// If the user did not specify a quality profile in their config, we still create the QP object
// for consistency (at the very least for the name).
allProfiles[profile.Name] = profileCfs =
new ProcessedQualityProfileData(new QualityProfileConfig {Name = profile.Name})
new ProcessedQualityProfileData
{
Profile = new QualityProfileConfig {Name = profile.Name},
// The user must explicitly specify a profile in the top-level `quality_profiles` section of
// their config, otherwise we do not implicitly create them in the service.
ShouldCreate = false

@ -29,12 +29,22 @@ public static class NewQp
bool resetUnmatchedScores,
params (string CfName, string TrashId, int FormatId, int Score)[] scores)
{
return new ProcessedQualityProfileData(new QualityProfileConfig
var profileConfig = new QualityProfileConfig
{
Name = profileName,
ResetUnmatchedScores = resetUnmatchedScores
})
};
return Processed(profileConfig, scores);
}
public static ProcessedQualityProfileData Processed(
QualityProfileConfig profileConfig,
params (string CfName, string TrashId, int FormatId, int Score)[] scores)
{
return new ProcessedQualityProfileData
{
Profile = profileConfig,
CfScores = scores
.Select(x => new ProcessedQualityProfileScore(x.TrashId, x.CfName, x.FormatId, x.Score))
.ToList()

@ -53,14 +53,17 @@ public class QualityProfileTransactionPhaseTest
{
var configData = new[]
{
new ProcessedQualityProfileData(new QualityProfileConfig
new ProcessedQualityProfileData
{
Name = "profile1",
Qualities = new[]
Profile = new QualityProfileConfig
{
new QualityProfileQualityConfig {Name = "quality1", Enabled = true}
Name = "profile1",
Qualities = new[]
{
new QualityProfileQualityConfig {Name = "quality1", Enabled = true}
}
}
})
}
};
var dtos = new[]

@ -15,14 +15,8 @@ public class UpdatedQualityProfileTest
{
var profile = new UpdatedQualityProfile
{
ProfileDto = new QualityProfileDto
{
Name = "dto_name"
},
ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig
{
Name = "config_name"
}),
ProfileDto = new QualityProfileDto {Name = "dto_name"},
ProfileConfig = NewQp.Processed("config_name"),
UpdateReason = QualityProfileUpdateReason.New
};
@ -35,10 +29,7 @@ public class UpdatedQualityProfileTest
var profile = new UpdatedQualityProfile
{
ProfileDto = new QualityProfileDto(),
ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig
{
Name = "config_name"
}),
ProfileConfig = NewQp.Processed("config_name"),
UpdateReason = QualityProfileUpdateReason.New
};
@ -59,7 +50,7 @@ public class UpdatedQualityProfileTest
UpgradeAllowed = false,
Cutoff = 1
},
ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig
ProfileConfig = NewQp.Processed(new QualityProfileConfig
{
Name = "config_name",
MinFormatScore = 110,
@ -109,7 +100,7 @@ public class UpdatedQualityProfileTest
NewQp.QualityDto(9, "Quality Item 9", true)
}
},
ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig()),
ProfileConfig = NewQp.Processed(""),
UpdatedQualities = new UpdatedQualities
{
NumWantedItems = 0,
@ -135,7 +126,7 @@ public class UpdatedQualityProfileTest
var profile = new UpdatedQualityProfile
{
ProfileDto = new QualityProfileDto {Name = ""},
ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig {Name = "config_name"}),
ProfileConfig = NewQp.Processed("config_name"),
UpdatedQualities = new UpdatedQualities
{
Items = new[]
@ -164,7 +155,7 @@ public class UpdatedQualityProfileTest
NewQp.QualityDto(9, "Quality Item 9", true)
}
},
ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig
ProfileConfig = NewQp.Processed(new QualityProfileConfig
{
UpgradeUntilQuality = "Quality Item 2"
}),
@ -200,7 +191,7 @@ public class UpdatedQualityProfileTest
NewQp.QualityDto(9, "Quality Item 9", true)
}
},
ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig
ProfileConfig = NewQp.Processed(new QualityProfileConfig
{
UpgradeUntilQuality = "Quality Item 9"
}),
@ -236,8 +227,9 @@ public class UpdatedQualityProfileTest
NewQp.QualityDto(9, "Quality Item 9", true)
}
},
ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig
ProfileConfig = NewQp.Processed(new QualityProfileConfig
{
// todo: Why is this commented out?
// UpgradeUntilQuality = "Quality Item 9"
}),
UpdatedQualities = new UpdatedQualities

@ -28,7 +28,7 @@ public class UpdatedQualityProfileValidatorTest
NewQp.UpdatedScore("foo4", 0, 100, FormatScoreUpdateReason.Reset)
},
ProfileDto = new QualityProfileDto {Name = "ProfileName"},
ProfileConfig = new ProcessedQualityProfileData(profileConfig),
ProfileConfig = NewQp.Processed(profileConfig),
UpdateReason = QualityProfileUpdateReason.Changed
};
@ -65,7 +65,7 @@ public class UpdatedQualityProfileValidatorTest
InvalidQualityNames = new[] {"foo1"}
},
ProfileDto = new QualityProfileDto(),
ProfileConfig = new ProcessedQualityProfileData(profileConfig),
ProfileConfig = NewQp.Processed(profileConfig),
UpdateReason = QualityProfileUpdateReason.New
};
@ -84,7 +84,7 @@ public class UpdatedQualityProfileValidatorTest
var updatedProfile = new UpdatedQualityProfile
{
ProfileDto = new QualityProfileDto(),
ProfileConfig = new ProcessedQualityProfileData(profileConfig),
ProfileConfig = NewQp.Processed(profileConfig),
UpdateReason = QualityProfileUpdateReason.New
};
@ -112,7 +112,7 @@ public class UpdatedQualityProfileValidatorTest
NewQp.QualityDto(1, "disabled_quality", false)
}
},
ProfileConfig = new ProcessedQualityProfileData(profileConfig),
ProfileConfig = NewQp.Processed(profileConfig),
UpdateReason = QualityProfileUpdateReason.New
};

Loading…
Cancel
Save