blob: 7c353a755cce91259cdec6341309cf62133c772c (
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 InitViewAction
( initViewAction
) where
import Task exposing (..)
import Http
import Json.Decode as Json exposing ((:=))
import Update exposing (Action(GoLoggedInView, GoSignInView))
import Model.Payment exposing (Payments, paymentsDecoder, perPage)
import Model.Payer exposing (Payers, payersDecoder)
import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder)
initViewAction : Task Http.Error Action
initViewAction = Task.onError loggedInView (always <| Task.succeed GoSignInView)
loggedInView : Task Http.Error Action
loggedInView =
Task.map GoLoggedInView (Http.get usersDecoder "/users")
`Task.andMap` (Http.get ("id" := userIdDecoder) "/whoAmI")
`Task.andMap` (Http.get paymentsDecoder "/monthlyPayments")
`Task.andMap` (Http.get paymentsDecoder ("/payments?page=1&perPage=" ++ toString perPage))
`Task.andMap` (Http.get ("number" := Json.int) "/payments/count")
`Task.andMap` (Http.get payersDecoder "/payers")
|