Skip to content

Latest commit

 

History

History
156 lines (107 loc) · 2.65 KB

README.md

File metadata and controls

156 lines (107 loc) · 2.65 KB

Rocket Seat Ignite - Nutri

Table of Contents

About

A calories counter backend made with Phoenix.

Endpoints

Built-in:

Meals

Setup

Install Erlang, Elixir and Phoenix.

Postgres

Create a postgress docker container with:

$ docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres

Bash Commands

# Create phoenix app without webpacker or html views
$ mix phx.new app_name --no-webpack --no-html

# Intall dependencies
$ mix deps.get

# Compile project
$ mix compile

# Generate linter config file
$ mix credo.gen.config

# Run linter
$ mix credo --strict

# Start Phoenix dev server on http://localhost:4000
$ mix phx.server

# Start your project as an Interactive Elixir session
$ iex -S mix

# List all configured routes
$ mix phx.routes

Ecto:

# Create and migrate database
$ mix ecto.setup

# Create a migration
$ mix ecto.gen.migration create_users_table

# Run pending migrations
$ mix ecto.migrate

# Drop and migrate databases
$ mix ecto.reset

# Drop databases
$ mix ecto.drop

# Create databases
$ mix ecto.create

Tests

# Run tests
$ mix test

# Run tests w/ coverage report
$ mix test --cover

Elixir Commands

Create a meal:

> meal_params = %{
  description: "Royal with cheese",
  date: "1994-05-21 12:00:00",
  calories: 500
}
> Nutri.Meals.Create.call(meal_params)

Fetch meals:

> Nutri.Repo.all(Nutri.Meal)
> Nutri.Repo.get(Nutri.Meal, 1)

> Nutri.get_meals()
> Nutri.get_meal_by_id(1)

Update meal:

> new_meal_params = %{
  "id" => 1,
  "description" => "UPDATEDDDDDDD",
  "date" => "2021-03-24 12:00:00",
  "calories" => 1000
}
> Nutri.Meals.Update.call(new_meal_params)

Delete meal:

> Nutri.delete_meal(1)

Libs

Docs

Resources