Skip to content

Commit 0419bb9

Browse files
committed
feat: add Ledger module and Ledger Transaction schema
1 parent 3a354b6 commit 0419bb9

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Configurator.Repo.Migrations.AddLedgerTransaction do
2+
use Ecto.Migration
3+
4+
def change do
5+
6+
end
7+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
defmodule GameBackend.Ledger do
2+
@moduledoc """
3+
"""
4+
5+
alias GameBackend.Ledger.Transaction
6+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
defmodule GameBackend.Ledger.Transaction do
2+
@moduledoc """
3+
The ledger will be used to keep track of a transaction log of each game
4+
"""
5+
use GameBackend.Schema
6+
import Ecto.Changeset
7+
8+
alias GameBackend.Users.User
9+
alias GameBackend.Users.Currencies.Currency
10+
11+
schema "ledger_transactions" do
12+
field(:type, Ecto.Enum, values: [:credit, :debit])
13+
field(:amount, :integer)
14+
field(:description, :string)
15+
16+
belongs_to(:user, User)
17+
belongs_to(:currency, Currency)
18+
19+
timestamps(type: :utc_datetime)
20+
end
21+
22+
def changeset(transaction, attrs) do
23+
transaction
24+
|> cast(attrs, [
25+
:type,
26+
:amount,
27+
:description,
28+
:user_id,
29+
:currency_id,
30+
])
31+
|> validate_required([:type, :amount, :description, :user_id, :currency_id])
32+
end
33+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule GameBackend.Repo.Migrations.AddLedgerTransaction do
2+
use Ecto.Migration
3+
4+
def change do
5+
create table(:ledger_transactions) do
6+
add(:type, :string)
7+
add(:amount, :integer)
8+
add(:description, :string)
9+
add(:user_id, references(:users))
10+
add(:currency_id, references(:currencies))
11+
12+
timestamps(type: :utc_datetime)
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)