Skip to content

Commit db20ed6

Browse files
committed
Merge branch 'master' into features/basic-readme
2 parents a5a6b3c + 1bd742b commit db20ed6

File tree

98 files changed

+1969
-729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1969
-729
lines changed

.dockerignore

Whitespace-only changes.

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ sudo: required
1515
notifications:
1616
recipients:
1717
18+
before_script:
19+
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('1234') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root

Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM elixir:1.4
2+
3+
RUN apt-get update
4+
RUN apt-get -y -q install mysql-client libmysqlclient-dev
5+
6+
COPY . /app
7+
WORKDIR /app
8+
RUN mix local.hex --force
9+
RUN mix local.rebar --force
10+
RUN mix deps.get
11+
RUN mix compile

README.md

+37-22
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,41 @@
1919

2020
## Beginning
2121

22-
**Step 1:** Download project.
23-
```bash
24-
git clone https://github.com/adrianmarino/points.git; cd points
25-
```
26-
**Step 2:** Install dependencies.
27-
```bash
28-
mix deps.get
29-
```
30-
**Step 3:** Create your dev database.
31-
```bash
32-
mix ecto.create
33-
mix ecto.migrate
34-
MIX_ENV=dev mix ecto.reset
35-
```
36-
**Step 4:** Start server.
37-
```bash
38-
mix phoenix.server
39-
```
22+
**Step 1:** Download project.
23+
```bash
24+
git clone https://github.com/adrianmarino/points.git; cd points
25+
```
26+
27+
**Step 1**: Install dependencies.
28+
```bash
29+
$ mix deps.get
30+
```
31+
32+
**Step 2**: Create and populate points database.
33+
```bash
34+
$ MIX_ENV=dev mix ecto.reset
35+
```
36+
37+
**Step 3**: Start server.
38+
```bash
39+
$ mix phoenix.server
40+
```
41+
42+
## Beginning with docker
43+
44+
```bash
45+
$ ./docker-server-init
46+
```
4047

4148
## Guide
4249

4350
This guide introduces you how can interact with points platform through easy examples. Adicionally, I'll show you how to configure the server.
4451

4552
### Client Tasks
4653

47-
You can interact with the rest api through mix tasks without need to use curl or any rest client. This tasks actually use a rest client as we'll see later.
54+
You can interact with the rest api through mix tasks without need to use curl or any rest client. This tasks actually use a rest client as we'll see later.
4855

49-
What can you do with points api?
56+
What can you do with points api?
5057
Run next on points directory:
5158
```bash
5259
$ mix help | grep cli
@@ -63,7 +70,7 @@ mix cli.entities # Show entities. Params: token
6370
mix cli.entities.create # Create an entity. Params: token code name
6471
mix cli.entities.delete # Delete an entity. Params: token code
6572
mix cli.entities.partners # Show entity partners. Params: token entity_code
66-
mix cli.entities.partners.create # Create an entity partner. Params: token partner_code entity_code
73+
mix cli.entities.partners.create # Create an entity partner. Params: token partner_code entity_code
6774
mix cli.entities.partners.delete # Delete an entity partner. Params: token partner_code entity_code
6875
mix cli.entities.show # Show an entity. Params: token code
6976
mix cli.entities.update # Update entity name. Params: token code name
@@ -125,7 +132,7 @@ $ mix cli.currencies.show OHpIUENHak9FTTAzUCtwaHB1dnk3dz09 XPT
125132
```bash
126133
$ mix help | grep cli.users.create
127134
mix cli.users.create # Create a user. Params: session_token email password first_name last_name
128-
$ mix cli.users.create OHpIUENHak9FTTAzUCtwaHB1dnk3dz09 [email protected] 1234567890 "Adrian Norberto" Marino
135+
$ mix cli.users.create OHpIUENHak9FTTAzUCtwaHB1dnk3dz09 [email protected] 1234567890 "Adrian Norberto" Marino
129136
22:20:53.900 [info] Response - Status: 201, Body: {
130137
"email": "[email protected]",
131138
"first_name": "Adrian Norberto",
@@ -252,3 +259,11 @@ To complete
252259

253260
### Custom Transactions
254261
To complete
262+
263+
## Docker
264+
265+
* docker-server-init: create/poulate database and run server in docker-compose env.
266+
* docker-server: Run server on docker-compose env.
267+
* docker-test: Run test on docker-compose env.
268+
* docker-reset: Reset(drop/create/migrate/populate) database in docker-compose env.
269+
* docker-clean: Clean(drop/create/migrate) database in docker-compose env.

config/dev.exs

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use Mix.Config
77
# watchers to your application. For example, we use it
88
# with brunch.io to recompile .js and .css sources.
99
config :point, Point.Endpoint,
10-
http: [port: 4000],
10+
http: [port: 3000],
11+
url: [host: "localhost", port: 3000],
1112
debug_errors: true,
1213
code_reloader: true,
1314
check_origin: false,
@@ -36,5 +37,6 @@ config :point, Point.Repo,
3637
username: "root",
3738
password: "1234",
3839
database: "point_dev",
39-
hostname: "localhost",
40-
pool_size: 10
40+
hostname: System.get_env("DB_HOST") || "localhost",
41+
pool_size: 10,
42+
ownership_timeout: 60_000

config/prod.exs

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use Mix.Config
1212
# manifest is generated by the mix phoenix.digest task
1313
# which you typically run after static files are built.
1414
config :point, Point.Endpoint,
15-
http: [port: {:system, "PORT"}],
16-
url: [host: "example.com", port: 80],
15+
http: [port: 3000],
16+
url: [host: "points", port: 3000],
1717
cache_static_manifest: "priv/static/manifest.json",
1818
session_ttl: 1_800,
1919
simultaneous_sessions_by_user_and_remote_ip: 3,
@@ -29,6 +29,16 @@ config :logger,
2929
format: "$time $metadata[$level] $levelpad$message",
3030
level: :info
3131

32+
# Configure your database
33+
config :point, Point.Repo,
34+
adapter: Ecto.Adapters.MySQL,
35+
username: "root",
36+
password: "1234",
37+
database: "point_prod",
38+
hostname: System.get_env("DB_HOST") || "localhost",
39+
pool_size: 100,
40+
ownership_timeout: 60_000
41+
3242
# ## SSL Support
3343
#
3444
# To get SSL working, you will need to add the `https` key

config/test.exs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ config :ecto_ttl,
2121
config :point, Point.Repo,
2222
adapter: Ecto.Adapters.MySQL,
2323
username: "root",
24-
password: "",
24+
password: "1234",
2525
database: "point_test",
26-
hostname: "localhost",
27-
pool: Ecto.Adapters.SQL.Sandbox
26+
hostname: System.get_env("DB_HOST") || "localhost",
27+
pool: Ecto.Adapters.SQL.Sandbox,
28+
ownership_timeout: 60_000
2829

2930
config :comeonin, :bcrypt_log_rounds, 4
3031
config :comeonin, :pbkdf2_rounds, 1

docker-clean

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix ecto.clean" $1 $2

docker-compose.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
database_storage:
2+
image: "busybox"
3+
volumes:
4+
- /var/lib/mysql
5+
6+
database:
7+
image: "mariadb:10"
8+
ports:
9+
- "3306:3306"
10+
environment:
11+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
12+
MYSQL_DATABASE: "point_${MIX_ENV}"
13+
volumes_from:
14+
- database_storage
15+
16+
points:
17+
build: "."
18+
environment:
19+
MIX_ENV: ${MIX_ENV}
20+
DB_HOST: database
21+
ports:
22+
- "3000:3000"
23+
links:
24+
- database

docker-reset

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix ecto.reset" $1 $2

docker-run

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
COMMAND=$1
3+
4+
export MIX_ENV=${2:-dev}
5+
export MYSQL_ROOT_PASSWORD=${3:-1234}
6+
7+
echo "=========================================================="
8+
echo "Environment: $MIX_ENV"
9+
echo "Password: $MYSQL_ROOT_PASSWORD"
10+
echo "Command: $COMMAND"
11+
echo "=========================================================="
12+
13+
docker-compose run -p3000:3000 --rm points sh -c "$COMMAND"

docker-server

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix phoenix.server" $1 $2

docker-server-init

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix ecto.reset; mix phoenix.server" $1 $2

docker-test

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix espec --format=doc" test $2

google-chrome-stable

-2
This file was deleted.

lib/mix/tasks/client/accounts.ex

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
defmodule Mix.Tasks.Cli.Accounts do
22
use Mix.Task.Point.Client
3-
@shortdoc "Show accounts. Param: session_token"
4-
defrun fn(token) -> points(base_url, token) |> accounts end
3+
@shortdoc "Show accounts. Params: token"
4+
defrun fn([token | _]) -> points(base_url(), token) |> accounts end
55

66
defmodule Show do
77
use Mix.Task.Point.Client
8-
@shortdoc "Show an account. Params: session_token owner_email currency_code"
9-
defrun fn([token | account]) -> points(base_url, token) |> accounts(show: Account.create(account)) end
8+
@shortdoc "Show an account. Params: token owner_email currency_code"
9+
defrun fn([token | account]) -> points(base_url(), token) |> accounts(show: Account.create(account)) end
1010
end
1111
defmodule Create do
1212
use Mix.Task.Point.Client
13-
@shortdoc "Create an account. Params: session_token owner_email currency_code"
14-
defrun fn([token | account]) -> points(base_url, token) |> accounts(create: Account.create(account)) end
13+
@shortdoc "Create an account. Params: token owner_email currency_code"
14+
defrun fn([token | account]) -> points(base_url(), token) |> accounts(create: Account.create(account)) end
1515
end
1616
defmodule Delete do
1717
use Mix.Task.Point.Client
18-
@shortdoc "Delete an account. Params: session_token owner_email currency_code"
19-
defrun fn([token | account]) -> points(base_url, token) |> accounts(delete: Account.create(account)) end
18+
@shortdoc "Delete an account. Params: token owner_email currency_code"
19+
defrun fn([token | account]) -> points(base_url(), token) |> accounts(delete: Account.create(account)) end
2020
end
2121
end

lib/mix/tasks/client/currencies.ex

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
defmodule Mix.Tasks.Cli.Currencies do
22
use Mix.Task.Point.Client
3-
@shortdoc "Show currencies. Param: session_token"
4-
defrun fn(token) -> points(base_url, token) |> currencies end
3+
@shortdoc "Show currencies. Params: token"
4+
defrun fn([token | _]) -> points(base_url(), token) |> currencies end
55

66
defmodule Show do
77
use Mix.Task.Point.Client
8-
@shortdoc "Show a currency. Params: session_token code"
9-
defrun fn([token | [code | _]])-> points(base_url, token) |> currencies(show: code) end
8+
@shortdoc "Show a currency. Params: token code"
9+
defrun fn([token | [code | _]])-> points(base_url(), token) |> currencies(show: code) end
1010
end
1111
defmodule Create do
1212
use Mix.Task.Point.Client
13-
@shortdoc "Create a currency. Params: session_token code name"
14-
defrun fn([token | params]) -> points(base_url, token) |> currencies(create: Currency.new(params)) end
13+
@shortdoc "Create a currency. Params: token code name"
14+
defrun fn([token | params]) -> points(base_url(), token) |> currencies(create: Currency.new(params)) end
1515
end
1616
defmodule Update do
1717
use Mix.Task.Point.Client
18-
@shortdoc "Update currency name. Params: session_token code name"
19-
defrun fn([token | params]) -> points(base_url, token) |> currencies(update: Currency.new(params)) end
18+
@shortdoc "Update currency name. Params: token code name"
19+
defrun fn([token | params]) -> points(base_url(), token) |> currencies(update: Currency.new(params)) end
2020
end
2121
defmodule Delete do
2222
use Mix.Task.Point.Client
23-
@shortdoc "Delete a currency. Params: session_token code"
24-
defrun fn([token | [code | _]]) -> points(base_url, token) |> currencies(delete: code) end
23+
@shortdoc "Delete a currency. Params: token code"
24+
defrun fn([token | [code | _]]) -> points(base_url(), token) |> currencies(delete: code) end
2525
end
2626
end

lib/mix/tasks/client/entities.ex

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
defmodule Mix.Tasks.Cli.Entities do
2+
use Mix.Task.Point.Client
3+
@shortdoc "Show entities. Params: token"
4+
defrun fn([token | _]) -> points(base_url(), token) |> entities end
5+
6+
defmodule Show do
7+
use Mix.Task.Point.Client
8+
@shortdoc "Show an entity. Params: token code"
9+
defrun fn([token | [code | _]])-> points(base_url(), token) |> entities(show: code) end
10+
end
11+
defmodule Create do
12+
use Mix.Task.Point.Client
13+
@shortdoc "Create an entity. Params: token code name"
14+
defrun fn([token | params]) -> points(base_url(), token) |> entities(create: Entity.new(params)) end
15+
end
16+
defmodule Update do
17+
use Mix.Task.Point.Client
18+
@shortdoc "Update entity name. Params: token code name"
19+
defrun fn([token | params]) -> points(base_url(), token) |> entities(update: Entity.new(params)) end
20+
end
21+
defmodule Delete do
22+
use Mix.Task.Point.Client
23+
@shortdoc "Delete an entity. Params: token code"
24+
defrun fn([token | [code | _]]) -> points(base_url(), token) |> entities(delete: code) end
25+
end
26+
27+
defmodule Partners do
28+
use Mix.Task.Point.Client
29+
@shortdoc "Show entity partners. Params: token entity_code"
30+
defrun fn([token | [entity_code | _]]) -> points(base_url(), token) |> partners(entity_code: entity_code) end
31+
32+
defmodule Create do
33+
use Mix.Task.Point.Client
34+
@shortdoc "Create an entity partner. Params: token partner_code entity_code "
35+
defrun fn([token | params]) -> points(base_url(), token) |> partners(create: Partner.new(params)) end
36+
end
37+
defmodule Delete do
38+
use Mix.Task.Point.Client
39+
@shortdoc "Delete an entity partner. Params: token partner_code entity_code"
40+
defrun fn([token | params]) -> points(base_url(), token) |> partners(delete: Partner.new(params)) end
41+
end
42+
end
43+
end
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
defmodule Mix.Tasks.Cli.ExchangeRates do
22
use Mix.Task.Point.Client
3-
@shortdoc "Show exchange rates. Param: session_token"
4-
defrun fn(token) -> points(base_url, token) |> exchange_rates end
3+
@shortdoc "Show exchange rates. Params: token"
4+
defrun fn([token | _]) -> points(base_url(), token) |> exchange_rates end
55

66
defmodule Show do
77
use Mix.Task.Point.Client
8-
@shortdoc "Show a exchange rate. Params: session_token source target"
9-
defrun fn([token | params]) -> points(base_url, token) |> exchange_rates(show: ExchangeRateId.new(params)) end
8+
@shortdoc "Show a exchange rate. Params: token source target"
9+
defrun fn([token | params]) -> points(base_url(), token) |> exchange_rates(show: ExchangeRateId.new(params)) end
1010
end
1111
defmodule Create do
1212
use Mix.Task.Point.Client
13-
@shortdoc "Create a exchange rate. Params: session_token source target value (target = source * value)"
14-
defrun fn([token | params]) -> points(base_url, token) |> exchange_rates(create: ExchangeRate.new(params)) end
13+
@shortdoc "Create a exchange rate. Params: token source target value"
14+
defrun fn([token | params]) -> points(base_url(), token) |> exchange_rates(create: ExchangeRate.new(params)) end
1515
end
1616
defmodule Update do
1717
use Mix.Task.Point.Client
18-
@shortdoc "Update a exchange rate. Params: session_token source target value"
19-
defrun fn([token | params]) -> points(base_url, token) |> exchange_rates(update: ExchangeRate.new(params)) end
18+
@shortdoc "Update a exchange rate. Params: token source target value"
19+
defrun fn([token | params]) -> points(base_url(), token) |> exchange_rates(update: ExchangeRate.new(params)) end
2020
end
2121
defmodule Delete do
2222
use Mix.Task.Point.Client
23-
@shortdoc "Delete a exchange rate. Params: session_token source target"
24-
defrun fn([token | params]) -> points(base_url, token) |> exchange_rates(delete: ExchangeRateId.new(params)) end
23+
@shortdoc "Delete a exchange rate. Params: token source target"
24+
defrun fn([token | params]) -> points(base_url(), token) |> exchange_rates(delete: ExchangeRateId.new(params)) end
2525
end
2626
end

lib/mix/tasks/client/movements.ex

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
defmodule Mix.Tasks.Cli.Movements do
2+
defmodule ByAccountAfter do
3+
use Mix.Task.Point.Client
4+
@shortdoc "Show account movements after a date. Params: token owner_email currency_code timestamp (after format: YYYYMMDD_HHMM)"
5+
defrun fn([token | params]) -> points(base_url(), token) |> movements(search: AccountMovement.create(params)) end
6+
end
7+
defmodule Between do
8+
use Mix.Task.Point.Client
9+
@shortdoc "Show movements between dates. Params: from to (format: YYYYMMDD_HHMM)"
10+
defrun fn([token | params]) -> points(base_url(), token) |> movements(search: Between.create(params)) end
11+
end
12+
end

0 commit comments

Comments
 (0)