|
@@ -1,4 +1,4 @@
|
|
|
-module API exposing (getDraft, getDrafts, getSetData, getSets)
|
|
|
|
|
|
|
+module API exposing (getDraft, getSetData, getSets)
|
|
|
|
|
|
|
|
import Database exposing (Database)
|
|
import Database exposing (Database)
|
|
|
import DraftMeta exposing (DraftMeta)
|
|
import DraftMeta exposing (DraftMeta)
|
|
@@ -7,20 +7,10 @@ import Json.Decode as Decode
|
|
|
import Url.Builder as UrlB
|
|
import Url.Builder as UrlB
|
|
|
|
|
|
|
|
|
|
|
|
|
-apiUrl : String
|
|
|
|
|
-apiUrl =
|
|
|
|
|
- "http://localhost:8000"
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-makeApiUrl : List String -> String
|
|
|
|
|
-makeApiUrl paths =
|
|
|
|
|
- apiUrl ++ "/" ++ String.join "/" paths
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
getSets : (Result String (List String) -> msg) -> Cmd msg
|
|
getSets : (Result String (List String) -> msg) -> Cmd msg
|
|
|
getSets onSuccess =
|
|
getSets onSuccess =
|
|
|
Http.get
|
|
Http.get
|
|
|
- { url = makeApiUrl [ "sets" ]
|
|
|
|
|
|
|
+ { url = UrlB.absolute [ "api", "sets" ] []
|
|
|
, expect =
|
|
, expect =
|
|
|
Http.expectJson (Result.mapError httpErrorToString >> onSuccess)
|
|
Http.expectJson (Result.mapError httpErrorToString >> onSuccess)
|
|
|
(Decode.field "sets"
|
|
(Decode.field "sets"
|
|
@@ -34,7 +24,7 @@ getSetData setCode onSuccess =
|
|
|
Http.request
|
|
Http.request
|
|
|
{ method = "GET"
|
|
{ method = "GET"
|
|
|
, headers = []
|
|
, headers = []
|
|
|
- , url = makeApiUrl [ "sets", setCode ]
|
|
|
|
|
|
|
+ , url = UrlB.absolute [ "api", "sets", setCode ] []
|
|
|
, body = Http.emptyBody
|
|
, body = Http.emptyBody
|
|
|
, expect = Http.expectJson (Result.mapError httpErrorToString >> onSuccess) Database.decoder
|
|
, expect = Http.expectJson (Result.mapError httpErrorToString >> onSuccess) Database.decoder
|
|
|
, timeout = Nothing
|
|
, timeout = Nothing
|
|
@@ -42,18 +32,6 @@ getSetData setCode onSuccess =
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-getDrafts : String -> (Result String (List DraftMeta) -> msg) -> Cmd msg
|
|
|
|
|
-getDrafts historyUrl onSuccess =
|
|
|
|
|
- Http.get
|
|
|
|
|
- { url = apiUrl ++ UrlB.absolute [ "drafts" ] [ UrlB.string "history" historyUrl ]
|
|
|
|
|
- , expect =
|
|
|
|
|
- Http.expectJson (Result.mapError httpErrorToString >> onSuccess)
|
|
|
|
|
- (Decode.field "drafts"
|
|
|
|
|
- (Decode.list DraftMeta.decoder)
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
getDraft : String -> (Result String DraftMeta -> msg) -> Cmd msg
|
|
getDraft : String -> (Result String DraftMeta -> msg) -> Cmd msg
|
|
|
getDraft draftID onSuccess =
|
|
getDraft draftID onSuccess =
|
|
|
Http.get
|
|
Http.get
|