-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41eea20
commit 0509fe9
Showing
2 changed files
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule Servy.PledgeController do | ||
alias Servy.Conv | ||
alias Servy.PledgeServer | ||
|
||
def create(conv, %{"name" => name, "amount" => amount}) do | ||
# sends pledge to the external service and caches it | ||
PledgeServer.create_pledge(name, String.to_integer(amount)) | ||
|
||
%{conv | status: 201, resp_body: "#{name} pledged #{amount}!"} | ||
end | ||
|
||
def index(conv) do | ||
# get recent pledges from cache | ||
pledges = PledgeServer.recent_pledges() | ||
|
||
%{Conv | status: 200, resp_body: inspect(pledges)} | ||
end | ||
end |
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,10 @@ | ||
defmodule Servy.PledgeServer do | ||
def create_pledge(name, amount) do | ||
{:ok, id} = send_pledge_to_service(name, amount) | ||
end | ||
|
||
defp send_pledge_to_service(_name, _amount) do | ||
# CODE GOES HERE TO SEND PLEDGE TO EXTERNAL SERVICE | ||
{:ok, "pledge-#{:rand.uniform(1000)}"} | ||
end | ||
end |