From 190299afe760eff93005ca64f6d432dc37c7765d Mon Sep 17 00:00:00 2001 From: Juliano Quatrin Nunes Date: Fri, 10 Jan 2025 14:36:49 -0300 Subject: [PATCH] chore: try to create badge on track / quest created --- .../app/read_models/questing/on_quest_created.rb | 6 ------ .../app/read_models/questing/on_track_created.rb | 9 +-------- .../app/read_models/rewarding/on_quest_created.rb | 12 ++++++++++++ .../app/read_models/rewarding/on_track_created.rb | 12 ++++++++++++ .../rewarding/read_model_configuration.rb | 2 ++ 5 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 apps/govquests-api/rails_app/app/read_models/rewarding/on_quest_created.rb create mode 100644 apps/govquests-api/rails_app/app/read_models/rewarding/on_track_created.rb diff --git a/apps/govquests-api/rails_app/app/read_models/questing/on_quest_created.rb b/apps/govquests-api/rails_app/app/read_models/questing/on_quest_created.rb index f5de2a10..ad4e49df 100644 --- a/apps/govquests-api/rails_app/app/read_models/questing/on_quest_created.rb +++ b/apps/govquests-api/rails_app/app/read_models/questing/on_quest_created.rb @@ -11,12 +11,6 @@ def call(event) display_data: event.data[:display_data] ) - badge_id = SecureRandom.uuid - Rewarding::BadgeReadModel.create!( - badge_id: badge_id, - display_data: event.data[:badge_display_data], - badgeable: quest - ) Rails.logger.info "Quest created in read model: #{quest.quest_id}" end end diff --git a/apps/govquests-api/rails_app/app/read_models/questing/on_track_created.rb b/apps/govquests-api/rails_app/app/read_models/questing/on_track_created.rb index ed473e19..0d02e479 100644 --- a/apps/govquests-api/rails_app/app/read_models/questing/on_track_created.rb +++ b/apps/govquests-api/rails_app/app/read_models/questing/on_track_created.rb @@ -1,18 +1,11 @@ module Questing class OnTrackCreated def call(event) - track = TrackReadModel.create!( + TrackReadModel.create!( track_id: event.data[:track_id], display_data: event.data[:display_data], quest_ids: event.data[:quest_ids] ) - - badge_id = SecureRandom.uuid - Rewarding::BadgeReadModel.create!( - badge_id: badge_id, - display_data: event.data[:badge_display_data], - badgeable: track - ) end end end diff --git a/apps/govquests-api/rails_app/app/read_models/rewarding/on_quest_created.rb b/apps/govquests-api/rails_app/app/read_models/rewarding/on_quest_created.rb new file mode 100644 index 00000000..7df8b3f5 --- /dev/null +++ b/apps/govquests-api/rails_app/app/read_models/rewarding/on_quest_created.rb @@ -0,0 +1,12 @@ +module Rewarding + class OnQuestCreated + def call(event) + BadgeReadModel.create!( + badge_id: SecureRandom.uuid, + display_data: event.data[:badge_display_data], + badgeable_type: "Questing::QuestReadModel", + badgeable_id: event.data[:quest_id] + ) + end + end +end diff --git a/apps/govquests-api/rails_app/app/read_models/rewarding/on_track_created.rb b/apps/govquests-api/rails_app/app/read_models/rewarding/on_track_created.rb new file mode 100644 index 00000000..0f9899d2 --- /dev/null +++ b/apps/govquests-api/rails_app/app/read_models/rewarding/on_track_created.rb @@ -0,0 +1,12 @@ +module Rewarding + class OnTrackCreated + def call(event) + BadgeReadModel.create!( + badge_id: SecureRandom.uuid, + display_data: event.data[:badge_display_data], + badgeable_type: "Questing::TrackReadModel", + badgeable_id: event.data[:track_id] + ) + end + end +end diff --git a/apps/govquests-api/rails_app/app/read_models/rewarding/read_model_configuration.rb b/apps/govquests-api/rails_app/app/read_models/rewarding/read_model_configuration.rb index 43d5d80f..1b20eac2 100644 --- a/apps/govquests-api/rails_app/app/read_models/rewarding/read_model_configuration.rb +++ b/apps/govquests-api/rails_app/app/read_models/rewarding/read_model_configuration.rb @@ -3,6 +3,8 @@ class ReadModelConfiguration def call(event_store) event_store.subscribe(OnRewardPoolCreated, to: [Rewarding::RewardPoolCreated]) event_store.subscribe(OnRewardIssued, to: [Rewarding::RewardIssued]) + event_store.subscribe(OnQuestCreated, to: [Questing::QuestCreated]) + event_store.subscribe(OnTrackCreated, to: [Questing::TrackCreated]) end end end