luckyframework / luckyframework/lucky

Add optional_param with enums

Open
#105 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Crystal
Stars
2.7k
Forks
172
PR merge metrics
No merged PRs in 30d

Description

This sets up some enums so you can have type safe params

```crystal
class Tasks::Index
# `allow` will create an enum
param filter, default: All, allow: [All, Completed, Incomplete]

action do
# This will be extra cool/if when they have exhaustiveness checks on enums!
case Filter
when All
tasks = TaskQuery.all
when Completed
tasks = TaskQuery.new.completed
when Incomplete
tasks = TaskQuery.new.incomplete
end

render tasks: tasks
end
end

# You can only use things in the enum when using a route
link "complete", to: Tasks::Index.route(filter: Tasks::Index::Filter::Completed)
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's Crystal examples for `optional_param`, the `allow` enum declaration, and route generation. Determine how enum values should be represented in params and routes, then define completion around type-safe filtering and restricting route links to the declared enum values.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.