Last active
November 29, 2023 13:59
-
-
Save guillermoap/08e6d1dea5c1f1cb372ad7157463da67 to your computer and use it in GitHub Desktop.
Code examples for article
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
# components/meetings/app/models/meetings/member.rb | |
class Meetings::Member < ApplicationRecord | |
def self.consume_confirmation(user_registration_identifier) | |
ApplicationRecord.transaction do | |
self.create!(identifier: user_registration_identifier) | |
Meetings::Outbox.create!( | |
event: 'MEMBER_CREATED_SUCCESS', | |
payload: { user_registration_identifier: self.identifier } | |
) | |
end | |
rescue ActiveRecord::RecordInvalid => e | |
Meetings::Outbox.create!( | |
event: 'MEMBER_CREATED_FAILURE', | |
payload: { user_registration_identifier: self.identifier } | |
) | |
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
# components/user_access/app/models/user_access/user_registration.rb | |
class UserAccess::UserRegistration < ApplicationRecord | |
def confirm_registration | |
ApplicationRecord.transaction do | |
self.update!(status_code: :confirmed, confirmed_at: Time.current) | |
UserAccess::Outbox.create!( | |
event: 'USER_REGISTRATION_CONFIRMED', | |
payload: { user_registration_identifier: self.identifier } | |
) | |
end | |
rescue ActiveRecord::RecordInvalid => e | |
# Handle error | |
end | |
def rollback_confirm_registraion | |
self.update!(status_code: :waiting_for_confirmation, confirmed_at: nil) | |
rescue ActiveRecord::RecordInvalid => e | |
# Handle error | |
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
# components/meetings/app/models/meetings/member.rb | |
class Meetings::Member < ApplicationRecord | |
def self.consume_confirmation(user_registration_identifier) | |
self.create!(user_registration_id: user_registration_identifier) | |
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
# app/models/member.rb | |
class Member < ApplicationRecord | |
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
# components/meetings/app/models/meetings/member.rb | |
class Meetings::Member < ApplicationRecord | |
def self.consume_confirmation(user_registration_identifier) | |
self.create!(identifier: user_registration_identifier) | |
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
# components/user_access/app/models/user_access/user_registration.rb | |
class UserAccess::UserRegistration < ApplicationRecord | |
def confirm_registration | |
ApplicationRecord.transaction do | |
self.update!(status_code: :confirmed, confirmed_at: Time.current) | |
UserAccess::Outbox.create!( | |
event: 'USER_REGISTRATION_CONFIRMED', | |
payload: { user_registration_identifier: self.identifier } | |
) | |
end | |
rescue ActiveRecord::RecordInvalid => e | |
# Handle error | |
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
# components/user_access/app/models/user_access/user_registration.rb | |
class UserAccess::UserRegistration < ApplicationRecord | |
def confirm_registration | |
ApplicationRecord.transaction do | |
self.update!(status_code: :confirmed, confirmed_at: Time.current) | |
Event.publish('USER_REGISTRATION_CONFIRMED') | |
end | |
rescue ActiveRecord::RecordInvalid => e | |
# Handle error | |
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
# app/models/user_registration.rb | |
class UserRegistration < ApplicationRecord | |
belongs_to :member | |
enum status_code: { | |
waiting_for_confirmation: 0, | |
confirmed: 1, | |
expired: 2 | |
} | |
def confirm_registraion | |
ApplicationRecord.transaction do | |
self.update!(status_code: :confirmed, confirmed_at: Time.current) | |
Member.create!(user_registration: self) | |
end | |
rescue ActiveRecord::RecordInvalid => e | |
# Handle error | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment