Rocktpay

To start your Phoenix server:

  • Install dependencies with mix deps.get
  • Create and migrate your database with mix ecto.setup
  • Start Phoenix endpoint with mix phx.server

Now you can visit localhost:4000 from your browser.

Ready to run in production? Please check our deployment guides.

Learn more

This a Elixir Project for study new knowloge and get a notion about that technology

To create a new project we gonna write:

mix phx.new rocktpay --no-webpack --no-html
# No use front-end tech's

To check if the database is configured success

mix ecto.setup

The file mix.exs is the configuration of all project The extension Elixir Linter and other we need a lib Credo

# mix.exs
defp deps do
    [
      {:phoenix, "~> 1.5.7"},
      {:phoenix_ecto, "~> 4.1"},
      {:ecto_sql, "~> 3.4"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_live_dashboard, "~> 0.4"},
      {:telemetry_metrics, "~> 0.4"},
      {:telemetry_poller, "~> 0.4"},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:credo, "~> 1.5", only: [:dev, :test], runtime: false} # Include this row
    ]
  end

To download all libs configured

mix deps.get 

To compile and set config credo

mix credo gen.config

As we dont worry with documentation, we need disable a config .credo.exs

{Credo.Check.Readability.ModuleDoc, false}, # Update this row

To up the server phoenix:

mix phx.server

Folder lib

There are 2 folder inside lib

  • rocketpay -> logical and rules system
  • rocketpay_web -> all we need to build a web system

Create a new route

In file router.ex

get "/", WelcomeController, :index

We created a route '/', that call the WelcomeController that its function is index Now we gonna create the controller welocome_controller.ex

1º way that create controller

We need define the module defmodule RocktpayWeb.WelcomeController do

2º way that create controller

it's necessary considerer special file, 'cause is a controller

use RocktpayWeb, :controller

3º way that create controller

Create de action index

def index(conn, _params)

Create Logical

To read a file

File.read("#{filename}.csv")

To open console/console with project

iex
iex -S mix

1 row function

defp handle_file({:ok, file}), do file

if the params is :ok, this return the file


To check if the database was created

mix exto.create

To create any migration

mix ecto.gen.migration create_user_table

To run the migration

mix ecto.migrate

To drop the database

mix ecto.drop

Config to use binary id for pk and fk

config :rocktpay, Rocktpay.Repo,
  migration_primary_key: [type: :binary_id],
  migration_foreing_key: [type: :binary_id]

mix ecto.gen.migration create_accounts_table

At iex if use Rocktpay.Repo.all(Rocktpay.User) -> get all User database test to account

params = %{user_id: "be7a4e5b-8a9d-4acf-8557-2cdf2c6a0c25", balance: "0.00"}
params |> Rocktpay.Account.changeset() |> Rocktpay.Repo.insert()
Rocktpay.Repo.all(Rocktpay.User) |> Rocktpay.Repo.preload(:account) # load with account

Ecto.Multi

give multi transactions


Auth Insomnia/Postman

if insomnia

In basic, set Basic Auth and insert the username and password

if postman

In Header:

  • Content Type: Authorization
  • application/json: Basic username:password remembet that the username:password should be base64 In iex we can convert to this type: Base.encode64("banana:nanica123") "YmFuYW5hOm5hbmljYTEyMw==" Basic YmFuYW5hOm5hbmljYTEyMw==

To se the covert test of project

mix test --cover mix coveralls.html -> Create report html