List of routes, not single route, for Api routes.

This commit is contained in:
Dillon Kearns 2021-04-30 17:02:15 -07:00
parent 6e6f09cabc
commit 429a8ae4c1
2 changed files with 9 additions and 12 deletions

View File

@ -3,9 +3,10 @@ module ApiHandler exposing (..)
import Regex
withRoutes : (constructor -> List String) -> Handler a constructor -> String
withRoutes : (constructor -> List (List String)) -> Handler a constructor -> List String
withRoutes buildUrls (Handler pattern handler toString constructor) =
toString (buildUrls (constructor []))
buildUrls (constructor [])
|> List.map toString
tryMatch : String -> Handler Response constructor -> Maybe Response

View File

@ -50,17 +50,15 @@ all =
|> literalSegment ".json"
|> withRoutes
(\constructor ->
constructor "100"
[ constructor "100" ]
-- [
--, constructor "101"
--]
)
|> Expect.equal
"users/100.json"
[ "users/100.json" ]
-- [
--, "users/101.json"
--]
, describe "multi-part"
[ test "multi-level routes" <|
\() ->
@ -69,25 +67,23 @@ all =
(\a ->
--constructor "dillonkearns" "elm-pages"
--, constructor "101"
a "dillonkearns" "elm-pages"
[ a "dillonkearns" "elm-pages" ]
--, constructor "elm-pages"
--]
)
|> Expect.equal
--[
"repos/dillonkearns/elm-pages.json"
[ "repos/dillonkearns/elm-pages.json" ]
--, "users/101.json"
--]
, test "3-level route" <|
\() ->
threeParts
|> withRoutes
(\constructor ->
constructor "dillonkearns" "elm-pages" "static-files"
[ constructor "dillonkearns" "elm-pages" "static-files" ]
)
|> Expect.equal
"repos/dillonkearns/elm-pages/static-files"
[ "repos/dillonkearns/elm-pages/static-files" ]
--, "users/101.json"
]