Skip to content

Commit

Permalink
feat: add quality profile min_upgrade_format_score field
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuochi committed Sep 22, 2024
1 parent 4142167 commit b8ce1e7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/quality_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data "radarr_quality_profile" "example" {
- `id` (Number) Quality Profile ID.
- `language` (Attributes) Language. (see [below for nested schema](#nestedatt--language))
- `min_format_score` (Number) Min format score.
- `min_upgrade_format_score` (Number) Min upgrade format score.
- `quality_groups` (Attributes List) Quality groups. (see [below for nested schema](#nestedatt--quality_groups))
- `upgrade_allowed` (Boolean) Upgrade allowed flag.

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/quality_profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Read-Only:
- `id` (Number) Quality Profile ID.
- `language` (Attributes) Language. (see [below for nested schema](#nestedatt--quality_profiles--language))
- `min_format_score` (Number) Min format score.
- `min_upgrade_format_score` (Number) Min upgrade format score.
- `name` (String) Quality Profile Name.
- `quality_groups` (Attributes List) Quality groups. (see [below for nested schema](#nestedatt--quality_profiles--quality_groups))
- `upgrade_allowed` (Boolean) Upgrade allowed flag.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/quality_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ resource "radarr_quality_profile" "example" {
- `cutoff_format_score` (Number) Cutoff format score.
- `format_items` (Attributes Set) Format items. Only the ones with score > 0 are needed. (see [below for nested schema](#nestedatt--format_items))
- `min_format_score` (Number) Min format score.
- `min_upgrade_format_score` (Number) Min upgrade format score.
- `upgrade_allowed` (Boolean) Upgrade allowed flag.

### Read-Only
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/quality_profile_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (d *QualityProfileDataSource) Schema(_ context.Context, _ datasource.Schema
MarkdownDescription: "Min format score.",
Computed: true,
},
"min_upgrade_format_score": schema.Int64Attribute{
MarkdownDescription: "Min upgrade format score.",
Computed: true,
},
"language": schema.SingleNestedAttribute{
MarkdownDescription: "Language.",
Computed: true,
Expand Down
47 changes: 29 additions & 18 deletions internal/provider/quality_profile_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
Expand Down Expand Up @@ -40,29 +41,31 @@ type QualityProfileResource struct {

// QualityProfile describes the quality profile data model.
type QualityProfile struct {
FormatItems types.Set `tfsdk:"format_items"`
QualityGroups types.List `tfsdk:"quality_groups"`
Name types.String `tfsdk:"name"`
Language types.Object `tfsdk:"language"`
ID types.Int64 `tfsdk:"id"`
Cutoff types.Int64 `tfsdk:"cutoff"`
MinFormatScore types.Int64 `tfsdk:"min_format_score"`
CutoffFormatScore types.Int64 `tfsdk:"cutoff_format_score"`
UpgradeAllowed types.Bool `tfsdk:"upgrade_allowed"`
FormatItems types.Set `tfsdk:"format_items"`
QualityGroups types.List `tfsdk:"quality_groups"`
Name types.String `tfsdk:"name"`
Language types.Object `tfsdk:"language"`
ID types.Int64 `tfsdk:"id"`
Cutoff types.Int64 `tfsdk:"cutoff"`
MinFormatScore types.Int64 `tfsdk:"min_format_score"`
CutoffFormatScore types.Int64 `tfsdk:"cutoff_format_score"`
MinUpgradeFormatScore types.Int64 `tfsdk:"min_upgrade_format_score"`
UpgradeAllowed types.Bool `tfsdk:"upgrade_allowed"`
}

func (p QualityProfile) getType() attr.Type {
return types.ObjectType{}.WithAttributeTypes(
map[string]attr.Type{
"quality_groups": types.ListType{}.WithElementType(QualityGroup{}.getType()),
"format_items": types.SetType{}.WithElementType(FormatItem{}.getType()),
"language": QualityLanguage{}.getType(),
"name": types.StringType,
"id": types.Int64Type,
"cutoff": types.Int64Type,
"min_format_score": types.Int64Type,
"cutoff_format_score": types.Int64Type,
"upgrade_allowed": types.BoolType,
"quality_groups": types.ListType{}.WithElementType(QualityGroup{}.getType()),
"format_items": types.SetType{}.WithElementType(FormatItem{}.getType()),
"language": QualityLanguage{}.getType(),
"name": types.StringType,
"id": types.Int64Type,
"cutoff": types.Int64Type,
"min_format_score": types.Int64Type,
"cutoff_format_score": types.Int64Type,
"min_upgrade_format_score": types.Int64Type,
"upgrade_allowed": types.BoolType,
})
}

Expand Down Expand Up @@ -151,6 +154,12 @@ func (r *QualityProfileResource) Schema(_ context.Context, _ resource.SchemaRequ
Optional: true,
Computed: true,
},
"min_upgrade_format_score": schema.Int64Attribute{
MarkdownDescription: "Min upgrade format score.",
Optional: true,
Computed: true,
Default: int64default.StaticInt64(1),
},
"language": schema.SingleNestedAttribute{
MarkdownDescription: "Language.",
Required: true,
Expand Down Expand Up @@ -397,6 +406,7 @@ func (p *QualityProfile) write(ctx context.Context, profile *radarr.QualityProfi
p.Cutoff = types.Int64Value(int64(profile.GetCutoff()))
p.CutoffFormatScore = types.Int64Value(int64(profile.GetCutoffFormatScore()))
p.MinFormatScore = types.Int64Value(int64(profile.GetMinFormatScore()))
p.MinUpgradeFormatScore = types.Int64Value(int64(profile.GetMinUpgradeFormatScore()))

qualityGroups := make([]QualityGroup, 0, len(profile.GetItems()))

Expand Down Expand Up @@ -535,6 +545,7 @@ func (p *QualityProfile) read(ctx context.Context, qualitiesIDs []int32, formatI
profile.SetId(int32(p.ID.ValueInt64()))
profile.SetCutoff(int32(p.Cutoff.ValueInt64()))
profile.SetMinFormatScore(int32(p.MinFormatScore.ValueInt64()))
profile.SetMinUpgradeFormatScore(int32(p.MinUpgradeFormatScore.ValueInt64()))
profile.SetCutoffFormatScore(int32(p.CutoffFormatScore.ValueInt64()))
profile.SetName(p.Name.ValueString())
profile.SetLanguage(*language.read())
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/quality_profiles_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (d *QualityProfilesDataSource) Schema(_ context.Context, _ datasource.Schem
MarkdownDescription: "Min format score.",
Computed: true,
},
"min_upgrade_format_score": schema.Int64Attribute{
MarkdownDescription: "Min upgrade format score.",
Computed: true,
},
"language": schema.SingleNestedAttribute{
MarkdownDescription: "Language.",
Computed: true,
Expand Down

0 comments on commit b8ce1e7

Please sign in to comment.