Skip to content

Commit 252553d

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

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
field(:game_id, :integer)
16+
17+
belongs_to(:user, User)
18+
belongs_to(:currency, Currency)
19+
20+
timestamps(type: :utc_datetime)
21+
end
22+
23+
def changeset(transaction, attrs) do
24+
transaction
25+
|> cast(attrs, [
26+
:type,
27+
:amount,
28+
:description,
29+
:user_id,
30+
:currency_id,
31+
])
32+
|> validate_required([:type, :amount, :description, :user_id, :currency_id])
33+
end
34+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
add(:game_id, :integer, null: false)
12+
13+
timestamps(type: :utc_datetime)
14+
end
15+
end
16+
end

0 commit comments

Comments
 (0)