Skip to content

Commit

Permalink
[AF-1] People Registration (#14)
Browse files Browse the repository at this point in the history
* Add people registration resource

- User entity and your context to handle people business rules.
- Context for new user registration.
- Bcrypt to handle password issues.
- Phonelib to handle phone issues.
- Add unique indexes for email and phone for users database table
- Logger provider with level configuration.
- Configure i18n.
- pt-BR translation.
- en-US translation.
- Add pub/sub pattern and API with dry-events.
- Add ActiveSupport to the main application to facilitate general development.
- Configure database cleaner for suite of tests.
  • Loading branch information
ricardopacheco authored Feb 17, 2024
1 parent a628133 commit bb8adfe
Show file tree
Hide file tree
Showing 38 changed files with 996 additions and 55 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
## [Unreleased]

## [0.2.0] - 2024-02-27

### Added

- User entity and your context to handle people business rules.
- Context for new user registration.
- Bcrypt to handle password issues.
- Phonelib to handle phone issues.
- Logger provider with level configuration.
- Configure i18n.
- `pt-BR` translation.
- `en-US` translation.
- Add `pub/sub` pattern and API with dry-events.
- Add `ActiveSupport` to the main application to facilitate general development.
- Configure database cleaner for suite of tests.

### Fixed

- Adjusting lint with standardrb throughout the code.
- Lifecyle for core provider.

### Changed

- Adjusting directory patterns for test coverage.

## [0.1.0] - 2024-02-06

- Initial release
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source "https://rubygems.org"
gemspec

gem "activesupport", "7.1.3"
gem "bcrypt", "3.1.20"
gem "dotenv", "3.0.2"
gem "dry-events", "1.0.1"
gem "dry-matcher", "1.0.0"
Expand All @@ -14,6 +15,7 @@ gem "dry-system", "1.0.1"
gem "dry-validation", "1.10.0"
gem "money", "6.16.0"
gem "pg", "1.5.5"
gem "phonelib", "0.8.7"
gem "rake", "13.1.0"
gem "rom", "5.3.0"
gem "rom-sql", "3.6.2"
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
auction_fun_core (0.1.0)
auction_fun_core (0.2.0)

GEM
remote: https://rubygems.org/
Expand All @@ -18,6 +18,7 @@ GEM
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.6)
coderay (1.1.3)
concurrent-ruby (1.2.3)
Expand Down Expand Up @@ -104,6 +105,7 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.5)
phonelib (0.8.7)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -209,6 +211,7 @@ PLATFORMS
DEPENDENCIES
activesupport (= 7.1.3)
auction_fun_core!
bcrypt (= 3.1.20)
database_cleaner-sequel (= 2.0.2)
dotenv (= 3.0.2)
dry-events (= 1.0.1)
Expand All @@ -219,6 +222,7 @@ DEPENDENCIES
faker (= 3.2.3)
money (= 6.16.0)
pg (= 1.5.5)
phonelib (= 0.8.7)
pry (= 0.14.2)
rake (= 13.1.0)
rom (= 5.3.0)
Expand Down
2 changes: 1 addition & 1 deletion config/app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

require_relative 'application'
require_relative "application"

AuctionFunCore::Application.finalize!
25 changes: 13 additions & 12 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
# frozen_string_literal: true

require_relative 'boot'
require_relative "boot"

require 'zeitwerk'
require 'i18n'
require 'dry/system'
require 'dry/system/loader/autoloading'
require 'dry/auto_inject'
require 'dry/types'
require "bcrypt"
require "zeitwerk"
require "i18n"
require "dry/system"
require "dry/system/loader/autoloading"
require "dry/auto_inject"
require "dry/types"

module AuctionFunCore
# Main class (Add doc)
class Application < Dry::System::Container
I18n.available_locales = %w[en-US pt-BR]
I18n.default_locale = 'pt-BR'
use :env, inferrer: -> { ENV.fetch('APP_ENV', 'development').to_sym }
I18n.default_locale = "pt-BR"
use :env, inferrer: -> { ENV.fetch("APP_ENV", "development").to_sym }
use :zeitwerk, run_setup: true, eager_load: true

configure do |config|
config.root = File.expand_path('..', __dir__)
config.root = File.expand_path("..", __dir__)

config.component_dirs.add 'lib' do |dir|
config.component_dirs.add "lib" do |dir|
dir.auto_register = true
dir.loader = Dry::System::Loader::Autoloading
dir.add_to_load_path = true
dir.namespaces.add 'auction_fun_core', key: nil
dir.namespaces.add "auction_fun_core", key: nil
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

ENV['APP_ENV'] ||= 'development'
ENV["APP_ENV"] ||= "development"

require 'bundler'
Bundler.setup(:default, ENV.fetch('APP_ENV', nil))
require "bundler"
Bundler.setup(:default, ENV.fetch("APP_ENV", nil))

unless defined?(Dotenv)
require 'dotenv'
require "dotenv"
Dotenv.load(".env.#{ENV.fetch("APP_ENV", nil)}")
Dotenv.require_keys('DATABASE_URL')
Dotenv.require_keys("DATABASE_URL")
end
66 changes: 66 additions & 0 deletions config/locales/contracts/en-US.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
en-US:
contracts:
errors:
or: "or"
array?: "must be an array"
empty?: "must be empty"
excludes?: "must not include %{value}"
excluded_from?:
arg:
default: "must not be one of: %{list}"
range: "must not be one of: %{list_left} - %{list_right}"
exclusion?: "must not be one of: %{list}"
eql?: "must be equal to %{left}"
not_eql?: "must not be equal to %{left}"
filled?: "must be filled"
format?: "is in invalid format"
number?: "must be a number"
odd?: "must be odd"
even?: "must be even"
gt?: "must be greater than %{num}"
gteq?: "must be greater than or equal to %{num}"
hash?: "must be a hash"
included_in?:
arg:
default: "must be one of: %{list}"
range: "must be one of: %{list_left} - %{list_right}"
inclusion?: "must be one of: %{list}"
includes?: "must include %{value}"
bool?: "must be boolean"
true?: "must be true"
false?: "must be false"
int?: "must be an integer"
float?: "must be a float"
decimal?: "must be a decimal"
date?: "must be a date"
date_time?: "must be a date time"
time?: "must be a time"
key?: "is required"
attr?: "is required"
lt?: "must be less than %{num}"
lteq?: "must be less than or equal to %{num}"
max_size?: "size cannot be greater than %{num}"
min_size?: "size cannot be less than %{num}"
none?: "cannot be defined"
str?: "must be a string"
type?: "must be %{type}"
size?:
arg:
default: "size must be %{size}"
range: "size must be within %{size_left} - %{size_right}"
value:
string:
arg:
default: "length must be %{size}"
range: "length must be within %{size_left} - %{size_right}"
custom:
errors:
default:
taken: "has already been taken"
not_found: "not found"
password_confirmation: "doesn't match password"
macro:
email_format: "need to be a valid email"
name_format: "must be between %{min} and %{max} characters"
password_format: "must be between %{min} and %{max} characters"
phone_format: "need to be a valid mobile number"
65 changes: 65 additions & 0 deletions config/locales/contracts/pt-BR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
pt-BR:
contracts:
errors:
or: "ou"
array?: "deve ser um array"
empty?: "deve ficar vazio"
excludes?: "não deve incluir %{value}"
excluded_from?:
arg:
default: "não deve ser um de: %{list}"
range: "não deve ser um de: %{list_left} - %{list_right}"
exclusion?: "não deve ser um de: %{list}"
eql?: "deve ser igual a %{left}"
not_eql?: "não deve ser igual a %{left}"
filled?: "deve ser preenchido"
format?: "está em formato inválido"
number?: "deve ser um número"
odd?: "deve ser ímpar"
even?: "deve ser par"
gt?: "deve ser maior que %{num}"
gteq?: "deve ser maior ou igual a %{num}"
hash?: "deve ser do tipo hash"
included_in?:
arg:
default: "deve ser um de: %{list}"
range: "deve ser um de: %{list_left} - %{list_right}"
inclusion?: "deve ser um de: %{list}"
includes?: "deve incluir %{value}"
bool?: "deve ser booleano"
true?: "deve ser verdadeiro"
false?: "deve ser falso"
int?: "deve ser um número inteiro"
float?: "deve ser um número real"
decimal?: "deve ser um número decimal"
date?: "deve ser no formato de data"
date_time?: "deve ser no formato de data e hora"
time?: "deve ser no formato de tempo"
key?: "é requerido"
attr?: "é requerido"
lt?: "deve ser menor que %{num}"
lteq?: "deve ser menor ou igual a %{num}"
max_size?: "tamanho não pode ser maior que %{num}"
min_size?: "tamanho não pode ser menor que %{num}"
none?: "não pode ser definido"
str?: "deve ser do tipo texto"
type?: "deve ser do tipo %{type}"
size?:
arg:
default: "tamanho deve ser %{size}"
range: "tamanho deve ser entre %{size_left} e %{size_right}"
value:
string:
arg:
default: "deve ser %{size} caracteres"
range: "deve ser entre %{size_left} e %{size_right} caracteres"
custom:
default:
taken: "não está disponível"
not_found: "não encontrado"
password_confirmation: "não corresponde à senha"
macro:
email_format: "não é um email válido"
name_format: "deve ter entre %{min} e %{max} caracteres"
password_format: "deve ter entre %{min} e %{max} caracteres"
phone_format: "não é um número de celular válido"
19 changes: 19 additions & 0 deletions db/migrate/20240217115734_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

ROM::SQL.migration do
change do
create_table(:users) do
primary_key :id
column :name, String, null: false
column :email, String, null: false
column :phone, String, null: false
column :password_digest, String, null: false
column :active, TrueClass, null: false, default: true
column :created_at, DateTime, null: false
column :updated_at, DateTime, null: false

index :email, unique: true
index :phone, unique: true
end
end
end
10 changes: 5 additions & 5 deletions lib/auction_fun_core.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

require_relative "auction_fun_core/version"
require 'zeitwerk'
require "zeitwerk"

require_relative '../config/boot'
require_relative '../config/application'
require_relative "../config/boot"
require_relative "../config/application"

module AuctionFunCore
class Error < StandardError; end

def self.root
File.expand_path '..', __dir__
File.expand_path "..", __dir__
end

autoload :Application, Pathname.new(File.expand_path('../config/application', __dir__))
autoload :Application, Pathname.new(File.expand_path("../config/application", __dir__))
end
19 changes: 19 additions & 0 deletions lib/auction_fun_core/commands/user_context/create_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module AuctionFunCore
module Commands
module UserContext
##
# Abstract base class for insert new tuples on users table.
# @abstract
class CreateUser < ROM::Commands::Create[:sql]
relation :users
register_as :create
result :one

use :timestamps
timestamp :created_at, :updated_at
end
end
end
end
Loading

0 comments on commit bb8adfe

Please sign in to comment.