Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-yechenwei committed Jan 12, 2023
1 parent 5a1c0b9 commit 3acfc6e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
38 changes: 30 additions & 8 deletions internal/services/labservice/lab_service_schedule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type RecurrencePattern struct {
ExpirationDate string `tfschema:"expiration_date"`
Frequency schedule.RecurrenceFrequency `tfschema:"frequency"`
Interval int64 `tfschema:"interval"`
WeekDays []schedule.WeekDay `tfschema:"week_days"`
WeekDays []string `tfschema:"week_days"`
}

type LabServiceScheduleResource struct{}
Expand Down Expand Up @@ -334,16 +334,13 @@ func expandRecurrencePattern(input []RecurrencePattern) *schedule.RecurrencePatt
result := schedule.RecurrencePattern{
ExpirationDate: recurrencePattern.ExpirationDate,
Frequency: recurrencePattern.Frequency,
WeekDays: expandWeekDays(recurrencePattern.WeekDays),
}

if recurrencePattern.Interval != 0 {
result.Interval = utils.Int64(recurrencePattern.Interval)
}

if recurrencePattern.WeekDays != nil {
result.WeekDays = &recurrencePattern.WeekDays
}

return &result
}

Expand All @@ -356,15 +353,40 @@ func flattenRecurrencePattern(input *schedule.RecurrencePattern) []RecurrencePat
recurrencePattern := RecurrencePattern{
ExpirationDate: input.ExpirationDate,
Frequency: input.Frequency,
WeekDays: flattenWeekDays(input.WeekDays),
}

if input.Interval != nil {
recurrencePattern.Interval = *input.Interval
}

if input.WeekDays != nil {
recurrencePattern.WeekDays = *input.WeekDays
return append(recurrencePatterns, recurrencePattern)
}

func expandWeekDays(input []string) *[]schedule.WeekDay {
if len(input) == 0 {
return nil
}

return append(recurrencePatterns, recurrencePattern)
result := make([]schedule.WeekDay, 0)

for _, item := range input {
result = append(result, schedule.WeekDay(item))
}

return &result
}

func flattenWeekDays(input *[]schedule.WeekDay) []string {
if input == nil {
return nil
}

result := make([]string, 0)

for _, item := range *input {
result = append(result, string(item))
}

return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func TestValidateLabPlanName(t *testing.T) {
func TestValidateScheduleNotes(t *testing.T) {
cases := []struct {
Input string
ExpectError bool
Expand Down

0 comments on commit 3acfc6e

Please sign in to comment.