Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AF-19] Add service layer #20

Merged
merged 6 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.development.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
APP_ENV=development
DATABASE_URL=postgresql://postgres:@127.0.0.1/auction_fun_core_development?pool=10
[email protected]
SMTP_ADDRESS=localhost
SMTP_PORT=1025
3 changes: 3 additions & 0 deletions .env.test.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
APP_ENV=test
DATABASE_URL=postgresql://postgres:@127.0.0.1:5432/auction_fun_core_test?pool=10
[email protected]
SMTP_ADDRESS=localhost
SMTP_PORT=1025
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ruby 3.3.0
postgres 16.1
golang 1.21.5
nodejs 20.10.0
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
## [Unreleased]

## [0.5.0] - 2024-02-23

### Added

- Layer for external services.
- Creation of first external service: email.
- Configure email as application provider.
- Mandatory environment variables for communication with email service.
- Configuring development environment to run email service on local machine.
- Using `idlemailer` dependency to build emails and triggers.

## Changes

- I18n locale directory from `config/locales` to root path of project.
- Scope i18n messages by locale.

## [0.4.1] - 2024-02-20

### Added
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem "dry-matcher", "1.0.0"
gem "dry-monads", "1.6.0"
gem "dry-system", "1.0.1"
gem "dry-validation", "1.10.0"
gem "idlemailer", "2.2.0"
gem "money", "6.16.0"
gem "pg", "1.5.5"
gem "phonelib", "0.8.7"
Expand Down
22 changes: 21 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.4.1)
auction_fun_core (0.5.0)

GEM
remote: https://rubygems.org/
Expand All @@ -27,6 +27,7 @@ GEM
database_cleaner-sequel (2.0.2)
database_cleaner-core (~> 2.0.0)
sequel
date (3.3.4)
diff-lcs (1.5.1)
docile (1.4.0)
dotenv (3.0.2)
Expand Down Expand Up @@ -92,14 +93,31 @@ GEM
i18n (1.14.1)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
idlemailer (2.2.0)
mail (~> 2.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.22.2)
money (6.16.0)
i18n (>= 0.6.4, <= 2)
mutex_m (0.2.0)
net-imap (0.4.10)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.4.0.1)
net-protocol
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
Expand Down Expand Up @@ -197,6 +215,7 @@ GEM
standard-performance (1.3.1)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
timeout (0.4.1)
transproc (1.1.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand All @@ -220,6 +239,7 @@ DEPENDENCIES
dry-system (= 1.0.1)
dry-validation (= 1.10.0)
faker (= 3.2.3)
idlemailer (= 2.2.0)
money (= 6.16.0)
pg (= 1.5.5)
phonelib (= 0.8.7)
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
database: postgres
mailserver: maildev --hide-extensions STARTTLS
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ This project uses `yadr` as a documentation tool. To generate documentation and

Documentation will be available at `http://localhost:8808`

## External resources

- [Email templates](https://codedmails.com/)

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
module AuctionFunCore
# Main class (Add doc)
class Application < Dry::System::Container
I18n.load_path += Dir[File.expand_path("i18n/**/*.{rb,yml}")]
I18n.available_locales = %w[en-US pt-BR]
I18n.default_locale = "pt-BR"
use :env, inferrer: -> { ENV.fetch("APP_ENV", "development").to_sym }
Expand Down
4 changes: 3 additions & 1 deletion config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
unless defined?(Dotenv)
require "dotenv"
Dotenv.load(".env.#{ENV.fetch("APP_ENV", nil)}")
Dotenv.require_keys("DATABASE_URL")
Dotenv.require_keys(
"DATABASE_URL", "DEFAULT_EMAIL_SYSTEM", "SMTP_ADDRESS", "SMTP_PORT"
)
end
11 changes: 11 additions & 0 deletions i18n/en-US/mail/user_context/registration.en-US.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
en-US:
mail:
general:
hello: "Hi %{name}"
app_name: "AuctionFun"
team: "Team AuctionFun"
user_context:
registration:
subject: "Welcome to AuctionFun"
body:
description: "Welcome to our platform! We are delighted to have you on board. If you have any questions or need assistance, feel free to reach out."
11 changes: 11 additions & 0 deletions i18n/pt-BR/mail/user_context/registration.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pt-BR:
mail:
general:
hello: "Olá %{name}"
app_name: "AuctionFun"
team: "Time AuctionFun"
user_context:
registration:
subject: "Bem vindo a AuctionFun"
body:
description: "Bem-vindo/a à nossa plataforma! Estamos encantados por tê-lo/a conosco. Se tiver alguma dúvida ou precisar de ajuda, não hesite em entrar em contato."
4 changes: 4 additions & 0 deletions lib/auction_fun_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ def self.root
File.expand_path "..", __dir__
end

def self.lib_path
File.expand_path ".", __dir__
end

autoload :Application, Pathname.new(File.expand_path("../config/application", __dir__))
end
2 changes: 1 addition & 1 deletion lib/auction_fun_core/contracts/application_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApplicationContract < Dry::Validation::Contract
config.messages.backend = :i18n
config.messages.default_locale = I18n.default_locale
config.messages.top_namespace = "contracts"
config.messages.load_paths << Application.root.join("config/locales/contracts/#{I18n.default_locale}.yml").to_s
config.messages.load_paths << Application.root.join("i18n/#{I18n.default_locale}/contracts/contracts.#{I18n.default_locale}.yml").to_s

register_macro(:email_format) do
next if EMAIL_REGEX.match?(value)
Expand Down
72 changes: 72 additions & 0 deletions lib/auction_fun_core/services/mail/templates/layout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title>AuctionFun</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
#outlook a {
padding: 0;
}
body {
margin: 0;
padding: 0;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
table,
td {
border-collapse: collapse;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
}
img {
border: 0;
height: auto;
line-height: 100%;
outline: none;
text-decoration: none;
-ms-interpolation-mode: bicubic;
}
p {
display: block;
margin: 13px 0;
}
</style>
<style type="text/css">
.mj-outlook-group-fix { width:100% !important; }
</style>
<style type="text/css">
@media only screen and (min-width:480px) {
.mj-column-per-100 {
width: 100% !important;
max-width: 100%;
}
}
</style>
<style type="text/css">
@media only screen and (max-width:480px) {
table.mj-full-width-mobile {
width: 100% !important;
}
td.mj-full-width-mobile {
width: auto !important;
}
}
</style>
<style type="text/css">
a,
span,
td,
th {
-webkit-font-smoothing: antialiased !important;
-moz-osx-font-smoothing: grayscale !important;
}
</style>
</head>
<body style="background-color:#ffffff;">
<%= yield %>
</div>
</body>
</html>
Loading
Loading