Skip to content

Commit

Permalink
- Added money dependency (#23)
Browse files Browse the repository at this point in the history
* - Added money dependency

* - Fixed failing car test
  • Loading branch information
rushikeshpandit authored Jan 10, 2024
1 parent 338b61c commit 78425c1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ config :rent_cars, RentCarsWeb.Endpoint,
# at the `config/runtime.exs`.
config :rent_cars, RentCars.Mailer, adapter: Swoosh.Adapters.Local

config :money,
default_currency: :USD

# Configure esbuild (the version is required)
config :esbuild,
version: "0.17.11",
Expand Down
2 changes: 1 addition & 1 deletion lib/rent_cars/cars/car.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule RentCars.Cars.Car do
field :brand, :string
field :daily_rate, :integer
field :description, :string
field :fine_amount, :integer
field :fine_amount, Money.Ecto.Amount.Type
field :license_plate, :string
field :name, :string
belongs_to :category, Category
Expand Down
2 changes: 1 addition & 1 deletion lib/rent_cars_web/controllers/api/admin/car_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule RentCarsWeb.Api.Admin.CarJSON do
brand: car.brand,
daily_rate: car.daily_rate,
license_plate: car.license_plate,
fine_amount: car.fine_amount,
fine_amount: Money.to_string(car.fine_amount),
category_id: car.category_id,
specifications: load_specifications(car.specifications),
name: car.name
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule RentCars.MixProject do
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
{:mix_test_watch, "~> 1.0", only: [:dev, :test], runtime: false},
{:argon2_elixir, "~> 4.0"},
{:phoenix_swoosh, "~> 1.0"}
{:phoenix_swoosh, "~> 1.0"},
{:money, "~> 1.12"}
]
end

Expand Down
3 changes: 1 addition & 2 deletions test/rent_cars/cars_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ defmodule RentCars.CarsTest do
assert car.brand == payload.brand
assert car.daily_rate == payload.daily_rate
assert car.license_plate == String.upcase(payload.license_plate)
assert car.fine_amount == payload.fine_amount
assert car.fine_amount == payload.fine_amount
assert car.fine_amount == Money.new(payload.fine_amount)

Enum.each(
car.specifications,
Expand Down

0 comments on commit 78425c1

Please sign in to comment.