-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Creating generic UserTable module with ETS. #1
- Loading branch information
1 parent
5cc8933
commit 6f20305
Showing
3 changed files
with
100 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
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,29 @@ | ||
defmodule UsersTable do | ||
|
||
alias ETS.Set | ||
|
||
@table :users_table | ||
|
||
def init do | ||
Set.new(name: @table) | ||
end | ||
|
||
def list_users do | ||
@table | ||
|> Set.wrap_existing!() | ||
|> Set.to_list() | ||
end | ||
|
||
def create_user(stripe_id) do | ||
@table | ||
|> Set.wrap_existing!() | ||
|> Set.put_new( {stripe_id, false}) | ||
end | ||
|
||
def update_payment_status(%{:stripe_id => stripe_id, :status => status}) do | ||
@table | ||
|> Set.wrap_existing!() | ||
|> Set.put({stripe_id, status}) | ||
end | ||
|
||
end |