-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from tapglue/console-user
Add user search and update to Console
- Loading branch information
Showing
14 changed files
with
645 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Error exposing (decodeList) | ||
|
||
import Json.Decode as Decode | ||
|
||
|
||
type alias Error = | ||
{ code : Int | ||
, message : String | ||
} | ||
|
||
|
||
decode : Decode.Decoder Error | ||
decode = | ||
Decode.map2 Error | ||
(Decode.field "code" Decode.int) | ||
(Decode.field "message" Decode.string) | ||
|
||
|
||
decodeList : Decode.Decoder (List Error) | ||
decodeList = | ||
Decode.at [ "errors" ] (Decode.list decode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module User.Api exposing (getUser, searchUser, updateUser) | ||
|
||
import Http | ||
import RemoteData exposing (WebData, sendRequest) | ||
import User.Model exposing (User, decode, decodeList, encode) | ||
|
||
|
||
getUser : String -> String -> Cmd (WebData User) | ||
getUser appId userId = | ||
Http.get ("/api/apps/" ++ appId ++ "/users/" ++ userId) decode | ||
|> sendRequest | ||
|
||
|
||
searchUser : String -> String -> Cmd (WebData (List User)) | ||
searchUser appId query = | ||
Http.get ("/api/apps/" ++ appId ++ "/users/search?q=" ++ query) decodeList | ||
|> sendRequest | ||
|
||
|
||
updateUser : String -> String -> String -> Cmd (WebData User) | ||
updateUser appId userId username = | ||
Http.request | ||
{ body = (encode username |> Http.jsonBody) | ||
, expect = Http.expectJson decode | ||
, headers = [] | ||
, method = "PUT" | ||
, timeout = Nothing | ||
, url = (userUrl appId userId) | ||
, withCredentials = False | ||
} | ||
|> sendRequest | ||
|
||
|
||
userUrl : String -> String -> String | ||
userUrl appId userId = | ||
"/api/apps/" ++ appId ++ "/users/" ++ userId |
Oops, something went wrong.