Skip to content

Commit

Permalink
feat: add domain logic to frontend app
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeirojose committed Oct 8, 2024
1 parent 6ba36ca commit 3c4e529
Show file tree
Hide file tree
Showing 68 changed files with 978 additions and 820 deletions.
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nodejs 22.9.0
ruby 3.3.0
nodejs 20.18.0
ruby 3.3.5
Empty file removed .turbo/cookies/2.cookie
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
require_relative "action_tracking/action"
require_relative "action_tracking/action_execution"

ACTION_EXECUTION_NAMESPACE_UUID = "061d2578-e3b3-41c0-b51d-b75b70876e71".freeze

module ActionTracking
class << self
attr_accessor :event_store, :command_bus

def generate_execution_id(action_id, user_id)
name = "#{action_id}-#{user_id}"
namespace_uuid = ACTION_EXECUTION_NAMESPACE_UUID
Digest::UUID.uuid_v5(namespace_uuid, name)
end
end

class Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def initialize(id)
end

def start(action_id, action_type, user_id, start_data)
raise AlreadyStartedError if @state != "not_started"
raise AlreadyStartedError if started?
raise AlreadyCompletedError if completed?

nonce = SecureRandom.hex(16)
strategy = ActionTracking::ActionStrategyFactory.for(action_type)
Expand Down Expand Up @@ -60,6 +61,14 @@ def valid_nonce?(nonce)

private

def started?
@state == "started"
end

def completed?
@state == "completed"
end

on ActionExecutionStarted do |event|
@state = "started"
@action_id = event.data[:action_id]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require_relative "gitcoin_score_action_strategy"
require_relative "proposal_vote_action_strategy"
require_relative "read_document_action_strategy"

module ActionTracking
class ActionStrategyFactory
STRATEGIES = {
"gitcoin_score" => GitcoinScoreActionStrategy,
"proposal_vote" => ProposalVoteActionStrategy,
"read_document" => ReadDocumentActionStrategy
}.freeze

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ActionTracking
class GitcoinScoreActionStrategy < ActionStrategy
GITCOIN_SCORE_HUMANITY_THRESHOLD = 20

def initialize(gitcoin_api:)
def initialize(gitcoin_api: GitcoinPassportApi.new)
@gitcoin_api = gitcoin_api
end

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class ActionExecutionTest < Test

def setup
super
@execution_id = SecureRandom.uuid
@action_id = SecureRandom.uuid
@user_id = SecureRandom.uuid
@execution_id = ActionTracking.generate_execution_id(action_id, user_id)
@execution = ActionExecution.new(@execution_id)
@action_type = "read_document"
end
Expand Down
2 changes: 1 addition & 1 deletion apps/govquests-api/infra/lib/infra/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Types
include Dry.Types
UUID =
Types::Strict::String.constrained(
format: /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}\z/i
format: /^\h{8}-(\h{4}-){3}\h{12}$/
)
ID = Types::Strict::Integer
Metadata =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Resolvers
class FetchActionExecutions < BaseResolver
type [Types::ActionExecutionType], null: true

argument :action_id, ID, required: true

def resolve(action_id:)
current_user = context[:current_user]
return unless current_user

ActionTracking::ActionExecutionReadModel.where(
action_id: action_id,
user_id: current_user.user_id
)
end
end
end
12 changes: 12 additions & 0 deletions apps/govquests-api/rails_app/app/graphql/types/action_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@ class ActionType < Types::BaseObject
field :action_type, String, null: false
field :action_data, GraphQL::Types::JSON, null: false
field :display_data, Types::DisplayDataType, null: false

field :action_executions, [Types::ActionExecutionType], null: true

def action_executions
current_user = context[:current_user]
return unless current_user

ActionTracking::ActionExecutionReadModel.where(
action_id: object.action_id,
user_id: current_user.user_id
)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ def nodes(ids:)
field :quests, resolver: Resolvers::FetchQuests
field :quest, resolver: Resolvers::FetchQuest
field :user, resolver: Resolvers::FetchUser
field :action_executions, resolver: Resolvers::FetchActionExecutions
end
end
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# rails_app/app/read_models/action_tracking/read_model_configuration.rb
module ActionTracking
class ActionReadModel < ApplicationRecord
self.table_name = "actions"

validates :action_id, presence: true, uniqueness: true
validates :action_type, presence: true
validates :action_data, presence: true

has_many :action_executions, foreign_key: :action_id, primary_key: :action_id, class_name: "ActionTracking::ActionExecutionReadModel"
end

class ActionExecutionReadModel < ApplicationRecord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def self.start(action_id:, user_id:, start_data:)
action = ActionTracking::ActionReadModel.find_by(action_id: action_id)
return {error: "Action not found"} unless action

execution_id = SecureRandom.uuid
execution_id = ActionTracking.generate_execution_id(action_id, user_id)
command = ActionTracking::StartActionExecution.new(
execution_id: execution_id,
action_id: action.action_id,
Expand Down
8 changes: 0 additions & 8 deletions apps/govquests-api/rails_app/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ def create_action(action_data)

min_score: 20
}
},
{
action_type: "proposal_vote",
display_data: {content: "Vote on Governance Proposal XYZ"},
action_data: {

proposal_id: "proposal_xyz"
}
}
]

Expand Down
2 changes: 2 additions & 0 deletions apps/govquests-api/rails_app/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type Action {
actionData: JSON!
actionExecutions: [ActionExecution!]
actionType: String!
displayData: DisplayData!
id: ID!
Expand Down Expand Up @@ -77,6 +78,7 @@ type Mutation {
}

type Query {
actionExecutions(actionId: ID!): [ActionExecution!]
quest(id: ID!): Quest
quests: [Quest!]!
user(id: ID!): User
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3c4e529

Please sign in to comment.