summaryrefslogtreecommitdiffstats
path: root/src/Config.elm
blob: 95a15ddb7fb233938ed9f6cb43609fa012b3f67d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Config exposing (ApiResource(..), makeApiUrl)

import Types exposing (Model)
import Utils exposing (templ)


type ApiResource
    = ApiPosts
    | ApiLikePost String
    | ApiCompose


makeApiUrl : Model -> ApiResource -> String
makeApiUrl model res =
    String.replace "{baseUrl}" model.apiURL <|
        case res of
            ApiPosts ->
                "{baseUrl}/posts?_sort=createdAt&_order=desc"

            ApiLikePost postId ->
                "{baseUrl}/posts/{0}"
                    |> templ [ postId ]

            ApiCompose ->
                "{baseUrl}/posts"