Skip to content

Commit

Permalink
feat: sort listed scenarios by difficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
Ric Featherstone authored and 06kellyjac committed Dec 21, 2023
1 parent a7d9399 commit db6da9c
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions scenarios/scenarios.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import (
"embed"
"errors"
"log/slog"
"sort"

"gopkg.in/yaml.v2"
)

//go:embed scenarios.yaml
var config embed.FS

type Scenario struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Description string `yaml:"description"`
Category string `yaml:"category"`
Difficulty string `yaml:"difficulty"`
}

func List() ([]Scenario, error) {
var scenarios []Scenario

Expand All @@ -26,6 +35,20 @@ func List() ([]Scenario, error) {
return nil, errors.Join(errors.New("failed to list scenarios"), err)
}

sort.Slice(scenarios, func(i, j int) bool {
iDifficulty := scenarios[i].Difficulty
jDifficulty := scenarios[j].Difficulty

switch iDifficulty {
case "Complex":
return jDifficulty != "Complex"
case "Medium":
return jDifficulty == "Easy"
default:
return false
}
})

return scenarios, nil
}

Expand All @@ -45,11 +68,3 @@ func Find(scenarioID string) (Scenario, error) {

return scenario, errors.New("unable to find scenario")
}

type Scenario struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Description string `yaml:"description"`
Category string `yaml:"category"`
Difficulty string `yaml:"difficulty"`
}

0 comments on commit db6da9c

Please sign in to comment.