-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pre-Auction Notification for Participants (#42)
- Loading branch information
1 parent
448b604
commit 6fdf60c
Showing
29 changed files
with
918 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
i18n/en-US/mail/auction_context/pre_auction/auction_start_reminder.en-US.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pt-BR: | ||
mail: | ||
auction_context: | ||
pre_auction: | ||
auction_start_reminder_mailer: | ||
subject: "The %{title} auction will start soon!" | ||
body: | ||
description: "We are excited to inform you that the auction you are participating in will begin soon!" | ||
auction_date: "Start Time" | ||
link_to_auction: "Click the link below to view auction details" | ||
thanks: "Thank you for your participation and we wish you good luck!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
i18n/pt-BR/mail/auction_context/pre_auction/auction_start_reminder.pt-BR.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pt-BR: | ||
mail: | ||
auction_context: | ||
pre_auction: | ||
auction_start_reminder_mailer: | ||
subject: "O leilão %{title} começará em breve!" | ||
body: | ||
description: "Estamos entusiasmados em informar que o leilão em que você está participando começará em breve!" | ||
auction_date: "Hora de Início" | ||
link_to_auction: "Clique no link abaixo para ver os detalhes do leilão" | ||
thanks: "Agradecemos pela sua participação e desejamos boa sorte!" |
36 changes: 36 additions & 0 deletions
36
...auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module AuctionFunCore | ||
module Contracts | ||
module AuctionContext | ||
module PreAuction | ||
## | ||
# Contract class for validate schedule reminder notification. | ||
# | ||
class AuctionStartReminderContract < Contracts::ApplicationContract | ||
I18N_SCOPE = "contracts.errors.custom.auction_context.pre_auction.auction_start_reminder" | ||
|
||
option :auction_repository, default: proc { Repos::AuctionContext::AuctionRepository.new } | ||
|
||
params do | ||
required(:auction_id).filled(:integer) | ||
end | ||
|
||
rule(:auction_id) do |context:| | ||
context[:auction] ||= auction_repository.by_id(value) | ||
key.failure(I18n.t("contracts.errors.custom.not_found")) unless context[:auction] | ||
end | ||
|
||
# Validation to start. | ||
# Checks whether the auction has started or not. | ||
# | ||
rule do |context:| | ||
next if context[:auction].present? && context[:auction].not_started? | ||
|
||
key(:base).failure(I18n.t("auction_already_started", scope: I18N_SCOPE)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
module AuctionFunCore | ||
module Operations | ||
module AuctionContext | ||
module PreAuction | ||
## | ||
# Operation class for send a reminder email to a participant about the start of an auction. | ||
# | ||
class AuctionStartReminderOperation < AuctionFunCore::Operations::Base | ||
include Import["repos.bid_context.bid_repository"] | ||
include Import["contracts.auction_context.pre_auction.auction_start_reminder_contract"] | ||
include Import["workers.services.mail.auction_context.pre_auction.auction_start_reminder_mailer_job"] | ||
|
||
# @todo Add custom doc | ||
def self.call(attributes, &block) | ||
operation = new.call(attributes) | ||
|
||
return operation unless block | ||
|
||
Dry::Matcher::ResultMatcher.call(operation, &block) | ||
end | ||
|
||
def call(attributes) | ||
auction = yield validate_contract(attributes) | ||
participant_ids = yield collect_current_auction_participants(auction.id) | ||
|
||
bid_repository.transaction do |_t| | ||
participant_ids.each do |participant_id| | ||
yield send_auction_start_reminder_mailer_job(auction.id, participant_id) | ||
end | ||
end | ||
|
||
Success([auction, participant_ids]) | ||
end | ||
|
||
private | ||
|
||
def validate_contract(attributes) | ||
contract = auction_start_reminder_contract.call(attributes) | ||
|
||
return Failure(contract.errors.to_h) if contract.failure? | ||
|
||
Success(contract.context[:auction]) | ||
end | ||
|
||
def collect_current_auction_participants(auction_id) | ||
Success( | ||
AuctionFunCore::Application[:container] | ||
.relations[:bids] | ||
.participants(auction_id) | ||
.one | ||
.participant_ids.to_a | ||
) | ||
end | ||
|
||
def send_auction_start_reminder_mailer_job(auction_id, participant_id) | ||
Success(auction_start_reminder_mailer_job.class.perform_async(auction_id, participant_id)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module AuctionFunCore | ||
module Services | ||
module Mail | ||
module AuctionContext | ||
module PreAuction | ||
class AuctionStartReminderMailer | ||
include IdleMailer::Mailer | ||
include IdleMailer::TemplateManager | ||
|
||
# @param auction [ROM::Struct::Auction] The auction object | ||
# @param participant [ROM::Struct::User] The participant object | ||
def initialize(auction, participant) | ||
@auction = auction | ||
@participant = participant | ||
mail.to = participant.email | ||
mail.subject = I18n.t("mail.auction_context.pre_auction.auction_start_reminder_mailer.subject", title: @auction.title) | ||
end | ||
|
||
def self.template_name | ||
IdleMailer.config.templates.join("auction_context/pre_auction/auction_start_reminder") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.