aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model/Payment.elm
blob: 31aba1dd5c50b507c8988e351373d70f2d5eccd2 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Model.Payment
  ( perPage
  , Payments
  , Payment
  , PaymentId
  , paymentsDecoder
  , paymentIdDecoder
  , deletePayment
  , PaymentFrequency(..)
  ) where

import Date exposing (..)
import Json.Decode as Json exposing ((:=))

import Model.User exposing (UserId, userIdDecoder)
import Model.Date exposing (dateDecoder)

perPage : Int
perPage = 8

type alias Payments = List Payment

type alias Payment =
  { id : PaymentId
  , creation : Date
  , name : String
  , cost : Int
  , userId : UserId
  }

type alias PaymentId = Int

type PaymentFrequency = Punctual | Monthly

paymentsDecoder : Json.Decoder Payments
paymentsDecoder = Json.list paymentDecoder

paymentDecoder : Json.Decoder Payment
paymentDecoder =
  Json.object5 Payment
    ("id" := paymentIdDecoder)
    ("creation" := dateDecoder)
    ("name" := Json.string)
    ("cost" := Json.int)
    ("userId" := userIdDecoder)

paymentIdDecoder : Json.Decoder PaymentId
paymentIdDecoder = Json.int

deletePayment : PaymentId -> Payments -> Payments
deletePayment paymentId = List.filter (((/=) paymentId) << .id)