-
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.
feat: add creation of special badges
- Loading branch information
1 parent
9db77c7
commit 0e259d6
Showing
4 changed files
with
63 additions
and
0 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
32 changes: 32 additions & 0 deletions
32
apps/govquests-api/govquests/gamification/lib/gamification/special_badge.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,32 @@ | ||
module Gamification | ||
class SpecialBadge | ||
include AggregateRoot | ||
|
||
def initialize(id) | ||
@id = id | ||
@display_data = nil | ||
@badge_type = nil | ||
@badge_data = nil | ||
@points = nil | ||
end | ||
|
||
def create(display_data, badge_type, badge_data, points) | ||
apply SpecialBadgeCreated.new(data: { | ||
badge_id: @id, | ||
display_data:, | ||
badge_type:, | ||
badge_data:, | ||
points:, | ||
}) | ||
end | ||
|
||
private | ||
|
||
on SpecialBadgeCreated do |event| | ||
@display_data = event.data[:display_data] | ||
@badge_type = event.data[:badge_type] | ||
@badge_data = event.data[:badge_data] | ||
@points = event.data[:points] | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
apps/govquests-api/rails_app/app/read_models/gamification/on_special_badge_created.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,13 @@ | ||
module Gamification | ||
class OnSpecialBadgeCreated | ||
def call(event) | ||
SpecialBadgeReadModel.create!( | ||
badge_id: event.data[:badge_id], | ||
display_data: event.data[:display_data], | ||
badge_type: event.data[:badge_type], | ||
badge_data: event.data[:badge_data], | ||
points: event.data[:points] | ||
) | ||
end | ||
end | ||
end |