I want to receive a json like this.
[
{
“department”: “Ventas”,
“applicant”: [
{
“id”: “NlmiwKPdlfslT5HDs1I7”,
“name”: “Emanuel Osorio”,
“email”: “emanuel@hotmial.com”,
“department”: “Ventas”,
“place”: “Vendedor”,
“phone”: “7152345654”
}
]
},
{
“department”: “Info”,
“applicant”: [
{
“id”: “TF9hEln12wGjl5ykqG8Q”,
“name”: “Rodolfo”,
“email”: “rodolfo@gmail.com”,
“department”: “Info”,
“place”: “Desarrollador”,
“phone”: “5676542345”
},
{
“id”: “iO2MZD0jRvfR6QAWxfhv”,
“name”: “Ulises”,
“email”: “uli_vra@hotmail.com”,
“department”: “Info”,
“place”: “Tec”,
“phone”: “7152435643”
}
]
}
]
so I make this model
applicantDecoder : Decoder Applicant
applicantDecoder =
Decode.succeed Applicant
|> optional “id” string “”
|> required “uid” string
|> required “name” string
|> required “email” string
|> required “department” string
|> required “place” string
|> required “phone” string
applicantByDepartmentDecoder : Decoder ApplicantByDepartment
applicantByDepartmentDecoder =
Decode.succeed ApplicantByDepartment
|> required “name” string
|> required “applicants” (list applicantDecoder)
and here is my decoder
applicantsByDepartmentDecoder : Decoder (List ApplicantByDepartment)
applicantsByDepartmentDecoder =
list applicantByDepartmentDecoder
applicantByDepartmentDecoder : Decoder ApplicantByDepartment
applicantByDepartmentDecoder =
Decode.succeed ApplicantByDepartment
|> required “name” string
|> required “applicants” (list applicantDecoder)
here is the way that I’m trying to make the get request
import Models.Applicant exposing (ApplicantByDepartment
, applicantByDepartmentDecoder)
import RemoteData exposing (WebData)
type alias Model =
{ applicantsByDepartment : WebData (List ApplicantByDepartment)
}
initialModel : Model
initialModel =
{ applicantsByDepartment = RemoteData.Loading
}
type Msg
= FetchApplicantsByDepartment
| ApplicantsReceived (WebData (List ApplicantByDepartment))
fetchApplicantsByDepartment : Cmd Msg
fetchApplicantsByDepartment =
Http.get
{ url = “https://myapi”
, expect =
applicantByDepartmentDecoder
|> Http.expectJson (RemoteData.fromResult >> ApplicantsReceived)
}
in this part show me the next error message
The argument is:
Json.Decode.Decoder ApplicantByDepartment
But (|>) is piping it to a function that expects:
Json.Decode.Decoder (#List# ApplicantByDepartment)
someone have any advice